Skip to content

Actions

Yauhen Shayunou edited this page Oct 21, 2020 · 1 revision

GodelTech.StoryLine.Wiremock provides one action used to define HTTP request mocks which is MockHttpRequest. This actions consists of two major methods:

  • Request() defines patterns used to find proper response which is going to be sent to caller.
  • Response() defines response properties which sent to caller (status, body, headers). So typical stub definition looks as follows:
            Scenario.New()
                .When()
                    .Performs<MockHttpRequest>(x => x
                        .Request(req => req
                            .Url("/xxx")
                            .Method("GET"))
                        .Response(res => res
                            .Status(200)
                            .Body("Text")))
                .Run();

Request()

The following configuration methods are available in MockHttpRequest action:

  • Method() specifies HTTP method of expected request.
  • Url() filters request by path and query matching provided pattern. There other url matching predicates which are described here request matching.
  • Header() defines headers which must present in matching request.
  • QueryParam() defines query parameter which must present in request url.
  • Body() defines text body which matches incoming request.

Body() method has fluent syntax which might simplify matching of request body in case of JSON, XML or Plain text:

  • EqualToJson() verifies that body matches provided JSON. It's possible to specify if string or partial match is expected.
  • EqualToJsonObjectBody() does the same as previous method but accepts .NET object as parameter. This object is serialized and resulted JSON is used for further configuration.
  • EqualToXml() body must match XML document.

There some additional overloads which mimic behavior of Wiremock which can be found on the following page.

Clone this wiki locally