Confirm that middleware is in use
UseMiddleware
is actually an extension method that will create a RequestDelegate that uses your middleware internally. That delegate does quite a lot of things, so it would be very difficult for you to test that it will properly register your actual middleware type.
The only thing you can really do is to check that the underlying ApplicationBuilder.Use
method was called with some request delegate.
Alternatively, you could also actually invoke the middleware, by building the application pipeline and executing it. But that will require that you set up dependency injection properly (since the delegate from UseMiddleware()
will use that) and that all your middleware’s dependencies are set up properly.
So this is going to be very complicated. I would suggest you to write an integration test instead that checks that for a request, your middleware will be invoked properly and can do what it should do.