Closed jonakirke94 closed 4 months ago
@jonakirke94 There a are several Json matchers available, see this wiki page for an overview (https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matchers) and see the detail page for how to use it.
@StefH The syntax seem different when using the AdminAPI
The examples do not use the AdminApiMappingBuilder
Could you show me how to do it?
builder
.Given(m => m.WithRequest(req => req
.UsingGet()
.WithBody() ???? <------
.WithUrl("test"))
@jonakirke94 I do understand your question now. In that case, your code should be like:
using var server = WireMockServer.StartWithAdminInterface();
var api = RestEase.RestClient.For<IWireMockAdminApi>(server.Url!);
var guid = Guid.Parse("53241df5-582c-458a-a67b-6de3d1d0508e");
var mappingBuilder = api.GetMappingBuilder();
mappingBuilder.Given(m => m
.WithTitle("This is my title 1")
.WithGuid(guid)
.WithRequest(req => req
.UsingPost()
.WithPath("/bla1")
.WithBody(body => body
.WithMatcher(matcher => matcher
.WithName("JsonPartialMatcher")
.WithPattern(new { test = "abc" })
)
)
)
.WithResponse(rsp => rsp
.WithBody("The Response")
)
);
// Act
var status = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
// Assert
status.Status.Should().Be("Mapping added");
Thanks.
So in your example it matches a json property "test" with value "abc"
Thanks.
So in your example it matches a json property "test" with value "abc"
correct
I'm using the testcontainers wiremock and try to set up a request mapping.
I'm using AdminApiMappingBuilder
This is an example:
How can I use WithBody here with JsonPartialMatcher? WithBody takes a MatcherModelBuilder but it's unclear to me how we can leverage this.