wiremock / wiremock/WireMock.Net

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

Open
#632 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
C#
Stars
1.7k
Forks
240
Avg merge
5d 12h
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with WireMockServerSettings, ReadStaticMappings, Mappings, LogEntries, and GetRequestMatchResult, which the issue uses for recording and replay checks. Trace how mappings and requests are stored and matched, then define recording behavior for identical requests and replay validation for the expected sequence. Done means repeated requests can be recorded distinctly and replayed in order with mismatches detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.