I'm trying to figure out whether it's possible to use custom HTTP client in integration tests?
Instead of getting client instance from TestServer
Client = Server.CreateClient()
to use my own implementation. Smthng like:
Client = new DSClient(Server.BaseAddress.AbsoluteUri, Credential);
When I do so i'm constantly getting 404. WAIDW?
I faced the same problem and in my situation I can not use the existing HttpClient because I need to modify the HttpClient when initializing it. So my solution is to create a server and test it using my own HttpClient.
using(var server = WebHost.CreateDefaultBuilder(new List<string>().ToArray())
.UseEnvironment("Test")
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Listen(IPAddress.Loopback, 5000);
})
.Build())
{
server.Start();
var client = new HttpClient
{
BaseAddress = new Uri("http://localhost:5000")
}
var resp = client.GetAsync("test/testme").Result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With