Skip to content

Record all request even when identical + Expect request sequences when replaying #632

Description

@julien-azouz-beezup

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 :

  1. Save ALL requests even identicals during a session and ensure the order in which they are called remains.
  2. 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 :

  1. I could restart the session to have another set of mappings. But then I will also have to play with the states manually.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions