Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to do "in memory" hosting with ASP.NET MVC applications, similar to Web API?

I am writing an ASP.net MVC 4 application, and I am thinking about using "in memory" hosting to write integration tests for my custom action filters.

There are a few examples on the web on how to do this with Web API (eg http://www.strathweb.com/2012/06/asp-net-web-api-integration-testing-with-in-memory-hosting/) but I haven't seen any example with MVC.

Is it possible to do "in memory" hosting with MVC applications? If so does anyone have any examples or could they point me to any articles that do this?

like image 306
user1838438 Avatar asked Dec 02 '13 10:12

user1838438


People also ask

Can ASP Net Web API ability to both self hosting and IIS?

ASP.NET Web API can be either be hosted in IIS or in a separate host process. The former approach is usually appropriate when the Web API is part of a web application and one or more web applications are going to consume it.

Which is better Web API or MVC?

Web API can be used for generating HTTP services that replies data alone, but MVC would be suitable for developing web applications that replies as both, views and data. Web API looks at Accept Header of the request who returning the data in various formats, so it can return in various formats, like XML, JSON etc.

What is MVC hosting?

Key ASP.NET MVC Hosting features Separation of tasks. With ASP.NET MVC, you can build web applications as a composite of three different roles. The "Model" is the application state typically stored in a database. The "View" extracts information from the "Model" and displays the information.

Which package component can be added for integration testing of the .NET core API applications?

Sdk package. Entity Framework Core is also used in the tests. The app references: Microsoft.


1 Answers

You might be interested in MvcIntegrationTestFramework. It is not the freshest one but I works. Here is self-explaining example from their page:

AppHost.Simulate("MyMvcApp").Start(browsingSession =>
{
    var loginResult = browsingSession.Post("Users/Login/", 
                                           new { UserName = "aaa", Password = "bbb" });
    Assert.That(loginResult.Response.StatusCode, Is.EqualTo(200));

    var result = browsingSession.Post("Money/Create/", 
                                      new { Amount = "1,000,000" });
    Assert.That(result.Response.StatusCode, Is.EqualTo(200));
});
like image 121
Konrad Kokosa Avatar answered Oct 20 '22 10:10

Konrad Kokosa