-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Fix code generation for parsing optional array parameters in RequestDelegateGenerator #57336
Conversation
…pointParameterEmitter.EmitParsingBlock` to be able to properly emit parsing logic for optional arrays.
…l point, because string interpolation made `12.3` as `12,3` failing the compilation.
@dotnet-policy-service agree |
align array creation more closely with the reflection delegate factory
This is our bespoke snapshot testing infrastructure. In order to use it, you'll have to add the call to the target unit test method, set this property in the test base class to true, run the test suite, reset the value of the property, then run the test suite again to observe the resulting behavior without this Assert.Fail spoiling your fun. Since we create a snapshot for each test method, I like to create a single test method that contains a test source with multiple endpoints with the conditions to test.
Thanks for this fix! We've got a few of these kinds of issues in the codebase since our team/CI machines primarily use an en-US culture. We should probably figure out a way to be resilient to this that doesn't rely on people with different locales running the test suite... 😅 |
@captainsafia Alright, I've added the missing baseline tests and this PR should be ready for review. |
|
||
await endpoint.RequestDelegate(httpContext); | ||
await VerifyResponseBodyAsync(httpContext, "[]"); | ||
await VerifyAgainstBaselineUsingFile(compilation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably exclude the baseline here since the generated code between MapAction_ExplicitQuery_IntArrayParam_Optional_QueryNotPresent
and MapAction_ExplicitQuery_IntArrayParam_Optional
is the same.
Alternatively, we could do one test method that uses a [Theory]
to test the scenario where a query is present and the one where it is not.
...uestDelegateGenerator/Baselines/MapAction_ExplicitQuery_IntArrayParam_Optional.generated.txt
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Fix code generation for parsing optional array parameters in RequestDelegateGenerator
Description
This PR aims to fix the invalid code generated for optional arrays in RequestDelegateGenerator (RDG), where the generated code tried to assign single element value into array variable.
The
EndpointParameter.ParsingBlockEmitter
property was lifted out ofEndpointParameter.TryGetParsability
intoEndpointParameterEmitter.EmitParsingBlock
method, to be able to properly condition all the parsing paths.I added 4 tests to cover the code path, but commented out
VerifyAgainstBaselineUsingFile
check. I can add them, but will need guidance on how to use this part of test infrastructure.This PR also contains a simple fix to
SupportsSingleKeyedServiceWithPrimitiveKeyTypes
test, that failed to compile on my machine due to culture specific handling of decimal point. I replaced simple.ToString()
call withConvert.ToString({value}, CultureInfo.InvariantCulture)
to force the value to be consistent across cultures.Fixes #57175