mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
WireMock.Net not responding in unit tests - same works in console application #90
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @raheel0452 on GitHub (Apr 10, 2018).
Dear Team,
In a console application, I've below code to start WireMock.Net
// setup
var server1 = FluentMockServer.Start(new FluentMockServerSettings
{
Urls = new[] { "http://localhost:9091" },
ReadStaticMappings = true,
StartAdminInterface = true
});
This works all good.
When i write same in Unit tests, WireMock.Net does not respond
It's mandatory for us to use port (i've referred to https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock-in-UnitTests)
Thanks in advance
@StefH commented on GitHub (Apr 10, 2018):
When using wiremock in unit tests, you should not use a fixed port.
Use code like this:
The wiki is somewhat confusing. I will update this in the weekend.
@raheel0452 commented on GitHub (Apr 11, 2018):
Thank you for response.
Couple of questions from above request
We've attempted to start server without specifying any port. However the behavior remained same
(isStarted status though displays as true)
It's important for us to read static mapping from specified location.
Code we're trying with
var server1 = FluentMockServer.Start();
server1.ReadStaticMappings("\bin\Debug\netcoreapp2.0\__admin\mappings");
Any thoughts ?
Thanks.
@StefH commented on GitHub (Apr 11, 2018):
It is possible to use a fixed port, but then you have to start wiremock once, else you get conflicts. And when running the tests on a build server you can never be 100% sure that the port is free. Thats the reason that I start the server without a port, so that a free port is chosen. And use that port further.
This should work. Please search in my unit tests for the code which uses static mappings. Maybe the code has troubles finding the relative path?
@raheel0452 commented on GitHub (Apr 11, 2018):
Thank you. This is working now.
However one last point worth mentioning - when i execute unit test in debug mode, even though isStarted is set to true, i can't access the mockserver through browser until the continue debug. Is that expected ?
@StefH commented on GitHub (May 18, 2018):
Probably expected, maybe not all async code is really listening.