Skip to content

Integration tests are not working if using inherited Startup and reference to Microsoft.AspNetCore.App without version specified #8428

@satano

Description

@satano

Describe the bug

We use integration tests in our AspNetCore application. We use inherited Startup class in our test project, so we can easily modify things in it for the testing purposes. The SUT is web API project that references Microsoft.AspNetCore.App. Everything works, if this reference has version specified. If we remove the version specification, the tests stop working. Requests to the test server keep returning 404 NotFound.

Version specification of this package is not recommended. If it is there, the compiler generates warning:

Warning NETSDK1071 A PackageReference to 'Microsoft.AspNetCore.App' specified a Version of 2.2.0. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs

Integration tests are always working (regardless of reference version specification) if they directly use Startup class from SUT.

To Reproduce

  1. Create a simple web API project. Make sure, the reference to Microsoft.AspNetCore.App in .csproj is without version specified: <PackageReference Include="Microsoft.AspNetCore.App" />
  2. Create integration tests project, that references web API project.
  3. Create a Startup class in test project, which is inherited form API's project Startup.
  4. Make a simple test which uses test Startup and makes a request to correct API in test server.
  5. The request should return 200 OK, but returns 404 NotFound.
  6. Modify the refeference in API project to have version specified: <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" /> The test will work.

Expected behavior

Integration tests should work as expected even if the package is without version.

Additional context

I created a full (yet simple) demo repository so you can clone it, run the tests and see the results.

There are two web API projects, which are the same. The only difference is how the Microsoft.AspNetCore.App package is referenced. And there are 4 sets of 2 test projects, where one project references API with version, the other test project API without version. 4 sets are because I used different approaches:

  • Direct using of Startup class in API project. In this case, always everything works.
  • Using inherited Startup class. Non of these approaches works with API project without version.
    • Using this inherited class directly.
    • Using inherited WebApplicationFactory.
    • Using TestServer.

Metadata

Metadata

Assignees

Labels

✔️ Resolution: DuplicateResolved as a duplicate of another issuearea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions