Using Matchers in request body
shobhitkasliwal-onbe opened this issue · 3 comments
Hello
I am trying to implement the API Consumer using matchers in the POST request body but the mock server is always responding with 500 (body is always comes as empty in the expected response) . Can anyone please guide me how can I implement the api consumer and provider using the Matchers in the request and response body ?
Thanks
Hi,
Can you provide some examples of what you have so far?
Other than that I can only recommend that you look at the test projects as an example, if you haven't already.
Hi @bartschotten - Thanks for the response. I did look at the test project but its not sending the request body as matchers.
Below is the sample code that is not working for me.
`[Fact]
public async Task Bff_PlaceOrder_Test2()
{
var input = Guid.NewGuid().ToString();
var requestJObject = Pact.JsonContent.With(Some.String.LikeGuid(input));
var interaction = Pact.Interaction
.UponReceiving("My Post Request")
.With(Pact.Request
.WithHeader("Content-Type", "application/json; charset=utf-8")
.WithMethod(Method.POST)
.WithBody(requestJObject)
.WithPath("/mytest"))
.WillRespondWith(Pact.Response
.WithStatus(200)
.WithHeader("Content-Type", "application/json")
.WithBody(Pact.JsonContent.With(Some.Element.WithTheExactValue("true"))));
builder.SetUp(interaction);
var httpClient = new HttpClient { BaseAddress = new Uri(_mockProviderServiceBaseUri) };
var requestContent = new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json");
// Act
var result = await httpClient.PostAsync("mytest", requestContent);
var body = await result.Content.ReadAsStringAsync();
// Assert
Assert.True(result != null);
}`
I am always getting 500 Error with the following message as response content.
{"message":"No matching response set up for this request.","actualRequests":{"method":"POST","path":"/mytest","headers":{"Host":"localhost:9224","Content-Type":"application/json; charset=utf-8","Content-Length":"38"},"query":{},"body":"175af1f4-b838-4504-b44e-6963566e89d7"},"expectedRequests":[{"method":"POST","path":"/mytest","headers":{"Content-Type":"application/json; charset=utf-8"},"query":{},"body":{}}]}
In the expected response the body is always coming as empty.
Oh now I see. Matching rules on requests are not supported. As I see it they are not an essential part of Pact.
https://github.com/bartschotten/com-pact#whats-not-supported