dotnet / dotnet/AspNetCore.Docs

DataContext in the middleware Invoke function

Open
#33,039 1 comment 0 reactions 0 assignees View on GitHub
:watch: Not Triaged aspnet-core/svc Source - Docs.ms testing/subsvc
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 3h
Merged PRs (30d)
97

Description

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.