2

While using the test server from the Microsoft.AspNetCore.Mvc.Testing package with code like this

var webAppFactory = new WebApplicationFactory<Program>();
var httpClient = webAppFactory.CreateClient();

I noticed that this is not using a Kestrel server and therefore some things don't work like on a real Kestrel server, e.g. body size limits:

warn: Microsoft.AspNetCore.Mvc.Filters.RequestSizeLimitFilter[1] A request body size limit could not be applied. This server does not support the IHttpRequestBodySizeFeature.

So, how can I run a real Kestrel server during my integration tests?

stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
  • _"how can I run a real Kestrel server during my integration tests?"_ - you shouldn't: the Testing Webserver is not actually a web-server at all: it doesn't listen on any TCP ports or accept "real" HTTP traffic - whereas if you _did_ try to use a "real" HTTP web-server with VS's Tests you will run into countless problems. – Dai Jul 01 '23 at 16:26
  • In a Integration test you can install/start your App and really call it. – jeb Jul 01 '23 at 16:38
  • @Dai well, but I need to test if my server side body size limit checks are fine and therefore I need a full Kestrel (and a test server for other tests, where the test server is enough) – stefan.at.kotlin Jul 01 '23 at 16:38
  • In that case (if you _really need_ to test this) then you should put it in your E2E tests, not an Integration Test - because you're testing a _server configuration_ parameter (which presumably can differ between Production and Dev/Test/Staging?), so having an automated integration test (using ASP.NET Core's integration test features) is a low-value test, whereas if you're testing a known environment that is expected to have a request body size limit (i.e. your Production) then that's in the scope of an E2E test. – Dai Jul 01 '23 at 17:03

0 Answers0