Connection between two test WebApplicationFactory in integration test

Viewed 122

I'm trying to write a test for an endpoint that passes data to another internal app by invoking a signalr hub. In my test I have added the two startups as a classfixture using WebApplicationFactory as follows.

public class BookControllerTests : IClassFixture<App1WebApplicationFactory<App1.Startup>>, IClassFixture<App2WebApplicationFactory<App2.Startup>>
    {

        public OperationsControllerTests(IClassFixture<App1WebApplicationFactory<App1.Startup>> app1Factory, IClassFixture<App2WebApplicationFactory<App2.Startup>> app2Factory)
        {
            _app1Client = app1Factory.CreateClient();
            _app2Factory = app2Factory;
        }

        [Fact]
        public async Task ShouldPostBook()
        {
            // Arrange
            var request = new Book{ Title = "Test book"};
            using var scope = app2Factory.Services.CreateScope();
            var app2Context = scope.ServiceProvider.GetRequiredService<App2DbContext>();


            // Act
            await _app1Client.PostAsync("/book", request);
            await Task.Delay(10_000, _token)
            // Assert
            
            Assert.True(app2Context.Books.AnyAsync(x => x.Title == request.Title));
        }

So, the problem is When connecting to the signalr hub I'm using localhost:5001. The address set for the app in the launch setting. I dont know with what address I should replace it for the test server. Because of that I'm getting ""No connection could be made because the target machine actively refused it. (localhost:5001)"}". Please help. Is this the right way to do it? Does this setup ensures that the test servers can communicate with each other? Is there a way to set address of the test server?

0 Answers
Related