Search code examples
c#asp.netautomated-testsowinweb-testing

How to start ASP.Net application without hosting?


I'm writing integration tests for my ASP.Net web application, so I want to start it and test on HTTP request/response level.

Because the tests are supposed to run concurrently and with minimal permissions, I do not want to expose them on any real HTTP port.

I read that OWIN is claimed to be an interface between ASP.Net applications and web servers.

I have an idea to use some mock web server object, which uses OWIN to host an ASP.Net application and doesn't expose it at any HTTP ports. Instead of this, the web server object should accept HTTP requests by calling its methods, feed them to the application it hosts and forward the response to the caller.

Are there any existing solutions?


Solution

  • Thanks to dawidr I found a similar way for those who uses ASP.Net MVC/Web API - Microsoft.Owin.Testing:

    using (var server = TestServer.Create<Startup>())
        server.HttpClient.GetAsync("api/ControllerName")
            .Result.EnsureSuccessStatusCode();
    

    Going this way, one can employ (and test) Owin's Startup object, used in real hosting scenario.