mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
WithBody delegate is null #341
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ZenwalkerD on GitHub (Mar 18, 2021).
Describe the bug
The Func<object,bool> for WithBody function is null for object parameter. Usage example as shown below.
I am using below code:
Postman request sent as shown in below image

The path is matching, breakpoint hits the delegate method; but object is always null.
Expected behavior:
the passed XML data from client i.e postman should not be null in wiremock api.
Test to reproduce
Other related info
Dotnet Core 5.0, Console App. Standalone
@StefH commented on GitHub (Mar 18, 2021):
Hello @ZenwalkerD,
If you use
.WithBody((xmlData), it's assumed that this is JSON data.If you want to get your example XML data (which is string), you need this code:

@StefH commented on GitHub (Mar 19, 2021):
@ZenwalkerD : did this answer help you?
@ZenwalkerD commented on GitHub (Mar 19, 2021):
As far as i understand, WithBody((parameter)) should have any data format which is being sent from the client, right?
So weather its XML or Json or something. WithBody should give it to parameter.
Either ways, kindly please add a documentation for this.
Also for my task, i took a different approach via RegexMatcher
Thanks
@StefH commented on GitHub (Mar 19, 2021):
To add flexibility, I updated to code to also support IBodyData, which contains more info about the body.
https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs#L78
A new version containing this fix will be released soon.
@ZenwalkerD commented on GitHub (Mar 19, 2021):
Thanks, also documentation would be of much help to newbies like me.
Not only w.r.t to this, but also with XMLmatchers i was struggling alot.