dotnet / dotnet/AspNetCore.Docs
Sample code returns 404
- Dominant language
- C#
- Stars
- 13.1k
- Forks
- 24.6k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 97
Description
Issue: the test suite returns 404 using the sample code. Note: I can hit them with Swagger UI.
Request: document the process model in order for developers to diagnose 404 responses quicker:
- What URL/port does the test framework run?
- The documentation hints that the SUT is hosted at `http://localhost:80` from the suggestion to add `BaseAddress = "https://localhost"` to avoid HTTPS redirects. However that doesn't make sense since ports < 1024 are blocked by Windows for non-privileges processes.
My code:
```c#
public partial class Program { // Made the class partial as suggested in the docs but I don't know why this is necessary. Maybe clarify why?
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(webApplicationOptions);
var app = builder.Build();
//Service configuration code omitted
//Note: I call builder.Configuration.AddAzureAppConfiguration() to retrieve config values from Azure Cloud
app.Run();
}
}
public class MyWebApplicationFactory : WebApplicationFactory where TProgram : class
{
protected override void ConfigureWebHost(IWebHostBuilder builder) {
builder.UseEnvironment("Development");
}
}
public class HomeControllerTests : IClassFixture> {
[Fact]
public void Get_Index_ReturnOk() {
var a = (await _client.GetAsync("/home")).StatusCode; // Returns 404 not 200
var b = (await _client.GetAsync("/")).StatusCode; // Returns 404 not 200
}
}
```
# Update:
Looks like removing the `ApplicationName` assignment in `var builder = WebApplication.CreateBuilder(new WebApplicationOptions { ApplicationName = Assembly.GetEntryAssembly().GetName().Name });` solves the 404 issues.
Request:
- Add document to forbid developers from modifying `ApplicationName` in `CreateBuilder()`.
Related: https://stackoverflow.com/a/75306984
---
#### Document Details
⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.*
* ID: 77889d43-fedb-f8b4-8fea-379ec946555c
* Version Independent ID: f499b131-8b14-7e10-1728-543fdd5a5656
* Content: [Integration tests in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-7.0#sut-environment)
* Content Source: [aspnetcore/test/integration-tests.md](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/test/integration-tests.md)
* Product: **aspnet-core**
* Technology: **aspnetcore-test**
* GitHub Login: @Rick-Anderson
* Microsoft Alias: **riande**
Contributor guide
Assessment
This issue has not been assessed yet.