aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Use JSON source generator in WebApplicationFactory

Open martincostello opened this issue 9 months ago • 1 comments

Use JSON source generator in WebApplicationFactory

Use JSON source generator to deserialize dictionary.

Description

Use JSON source generator to deserialize JSON to prevent InvalidOperationException in a test project with JsonSerializerIsReflectionEnabledByDefault=false.

I wasn't sure how to test this without having to add an entirely new test project - happy to add something if someone can give a suggestion on how to go about that in a way that would be acceptable to the team.

Fixes #55586

martincostello avatar May 08 '24 07:05 martincostello

Thanks for your PR, @martincostello. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Just noticed that the old labels were set manually. Why networking, @mkArtakMSFT?

amcasey avatar May 15 '24 21:05 amcasey

FYI @captainsafia

amcasey avatar May 15 '24 21:05 amcasey

@martincostello TY for the PR.

We reference the Mvc.Testing package in other tests in the repo (Identity.FunctionalTests, MvcFunctionalTest, for example). We can probably verify whether or not this fix applies by setting the JsonSerializerIsReflectionEnabledByDefault property in those projects and checking if the change resolves any IOE.

captainsafia avatar May 17 '24 21:05 captainsafia

Playing around with Microsoft.AspNetCore.Mvc.FunctionalTests locally I get the following results:

JSON source generator? JsonSerializerIsReflectionEnabledByDefault Passed Failed
No true 1579 2
No false 4 1577
Yes true 1579 2
Yes false 1469 112

The tests that fail for me regardless of the settings are from AntiforgeryMiddlewareTest for Works_WithAntiforgeryMetadata_ValidToken and Works_WithAntiforgeryMetadata_ValidToken_DisableRequestSizeLimits - I'm not sure why.

martincostello avatar May 18 '24 08:05 martincostello

The tests that fail for me regardless of the settings are from AntiforgeryMiddlewareTest for Works_WithAntiforgeryMetadata_ValidToken and Works_WithAntiforgeryMetadata_ValidToken_DisableRequestSizeLimits - I'm not sure why.

#55779

martincostello avatar May 18 '24 08:05 martincostello

@captainsafia Anything more you need me to do here?

martincostello avatar Jun 18 '24 08:06 martincostello

/azp run

captainsafia avatar Jun 25 '24 01:06 captainsafia

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar Jun 25 '24 01:06 azure-pipelines[bot]

Mvc.TemplateTests are skipped and OpenAPI test fix is merged. Hopefully this goes through smoothly 🤞🏽

Edit: to that end I'll optimistically set auto-merge on this.

captainsafia avatar Jun 26 '24 17:06 captainsafia

build-ops; CI post-merge failure, but nothing to do with this PR; I'll try and poke some things

(CI failure is about changing "shipped" files inappropriately, which this PR does not even remotely do)

also an unrelated secondary failure about feel failures; I guess CI is having a very bad day

mgravell avatar Jun 27 '24 14:06 mgravell