-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
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
- 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" />
- Create integration tests project, that references web API project.
- Create a
Startup
class in test project, which is inherited form API's projectStartup
. - Make a simple test which uses test
Startup
and makes a request to correct API in test server. - The request should return
200 OK
, but returns404 NotFound
. - 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
.