When making Integration tests for asp.net core MS docs say to use WebApplicationFactory<Program>
.
So with my SS project using Identity auth I can do something like:
_factory = new WebApplicationFactory<Program>();
using var client = _factory.CreateClient();
var response = await client.GetAsync("/hello");
Assert.That(response.IsSuccessStatusCode);
The HttpClient that is returned can make requests but it’s not actually firing up the host with a port I don’t think. I guess it’s intercepting the requests under the hood.
How do I use the ServiceStack client to make test requests? I guess I need to specify it to use the HttpClient created by the factory.
I try variations of:
var ssClient = new JsonServiceClient(client.BaseAddress?.ToString() ?? "/");
ssClient.HttpClient = client;
var response2 = await ssClient.GetAsync(new Hello { Name = "World" });
But it appears to be trying to make http request to local machine.
I have tried adding:
services.AddJsonApiClient("http://localhost"); //the base address set by factory
and tried getting it from IoC but I can’t quite figure out how to make it work. Is it possible or am I going in the wrong direction?