Skip to content

Commit 4fd0a0f

Browse files
csharpfritzCopilot
andcommitted
Add 39 tests for FormShim dual-mode and WebFormsForm component (FritzAndFriends#533)
- FormShimTests.cs: 27 tests covering SSR (IFormCollection) and interactive (Dictionary<string, StringValues>) modes for indexer, GetValues, AllKeys, Count, ContainsKey, and SetFormData mutation - WebFormsFormTests.razor: 12 bUnit tests for form rendering, Method/Action parameters, ChildContent, HtmlAttributes, and default POST method - Fix WebFormsForm.razor: add @inherits ComponentBase to prevent duplicate CaptureUnmatchedValues from BaseWebFormsComponent via _Imports.razor - Fix RequestShim.cs: disambiguate FormShim(null) constructor call Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f561482 commit 4fd0a0f

6 files changed

Lines changed: 779 additions & 3 deletions

File tree

.squad/agents/rogue/history.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,20 @@ Conventions discovered: SessionShim uses Shouldly assertions + xUnit `[Fact]` (m
516516
- Fully-qualified `BlazorWebFormsComponents.BaseWebFormsComponent` required — test project has a `BaseWebFormsComponent/` folder creating namespace ambiguity. Same for `System.EventArgs` vs `EventArgs/` folder.
517517
- `dotnet test --filter` uses `|` for OR (not `OR` keyword) in vstest filter expressions.
518518

519+
### FormShim & WebFormsForm Tests (Issue #533)
520+
521+
**39 new tests — all passing.** Created 2 test files covering FormShim dual-mode support and WebFormsForm component rendering.
522+
523+
**Test files created:**
524+
- `FormShimTests.cs` (27 tests, all pass): Dual-mode coverage for SSR (IFormCollection) and interactive (Dictionary<string, StringValues>) paths. Tests indexer, GetValues, AllKeys, Count, ContainsKey for both modes plus null/empty. SetFormData mutation tests for interactive mode (populate, replace, multi-value preservation).
525+
- `WebFormsForm/WebFormsFormTests.razor` (12 tests, all pass): bUnit rendering tests — form element renders, default method is POST, Method/Action parameters, ChildContent renders inside form, HtmlAttributes (class, id, data-*), multiple attributes, empty form, nested elements.
526+
527+
**Bug found and fixed:**
528+
- `WebFormsForm.razor` was missing `@inherits ComponentBase`, causing it to inherit `BaseWebFormsComponent` via `_Imports.razor`. Both `BaseWebFormsComponent` and `WebFormsForm` had `[Parameter(CaptureUnmatchedValues = true)]`, causing `ThrowForMultipleCaptureUnmatchedValuesParameters` at render time. Fixed by adding explicit `@inherits ComponentBase`.
529+
- `RequestShim.cs` line 79: `new FormShim(null)` was ambiguous between `FormShim(IFormCollection?)` and `FormShim(Dictionary<string, StringValues>)`. Fixed by casting to `(IFormCollection?)null`.
530+
531+
**Key patterns:**
532+
- FormShim tests are pure C# xUnit (no bUnit needed) — use `new FormCollection(dict)` for SSR mock data.
533+
- WebFormsForm tests use `.razor` bUnit pattern inheriting `BlazorWebFormsTestContext`.
534+
- Any `.razor` component in the main project that should NOT inherit `BaseWebFormsComponent` must have explicit `@inherits ComponentBase` to override the project-level `_Imports.razor`.
535+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# WebFormsForm must inherit ComponentBase explicitly
2+
3+
**Author:** Rogue (QA)
4+
**Date:** 2026-07
5+
**Scope:** WebFormsForm.razor, RequestShim.cs
6+
**Issue:** #533
7+
8+
## Decision
9+
10+
Any `.razor` component in the main project that should NOT be a Web Forms control must explicitly declare `@inherits ComponentBase` to override the project-level `_Imports.razor` (which specifies `@inherits BaseWebFormsComponent`).
11+
12+
## Bugs Found
13+
14+
1. **WebFormsForm.razor** — Missing `@inherits ComponentBase` caused it to inherit `BaseWebFormsComponent` via `_Imports.razor`. Both classes had `[Parameter(CaptureUnmatchedValues = true)]`, throwing `ThrowForMultipleCaptureUnmatchedValuesParameters` at render time. Fixed by adding `@inherits ComponentBase`.
15+
16+
2. **RequestShim.cs line 79**`new FormShim(null)` was ambiguous between `FormShim(IFormCollection?)` and `FormShim(Dictionary<string, StringValues>)` after the dual-mode constructor was added. Fixed by casting to `(IFormCollection?)null`.
17+
18+
## Impact
19+
20+
Both fixes are required for the WebFormsForm component to render at all. Without them, any page using `<WebFormsForm>` crashes at component initialization.

0 commit comments

Comments
 (0)