This can cause issues when running these unit-tests on a build-server, there is not 100% guarantee that this port will be free on the OS.
My suggestion would be to start the WireMock.Net without a fixed port. Just like:
var server = WireMockServer.Start();
// Getting the random port on which the WireMock.Net server is running, can be done like:
var port = server.Ports[0];
// Or you can also get the full URL where the WireMock.Net server is running with:
var url = server.Urls[0];
However this means that setting up the TheIdentityHubOptions should be done in each unit-test because the port is not fixed anymore.
Another suggestion:
I see that in every test the WireMock.Net server is started and stopped, in that case using a local variable var server = instead of defining and reusing a private class variable like private WireMockServer _Server; would be a better option.
Another idea would be to start the WireMock.Net server once during start from the test-class and reset + add a new mapping in each test. This can be a bit quicker when running the tests.
Thanks for the suggestions @StefH ! We will try to implement them in the near future, as they will surely improve the stability of the fresh TheIdenityHubServiceTests.
Concern
I see that WireMock.Net is used to unit-test the TheIdentityHubService in the TheIdentityHubServiceTests.cs file.
However a fixed port is used: https://github.com/minvws/nl-covid19-notification-app-backend/blob/601afa149dd631593589b383266e6b4185ab2524/Components.Tests/Icc/TheIdentityHubServiceTests.cs#L35
This can cause issues when running these unit-tests on a build-server, there is not 100% guarantee that this port will be free on the OS.
My suggestion would be to start the WireMock.Net without a fixed port. Just like:
However this means that setting up the
TheIdentityHubOptions
should be done in each unit-test because the port is not fixed anymore.Another suggestion: I see that in every test the WireMock.Net server is started and stopped, in that case using a local variable
var server =
instead of defining and reusing a private class variable likeprivate WireMockServer _Server;
would be a better option.Another idea would be to start the WireMock.Net server once during start from the test-class and reset + add a new mapping in each test. This can be a bit quicker when running the tests.