-
-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpTest WithRequestJson does not use JsonSerializer set on FlurlClientCache #813
Comments
I'm not sure if I'm following. Any value set explcitly on HttpTest.Settings should always override the same setting set anywhere in the SUT. That's by design. But when not explicitly set on HttpTest.Settings, it should respect the settings specified in the SUT. In your code above, I confirmed that the settings specified at the start are in effect when you make the call further down. Am I missing something? |
I've updated the title to hopefully help clarify. When I run this test, the call ".WithRequestJson(requestDto)" fails. Reason being is the json serializer set on the FlurlClientCache is using camel case. Hence, the serialized json used in the body of the call is {"property":"Value"}. In the call to WithRequestJson, the serializer used to serialize requestDto is not the same as what is set earlier. As a result, WithRequestJson is using pascal case, and is comparing {"Property":"Value"} to the body of the call. Note the uppercase "Property" vs lowercase "property". {"Property":"Value"} is not the same as {"property":"Value"} Assertion message: Stack Trace: |
Got it. I probably should have ran your test before replying. :) Sounds legitimate, it's been added to the backlog and I'll look into when I get some time. |
This is very similar to Issue 246 but has a slightly different configuration path. In my production code, I'm using DI to configure the FlurlClientCache with defaults. I was able to duplicate this issue when configuring the cache defaults, or directly on a FlurlClient or FlurlRequest. However, if configuring FlurlHttp.Clients.WithDefaults, it works properly.
It seems to me the issue is in the HttpTest WithRequestJson (or similar) methods that deserialize the request or response body using the settings of HttpTest rather than the settings that are currently in effect at the call level. As a result, the assertion uses a different serializer configuration than the actual call, which then fails the assertion.
As in the linked issue, I can set the JsonSerializer on the HttpTest instance, but that doesn't work if I have different serializer settings on different clients or requests at the same time. (But who would do that? :) )
The text was updated successfully, but these errors were encountered: