Question: Request.Create().WithBody() not able to match with custom class which implements IMatcher #82

Closed
opened 2025-12-29 14:22:06 +01:00 by adam · 1 comment
Owner

Originally created by @shraj on GitHub (Mar 27, 2018).

Originally assigned to: @StefH on GitHub.

mock.Given(Request.Create()
	.UsingPost()
	.WithPath("/api/v1/xxx/action")
	.WithBody(new TTT())                    
)
.RespondWith(Response.Create()
	.WithBody(response)
	.WithHeader("Content-Type", "application/json")
	.WithStatusCode(HttpStatusCode.OK)
);
public class TTT : IMatcher
{
	public double IsMatch(string input)
	{
		//input is null
		return 1;
	}
}
var client = new HttpClient();
var content = new StringContent("{data: 1}", UTF8, "application/json");
client.PostAsync("/api/v1/xxx/action", content);
Originally created by @shraj on GitHub (Mar 27, 2018). Originally assigned to: @StefH on GitHub. ``` C# mock.Given(Request.Create() .UsingPost() .WithPath("/api/v1/xxx/action") .WithBody(new TTT()) ) .RespondWith(Response.Create() .WithBody(response) .WithHeader("Content-Type", "application/json") .WithStatusCode(HttpStatusCode.OK) ); ``` ``` C# public class TTT : IMatcher { public double IsMatch(string input) { //input is null return 1; } } ``` ``` var client = new HttpClient(); var content = new StringContent("{data: 1}", UTF8, "application/json"); client.PostAsync("/api/v1/xxx/action", content); ```
adam closed this issue 2025-12-29 14:22:06 +01:00
Author
Owner

@StefH commented on GitHub (Mar 28, 2018):

IMatcher is a base interface.

Use IStringMatcher of IObjectMatcher

See https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs for more details.

@StefH commented on GitHub (Mar 28, 2018): `IMatcher` is a base interface. Use `IStringMatcher` of `IObjectMatcher` See https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs for more details.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#82