mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Modifying slightly the mocked response, seems to make the output be not parsable. #567
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 @RogerSep on GitHub (Dec 28, 2023).
Originally assigned to: @StefH on GitHub.
I can't understand why tweaking a little bit the json response from my setup, causes tests to fail. Specifically if I add or remove a json property, the json isn't parsable anymore.
There's code at the end of this issue, the test is trying to setup a delegating handler that adds authorization headers to requests made with an http client.
Expected behavior:
Removing the
.WithTransformer()or removing some fields from the response shouldn't cause a json to not be parsable.Test to reproduce
The JSON value could not be converted to TestProject.OAuthHttpHandler+TokenResponse. Path: $ | LineNumber: 0 | BytePositionInLine: 80.Other related info
Here's a code snippet of my test. I have a second question, and it's that in the snippet, I don't know how to match form params. One of the forms i've tried is marked with the following comment
// How do I make it match form params?, but I've also triedWithParam(), I can't seem to find it.Using these packages
With this test
@StefH commented on GitHub (Dec 28, 2023):
1]
For "Form", you can take a look at this test case
WireMockServer_WithBodyAsFormUrlEncoded_Using_PostAsync_And_WithExactMatcher2]
To be able to use
"jwt": "{{request.headers.Authorization}}", you need to add.WithTransformerto enable HandleBars text replacement.@RogerSep commented on GitHub (Jan 2, 2024):
Thanks for your response.
@StefH commented on GitHub (Jan 2, 2024):
When using
WithBodyAsJson, you do not need to pass a string value, you can just pass in an object.Like
@StefH commented on GitHub (Jan 8, 2024):
@RogerSep
Did you try my previous comment?
@RogerSep commented on GitHub (Jan 9, 2024):
Hello, I just got back to this line of work, it did work. Thanks a lot.
Not sure why the string wouldn't work, but your option worked, thanks!