Sudhir Kumbhare

Sudhir Kumbhare

  • NA
  • 50
  • 1.2k

.NET Core 5.0 TestServer

Mar 12 2021 9:39 AM
I have built a unit test project in .NET Core 5.0 to test my API's. I have created a test server using HostBuilder. In my unit testing class I am calling an API using
HttpClient client;
client = TestServer.GetTestClient(); in all methods. It' working and no issues.
But in couple of unit test methods when request goes to BL(Business logic level) I need to make a call to TestServer to get the token then the actual problem starts. I can't make a call using Httpclient without using TestServer.GetTestClient() because if I do that it says the hosting server have actively refused to connect. And I can't make a call using TestServer.GetTestClient() because it will be a cyclic dependency on main project.
Is there a way to call TestServer using only Httpclient without using TestServer.GetTestClient()?

Answers (1)