From the course: ASP.NET Core: Middleware

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Testing a middleware

Testing a middleware

- [Instructor] As the last step, I'd like to give you some pointers and guidance on how you can test your new custom middleware. I mean, of course we can mock a lot of things. We could mock the pipeline, we could mock the endpoint that's being called. And then essentially the middleware is just part of that. So we could, for instance, instantiate the class and then run the invoke async method with our mocked objects and then just see what's happening. But there might be an alternative at least for certain kinds of tests. And that's what I would like to show you. I already prepared a little bit for that. I added a new project, the AspNetCoreMiddleware.Tests project. It's an xUnit project. And I've already added one unit test. And I'm just testing or I want to test whether our middleware does sets the HTDP response header. That's the idea here. And what I would like to do is I just run the program. I just run the web application and then see what's going to happen. And for that, I can…

Contents