dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.58k stars 25.29k forks source link

DataContext in the middleware Invoke function #33039

Open ragavendra opened 2 months ago

ragavendra commented 2 months ago

Description

[Enter feedback here] First of all, thanks for this documentation, I was able to almost test one middle ware.

However, I was trying to write unit tests for another one which uses DataContext or is DI injested in the Invoke method. The DataContext is however resolved, but the model say Blog does not have any data entries in it. I am assuming this to be the case as I am using the UseTestServer() in the beginning.

Is there a way or any alternative way as well of injesting data to the DataContext so that the middleware can be tested?

Page URL

https://learn.microsoft.com/en-us/aspnet/core/test/middleware?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/test/middleware.md

Document ID

8415adee-793e-2ba7-b97b-672b493ba42b

Article author

@Tratcher

tdykstra commented 2 months ago

@andrejpk I noticed you contributed to this article recently -- can you help with this question?