I have a case where I want to test my actions on a Rest API I do not have control on.
This API is stateful so for example this sequence is possible :
- Request A (GET method) -> Responds X
- Request B (POST method)
- Request A (GET method) -> Responds Y
With the static mapping, Request A will always be followed by response X.
I would like to :
- Save ALL requests even identicals during a session and ensure the order in which they are called remains.
- Use the resulting mapping to test a system and then ensure the requests where called in the expected order (the same as during the recording).
For now the only way those were :
- I could restart the session to have another set of mappings. But then I will also have to play with the states manually.
- The following code :
public void ReplayAndCheckSequence()
{
var settings = new WireMockServerSettings
{
Urls = new[] { "http://localhost:9095/" },
AllowPartialMapping = false,
};
_server = WireMockServer.Start(settings);
_server.ReadStaticMappings("mappings");
var serverMappings = _server.Mappings.ToList();
// Let the System Under Test run
Thread.Sleep(10000);
var serverLogEntries = _server.LogEntries.ToList();
Check.That(serverMappings.Count).Equals(serverLogEntries.Count);
for (int i = 0; i < serverLogEntries.Count; i++)
{
var entry = serverLogEntries[i];
var requestMatchResult = serverMappings[i].GetRequestMatchResult((RequestMessage) entry.RequestMessage, "");
Check.That(requestMatchResult.IsPerfectMatch).IsTrue();
}
}
Last note : It seems that MockServer would be able to do all of this.
Unfortunately is it decicated to Java and while it exposes a RestAPI, the most up to date .NET client seem to be abandonned.
I also prefer running the server in the same process as the tests like WireMock.Net allows.
I have a case where I want to test my actions on a Rest API I do not have control on.
This API is stateful so for example this sequence is possible :
With the static mapping, Request A will always be followed by response X.
I would like to :
For now the only way those were :
Last note : It seems that MockServer would be able to do all of this.
Unfortunately is it decicated to Java and while it exposes a RestAPI, the most up to date .NET client seem to be abandonned.
I also prefer running the server in the same process as the tests like WireMock.Net allows.