MVC / Razor Pages support for unions#67005
Open
DeagleGross wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds functional coverage to ensure C# union types flow correctly through MVC’s System.Text.Json input/output formatters and through Razor Pages handler binding + JsonResult responses, complementing the existing Minimal API union coverage.
Changes:
- Adds a new
FormatterWebSitecontroller + model types to exercise union binding/serialization scenarios via MVC. - Adds MVC functional tests for union request-body binding (input formatter) and union return-type serialization (output formatter).
- Adds a Razor Pages smoke test site page + functional test to validate unions behave similarly in Razor Pages.
Show a summary per file
| File | Description |
|---|---|
| src/Mvc/test/WebSites/RazorPagesWebSite/Pages/Unions.cshtml.cs | Adds a Razor Page handler that returns and accepts a union via [FromBody]. |
| src/Mvc/test/WebSites/RazorPagesWebSite/Pages/Unions.cshtml | Adds the Razor Page endpoint for the unions smoke test. |
| src/Mvc/test/WebSites/FormatterWebSite/Models/UnionTypes.cs | Defines a set of union types (primitive/object/nested/classifier) used by MVC functional coverage. |
| src/Mvc/test/WebSites/FormatterWebSite/Controllers/UnionsController.cs | Adds MVC endpoints to serialize unions and echo unions back (input + output path). |
| src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonOutputFormatterTest.Unions.cs | Adds output-formatter functional tests for union return types. |
| src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonOutputFormatterTest.cs | Marks the test class partial to split union tests into a separate file. |
| src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonInputFormatterTest.Unions.cs | Adds input-formatter functional tests for union request bodies (including ambiguous cases). |
| src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonInputFormatterTest.cs | Marks the test class partial to split union tests into a separate file. |
| src/Mvc/test/Mvc.FunctionalTests/RazorPagesUnionsTest.cs | Adds functional tests validating union behavior through the Razor Pages pipeline. |
Copilot's findings
- Files reviewed: 9/9 changed files
- Comments generated: 1
Comment on lines
+4
to
+6
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Text; |
Youssef1313
reviewed
Jun 3, 2026
| // [Theory] | ||
| // [InlineData("42", "42")] | ||
| // [InlineData("\"hi\"", "\"hi\"")] | ||
| // // TODO: enable null case after https://github.com/dotnet/runtime/issues/128688 is fixed. |
Member
There was a problem hiding this comment.
Can we uncomment and skip the test instead ([Theory(Skip = "...")])?
Youssef1313
reviewed
Jun 3, 2026
| // [Theory] | ||
| // [InlineData("int", "5")] | ||
| // [InlineData("string", "\"hi\"")] | ||
| // // TODO: enable a null arm once https://github.com/dotnet/runtime/issues/128688 is fixed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A follow-up of #66951 and #67001.
This PR adds tests to verify MVC and Razor Pages flow of union processing works, and different union usage cases are covered. MVC is a lower priority than Minimal API, but since the support is cheap, I am proposing to add coverage for MVC / Razor Pages as well.
Closes #66545