You cannot do this. The OWIN pipeline is designed for decoupling from any hosting env.
MVC is heavily system.web with system.web , which makes testing with the OWIN pipeline difficult.
You can do something like this:
[TestClass] public class ManageControllerTests { [TestMethod] public async Task ManageController_Index_ShoudlPass() { using (var server = CustomTestServer.Create<Startup>()) { server.OnNextMiddleware = context => { context.Response.StatusCode.ShouldBe(Convert.ToInt16(HttpStatusCode.OK)); return Task.FromResult(0); } var response = await server.HttpClient.GetAsync("/Manage"); } }
You will need to withdraw
public class CustomTestServer : TestServer
And add the middleware to the constructor after the existing middleware
appBuilder.Use(async (context, next) => { await OnNextMiddleware(context); });
And a public member
public Func<IOwinContext, Task> OnNextMiddleware { get; set; }
From there, when you call server.httpclient.getasync... , the middleware will pass the response to the next middleware for processing.
Siva kandaraj
source share