Mark
Explore posts from serversHttpContextAccessor returns null for HttpContext in tests
okay, so the fix was that i need to only access contextAccessor.HttpContext inside the lambda of HasQueryFilter so that the check is deferred until a request is made. wrapping the HasQueryFilter in an if statement is probably weird to begin with but worked during app execution but not during test runs, must be some minor difference with how the app is ran with WebApplicationFactory
16 replies
HttpContextAccessor returns null for HttpContext in tests
it seems like in tests the HttpContextAccessor runs at startup and HttpContext is of course null, but when a request is made, it doesn't rerun. on the other hand when running the app, it doesn't run at startup but does run when a request is made
16 replies
HttpContextAccessor returns null for HttpContext in tests
https://github.com/mwojtul/todos/blob/context-accessor/TodoApi.Tests/Integration/TodoEndpointsTests.cs#L12 here's the test
16 replies