Integration test when API calling another API

636 views Asked by At

I have two APIs on same solution. Let's call them API-1 and API-2.

API-1 calculate something, one of the variables is got from the API-2 by a http client get.

When I was writing the integration test for the API, I do a new instance of TestServer for API-1, I have that API-2 call nested in API-1, but the test server I have up is only for API-1.

This is what I tried already (but it didn't work):

               .UseStartup<JurosAPI.Startup>());
            _server.BaseAddress = new Uri("http://localhost:56149/");

            _client = _server.CreateClient();

            _server2 = new TestServer(new WebHostBuilder()
               .UseStartup<CalculadoraJurosAPI.Startup>().ConfigureTestServices(
                 services =>
                 {
                     //Inject HttpClient that's able to connect to server 1.
                     services.AddSingleton(typeof(HttpClient), _client);
                 }));

            _client2 = _server2.CreateClient(); 

Even doing it I cannot call API-2 from API-1 on the tests.

Is it possible to call the two APIs on that Integration Test? I have a bad design on my code? Should I mock this nested API call? How do I do that?

0

There are 0 answers