I've already got unit tests working fine, but would like to do in memory hosting and use HttpClient for integration tests. Can't seem to find to much information about this for ASP.NET 5.
2 Answers
Ended up using the following package instead of Kestrel:
Microsoft.AspNet.TestHost package
Example how I use it against my app:
[Fact]
public async void GetShouldReturnTwoValues()
{
var server = TestServer.Create(app =>
{
var env = app.ApplicationServices.GetRequiredService<IHostingEnvironment>();
new Startup(env).Configure(app, env);
}, services => services .AddMvc());
var result = await server.CreateClient().GetAsync("api/values/");
Assert.True(result.IsSuccessStatusCode);
}
Repo:
Usage / Documentation:
1 Comment
Israel Garcia
I am currently attempting to do this integration test with ASP.NET 5 beta7 and I found the problem with my controllers cannot found the views because they attempt to search them within the test project instead on the web project. Anyone had face this issue?
I stumbled upon the same question. So I want to add for completeness that the name of the NuGet package changed to Microsoft.AspNetCore.TestHost.
The correct documentation: https://docs.asp.net/en/latest/testing/integration-testing.html