Mark
Mark
Explore posts from servers
CC#
Created by Mark on 3/13/2025 in #help
HttpContextAccessor 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
CC#
Created by Mark on 3/13/2025 in #help
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
CC#
Created by Mark on 3/13/2025 in #help
HttpContextAccessor returns null for HttpContext in tests
16 replies
CC#
Created by Mark on 3/13/2025 in #help
HttpContextAccessor returns null for HttpContext in tests
integration
16 replies
CC#
Created by Mark on 3/13/2025 in #help
HttpContextAccessor returns null for HttpContext in tests
i thought you would when using HttpClient to send a request
16 replies
CC#
Created by Mark on 3/13/2025 in #help
HttpContextAccessor returns null for HttpContext in tests
fwiw, i have the same problem if i inject a separate service into the dbcontext. httpcontext when accessed in that service will be null
16 replies
CC#
Created by Mark on 3/13/2025 in #help
HttpContextAccessor returns null for HttpContext in tests
would you just not use query filters then?
16 replies