I have been playing a little with Wiremock.net for mocking out HTTP calls. I've got it working happily running from a console application, but when I try to do it with a unit test it stops responding. Here is my complete code:
FluentMockServer serviceMock;
[TestInitialize]
public void Initialize()
{
serviceMock = FluentMockServer.Start(new FluentMockServerSettings { Urls = new[] { "http://+:5010" } });
serviceMock.Given(Request.Create().UsingPost().WithPath("/callbacks/booked"))
.RespondWith(Response.Create().WithStatusCode(200).WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new List<Callback>
{
new Callback { CustomerId = 1, RequestedFor = new DateTime(2017, 12, 14, 15, 00, 01) },
}));
}
[TestMethod]
public void CanHitMockEndpoint()
{
var client = new RestClient("http://localhost:5010");
var response = client.Get<List<Callback>>(new RestRequest("/callbacks/booked"));
response.StatusCode.Should().Be(HttpStatusCode.OK);
}
[TestCleanup]
public void Cleanup() => serviceMock.Stop();
When I get the response back, it has a status code of zero, and the message "Unable to connect to the remote server"
The strange thing is, if I move the Initialize and Cleanup items into a console app, and run it alongside, the test will work. I've confirmed that the Initialize/Cleanup is running, so I'm definitely either missing something obvious, or something strange is going on!
Any help would be great.