dotnet / dotnet/aspnetcore

Integration Testing returns 404 for all HTTP requests that work with curl/Postman

Open
#51,143 0 comments 0 reactions 0 assignees View on GitHub
area-mvc feature-mvc-testing
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Issue: the [Integration Testing](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-7.0#sut-environment) sample code returns 404 for all HTTP requests that work with curl/Postman!

Fortunately I discovered https://stackoverflow.com/a/75306984 which hinted me to remove `ApplicationName` assignment from my code:
```c#
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { ApplicationName = Assembly.GetEntryAssembly().GetName().Name });
```

Question:
Why does specifying the application name of your process cause the Integration Testing library to go bonkers.

Issues:
- The above mentioned `ApplicationName` assignment breaks the library from working
- This bug makes it impossible/difficult for developers to diagnose the problem/find a solution!!! A better design would be to make the URL/port visible to the user or provide better documentation.

FYI: My subsequent AspNetCore.Docs request: https://github.com/dotnet/AspNetCore.Docs/issues/30582

### Expected Behavior

The Integration Testing libary should return non-404 HTTP responses.

### Steps To Reproduce

- Clone [Integration Testing](https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-7.0#sut-environment) with the following addition:
```c#
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { ApplicationName = Assembly.GetEntryAssembly().GetName().Name });
```
- Run an integration test.
- Expected: 200 OK response
- Actual: 404 Not Found

### Exceptions (if any)

_No response_

### .NET Version

7

### Anything else?

.NET SDK:
Version: 7.0.401
Commit: eb26aacfec

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.401\

Host:
Version: 7.0.11
Architecture: x64
Commit: ecb34f85ec

.NET SDKs installed:
7.0.401 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.