Reputation: 6069
I have an ASP.Net Core 1.1 project that is using ServiceStack Core. I am trying to write a basic integration test that looks like so:
[TestFixture]
public class BasicStartupTest
{
TestServer Server;
HttpClient Client;
const string BASE_URL = "http://localhost:57893";
[OneTimeSetUp]
public void OneTimeSetup()
{
Server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
Client = Server.CreateClient();
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
Server.Dispose();
}
[Test]
public async Task ShouldHitHealthEndpointAndReturn200()
{
var response = await Client.GetAsync("/health");
response.EnsureSuccessStatusCode();
}
}
Problem is, when it tried to run the GetAsync function from the Client instance, i get the following stack trace:
Result StackTrace: at ServiceStack.Host.NetCore.NetCoreRequest.get_UserHostAddress() in C:\TeamCity\buildAgent\work\a61371dd01fad6bd\src\ServiceStack\Host\NetCore\NetCoreRequest.cs:line 215
at ServiceStack.HttpRequestExtensions.GetAttributes(IRequest request) in C:\TeamCity\buildAgent\work\a61371dd01fad6bd\src\ServiceStack\HttpRequestExtensions.cs:line 844
at ServiceStack.AppHostBase.ProcessRequest(HttpContext context, Func`1 next) in C:\TeamCity\buildAgent\work\a61371dd01fad6bd\src\ServiceStack\AppHostBase.NetCore.cs:line 113
at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
It goes on, but it looks like there is an issue with some get_UserHostAddress function in ServiceStack when I try to make a call to the endpoint in my integration test.
How do I fix this error?
Upvotes: 1
Views: 256
Reputation: 143284
Use a proper Integration Test with a real self host HTTP Server enabled, for .NET Core the AppSelfHostBase class is available in the ServiceStack.Kestrel NuGet package.
Upvotes: 2