docs(563): scope the required-member claim to the serializer, and name model validation as residue
The previous commit said a body omitting a `required` member "reaches the action" in production. That overreaches what was measured: MVC adds an implicit required check for non-nullable reference types (ErsatzTV.Core.Nullable has <Nullable>enable</Nullable>, and Startup configures no ApiBehaviorOptions, so the [ApiController] automatic 400 is live), which would very likely reject that body before the action. What is measured is the SERIALIZER: Newtonsoft deserializes it to a default, System.Text.Json throws. The prose in the test, ApiJsonSettings, the record and docs/testing.md now stops there and puts MVC model validation on the uncovered-wrapper list where it belongs. Decisions-Edit: yes Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015QqCpYFsKgnAnx6jVwrKiV
This commit is contained in:
@@ -33,9 +33,9 @@ namespace ErsatzTV.Tests.Controllers;
|
||||
/// The hops this cannot host, named rather than implied: the <c>Cli.Wrap</c> launch of the user's
|
||||
/// own program (exit code, timeout, stdout capture); the Kestrel/middleware/auth transport the
|
||||
/// program calls back over; and MVC's binding <i>wrapper</i> — the input formatter's content-type
|
||||
/// selection and malformed-body handling, and the <c>[ApiController]</c> automatic 400 a failed
|
||||
/// bind produces before an action runs, since every test here hands an action an already-bound
|
||||
/// object. The serializer <i>inside</i> that wrapper is not residue: request bodies are
|
||||
/// selection and malformed-body handling, model validation (a non-nullable reference type picks
|
||||
/// up an implicit required check there), and the <c>[ApiController]</c> automatic 400 either
|
||||
/// produces before an action runs, since every test here hands an action an already-bound object. The serializer <i>inside</i> that wrapper is not residue: request bodies are
|
||||
/// deserialized with <see cref="ApiJsonSettings" />, the same configuration <c>Startup</c> hands
|
||||
/// to <c>AddNewtonsoftJson</c>, so the fixture is bound the way production binds it. That is not
|
||||
/// a formality — Newtonsoft and System.Text.Json disagree on the DTOs' <c>required</c> members,
|
||||
@@ -133,10 +133,11 @@ public class ScriptedScheduleControllerTests
|
||||
{
|
||||
// The replay above is only faithful while Bind uses MVC's own serializer, and "the two agree" is
|
||||
// not a safe assumption to leave unstated: Newtonsoft has no notion of the C# `required` keyword,
|
||||
// so a body omitting one binds to a default and reaches the action, where System.Text.Json
|
||||
// rejects the body outright. This goes through Bind itself, which is what gives it teeth — the
|
||||
// fixture's own bodies parse identically under either serializer, so only a body like this one
|
||||
// can witness a swap.
|
||||
// so a body omitting one deserializes to a default, where System.Text.Json rejects it outright.
|
||||
// The claim is about the SERIALIZER only — what MVC's validation layer then does with such a
|
||||
// body (non-nullable reference types pick up an implicit required check) is the uncovered
|
||||
// wrapper, not this. Binding through Bind itself is what gives this teeth: the fixture's own
|
||||
// bodies parse identically under either serializer, so only a body like this one witnesses a swap.
|
||||
using JsonDocument document = JsonDocument.Parse(BodyMissingRequiredMember);
|
||||
|
||||
ContentCollection bound = Bind<ContentCollection>(document.RootElement).ShouldNotBeNull();
|
||||
|
||||
Reference in New Issue
Block a user