I am using dotnet-testcontainers
https://github.com/HofmeisterAn/dotnet-testcontainers to spin up a container with mountebank in my xUnit test.
I can successfully create a mountebank client and create an imposter successfully.
The issue is that when the test is run, the app tries to make a call to the imposter on http://localhost:3000
and gets connection refused.
I can successfully open http://localhost:2525
and can see Mountebank default page. So mountebank is running fine. I also confirmed that the imposter was created successfully on port 3000
by looking at docker container log.
I also tried to use Postman to make a call to my imposter at http:localhost:3000
and get connection refused.
What could be the issue? Is this an issue that port 3000
in the docker container is not exposed or something? Below is my code:
MountebankClient mbClient = new MountebankClient();
var testcontainersBuilder = new TestcontainersBuilder<TestcontainersContainer>()
.WithImage("bbyars/mountebank")
.WithName("mountebank")
.WithPortBinding(2525, false)
.WithHostname("localhost");
var testContainers = testcontainersBuilder.Build();
await testContainers.StartAsync();
var testImposter = mbClient.CreateHttpImposter(3000);
testImposter.AddStub().ReturnsBody(HttpStatusCode.OK, File.ReadAllText(@".\Stubs\testImposter.json"));
mbClient.Submit(testImposter);