# bUnit 2.7.2 Standardization Implementation Plan > **For Codex:** REQUIRED SUB-SKILL: Use `executeplan` to implement this plan task-by-task. **Goal:** Standardize every existing bUnit test project on stable bUnit **2.7.2**, migrate its test API and prove dependency/runtime compatibility before any Theme or application UI implementation. **Architecture:** Upgrade test dependencies in their current repository-owned version files and migrate tests in small commits, retaining each repository's xUnit generation, runtime, production packages and behavioral assertions. Establish a shared compatibility record, then close a mandatory cross-repository gate **GB**. Do not introduce bUnit into projects using HtmlRenderer, native Perspective or Playwright alone. **Tech Stack:** .NET 10, bUnit 2.7.2, existing xUnit v2/v3 runners and test SDKs, AngleSharp/Css/Diffing, existing JSInterop/auth/navigation fakes and repository test fixtures. --- ## Order, inventory and scope Execute this chapter after G0 inventory and **before TH-01, every shared UI task and every local UI task**. GB is the prerequisite for the whole remaining plan, including Secrets target isolation. Baseline discovery is allowed before GB; UI implementation is not. Package/test changes here ship as test-only commits, without Theme publication or application deployment. [Source/package inventory](bunit-inventory.json) records seven actual test projects. Its `obj/project.assets.json` observations are cached local evidence, not fresh restores or passing runs. Re-discover all authored `.csproj`, `.props`, `.targets`, lock files and conditional/central package references before execution; exclude hidden worktrees/build outputs. Add newly discovered bUnit consumers to this chapter and the ledger before closing GB. | Project | Current bUnit declaration | Version authority | Migration task | |---|---|---|---| | Theme | 2.7.2 | `scadaproj/ZB.MOM.WW.Theme/Directory.Packages.props` | BU-03: retain pin, verify graph/runtime | | ScadaBridge CentralUI.Tests | 2.7.2 | `ScadaBridge/Directory.Packages.props` | BU-04: retain pin, resolve parser policy/runtime | | Secrets.Ui.Tests | 1.40.0 | `scadaproj/ZB.MOM.WW.Secrets/Directory.Packages.props` | BU-05 | | Overview.Tests | 1.40.0 | Test `.csproj` | BU-06 | | OtOpcUa AdminUI.Tests | 2.0.33-preview | `OtOpcUa/Directory.Packages.props` | BU-07 | | HistorianGateway.Tests | 1.40.0 | Test `.csproj` | BU-08 | | BTDB Manager.Tests | 1.40.0 | Test `.csproj`; no central package management | BU-09 | All paths in the table expand under `/Users/dohertj2/Desktop/`. The exact test project paths and runner versions are in the inventory and task commands below. Preserve OtOpcUa's xUnit v3/Akka TestKit stack and the other projects' xUnit v2 stacks. A central package edit can affect other tests: restore/build those affected projects as part of verification. MxAccessGateway, OEE router static-renderer tests, registry Playwright tests and native Perspective remain on their existing test approaches. Their subsequent UI work still waits for GB so the entire family starts Theme implementation from a verified common bUnit baseline. ## Compatibility decisions and stop conditions 1. Pin `bunit` **exactly 2.7.2** in each current authority; no floating range, preview, local shim, second bUnit generation, or fallback to a newer unrequested version. Remove direct `bunit.core`/`bunit.web` references only if discovery finds them; check third-party test helpers for old transitive bUnit dependencies. 2. Inspect the **actual restored** `project.assets.json` and nuspecs, including dependency groups for net10.0, AngleSharp, AngleSharp.Css/Diffing, Microsoft.AspNetCore.Components.*, test SDK and runner. The cached bUnit 2.7.2 nuspec declares AngleSharp minimum 1.4.0, Css beta.157 and Diffing 1.1.1; that does not prove patched-parser compatibility. 3. Prefer the already-declared patched AngleSharp 1.5.2 candidate; also probe 1.5.0 where existing Theme evidence uses it. Record the tested exact supported parser version per project; use a common patched version if all full graphs support it. Parser patch uniformity is desirable, but the hard requirement is bUnit 2.7.2 plus a demonstrated compatible and acceptable dependency graph. 4. Secrets currently has a central AngleSharp version declaration without a direct UI-test reference; its cached UI graph still resolves 1.2.0. A `PackageVersion` alone is not a direct dependency. Plan an explicit test-only reference if needed. Add the central parser version plus test-only reference in OtOpcUa/ScadaBridge if the validated combination requires it; do not put parser dependencies in production projects. 5. Existing ScadaBridge/OtOpcUa comments report patched-parser binary failures and scoped GHSA suppression; Theme notes claim a patched combination works. Treat both as hypotheses until **render/query/event tests execute** against the resolved binaries. Compilation, restore or matching version strings do not resolve this disagreement. 6. Run existing NuGet vulnerability/transitive checks without setting `NuGetAudit=false`, adding broad NoWarn or expanding suppressions. Remove the old advisory suppression only after the resolved graph and runtime evidence support removal. If bUnit 2.7.2 cannot meet both runtime compatibility and accepted dependency policy, keep GB incomplete with the exact failing versions/stack trace and a concrete compatibility decision for the owner. Do not silently choose a vulnerable downgrade, a different bUnit version or skip the failing tests to declare success. 7. Do not replace real authorization, renderer dispatch, cancellation, disposal or timing behavior with mocks merely to make the upgrade pass. Keep the separate browser tests for native focus/inertness; bUnit does not prove those behaviors. ## Migration contract for all later chapters The plan's later code snippets now assume this post-GB API. Apply changes to actual repository fixtures during this phase, not by postponing compile fixes to the UI tasks. | Previous bUnit API where present | Post-GB API/action | |---|---| | `Bunit.TestContext` | `BunitContext`; migrate fixtures and helper signatures | | `RenderComponent` | `Render` | | `cut.SetParametersAndRender(...)` | `cut.Render(...)` | | `AddTestAuthorization()` | `AddAuthorization()`; preserve roles/policies/claims | | Fake-prefixed bUnit doubles | Corresponding Bunit-prefixed type, including navigation/auth helpers | | Non-generic rendered fragment/markup abstractions | Appropriate `IRenderedComponent` with actual component/ContainerFragment type | | `DisposeComponents()` | Await `DisposeComponentsAsync()`; use correct runner lifecycle for async services | | Event helper optional argument overloads | Explicit event args; keep original event semantics | | Auto-refreshing element collections | Re-query `FindAll` after render changes | These changes follow the [official migration guide](https://bunit.dev/docs/migrations/1to2.html) and [authorization documentation](https://github.com/bunit-dev/bunit/blob/main/docs/site/docs/test-doubles/auth.md). Check the exact 2.7.2 assembly/XML API during execution because current online docs can move forward. **Never globally replace `Xunit.TestContext.Current` in OtOpcUa**: it supplies runner cancellation, not a bUnit renderer. Likewise keep framework `HtmlRenderer.RenderComponentAsync` unchanged. ## Task BU-01: Record pre-upgrade tests and package graphs **Files:** create `/Users/dohertj2/Desktop/scadaproj/components/ui-theme/validation/bunit-2.7.2/BASELINE.md` and per-project result/graph records there; read the seven test projects and their version files in `bunit-inventory.json`. 1. Record HEAD, SDK, test project, target framework and existing dirty changes per repository. Do not overwrite current work. Locate global/aliased imports, helper base classes, rendered-type signatures and authorization/JSInterop doubles. 2. From each project root run `dotnet restore ` and `dotnet list package --include-transitive`. Record actual resolved versions and relevant audit/suppression context. Use configured approved public/private sources; do not log credentials or proprietary feed headers. 3. Run `dotnet test -c Release --list-tests` and `dotnet test -c Release --logger "trx;LogFileName=before.trx" --results-directory `. Use the exact project paths in BU-03–09. Record discovery count, passed/failed/skipped totals, skipped reasons and pre-existing failures. 4. Mark SQL/Windows/native/live fixtures separately and provision disposable required fixtures for execution where available. Missing infrastructure is not an upgrade regression or a passing test; unverified affected behavior remains an explicit gate item. 5. Commit inventory/baseline evidence only, excluding secrets, runtime data, generated bin/obj and unrelated changes. Expected: a reproducible before record for all seven projects and a list of active migration sites. No test suite is claimed green unless actually run. ## Task BU-02: Prove the dependency candidate with a minimal render probe **Files:** create temporary probes under `/tmp/scada-bunit-compat//`; create the compatibility matrix at `/Users/dohertj2/Desktop/scadaproj/components/ui-theme/validation/bunit-2.7.2/COMPATIBILITY.md`. Final project pins are applied by BU-03–09. 1. Build a net10.0 xUnit v2 probe with bUnit 2.7.2, a direct candidate AngleSharp reference, the existing Theme test SDK/runner versions, and FrameworkReference Microsoft.AspNetCore.App. Use exact versions, an isolated package directory, and configured approved sources. Do not copy a production configuration or start a service. Minimal `BunitCompatibility.csproj` for the 1.5.2 candidate (use 1.5.0 only in the separate candidate directory): ```xml net10.0 true false enable enable ``` Restore each probe with `dotnet restore /tmp/scada-bunit-compat//BunitCompatibility.csproj --packages /tmp/scada-bunit-compat//packages` using a temporary NuGet.Config containing the repository-approved sources, without plaintext credentials. This isolates the dependency resolution from a stale global package directory; retain the resolved assets as probe evidence. 2. Use this complete runtime probe as one test file (retain existing project global usings or add the imports shown): ```csharp using Bunit; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Rendering; using Xunit; public sealed class BunitCompatibilityTests : BunitContext { [Fact] public void Render_query_click_rerender_and_authorization_are_available() { var auth = this.AddAuthorization(); auth.SetAuthorized("synthetic-user"); auth.SetRoles("Viewer"); var cut = Render(); Assert.Equal("Count 0", cut.Find("button").TextContent); cut.Find("button").Click(); Assert.Equal("Count 1", cut.Find("button").TextContent); Assert.Single(cut.FindAll("button")); } public sealed class Probe : ComponentBase { private int count; protected override void BuildRenderTree(RenderTreeBuilder b) { b.OpenElement(0, "button"); b.AddAttribute(1, "onclick", EventCallback.Factory.Create(this, () => count++)); b.AddContent(2, $"Count {count}"); b.CloseElement(); } } } ``` 3. Run `dotnet test /tmp/scada-bunit-compat//BunitCompatibility.csproj -c Release`. First run each candidate against the exact restored graph; expected acceptance is discovery plus successful render/query/event/rerender without TypeLoadException/MissingMethodException. A failure records actual evidence, not a reason to weaken assertions. The class exercises basic API/runtime availability; real policy evaluation and host-specific helpers are tested in the seven suites. 4. Probe the explicitly relevant 1.5.2 and 1.5.0 candidates, inspecting resolved Css/Diffing and framework groups. Record which exact combination is acceptable before applying pins. A simple probe is necessary but not sufficient: each real project migration must pass its own tests. 5. Record any required parser pin as `ANGLESHARP_VERSION` resolved to an actual tested version during execution. If no acceptable combination works, retain the exact bUnit target and leave GB blocked; document follow-up rather than claiming compatibility. No new production dependencies are introduced. ## Shared steps for each project migration Execute these steps separately in BU-03–09, using that task's files, commands and focused suites: 1. Apply exact bUnit/parser pins in the listed authority, then restore and build the test project. For a 1.x/preview project, capture the compile/API errors as the expected migration red state; for an already-2.7.2 project use the actual runtime/graph baseline instead of inventing a failing test. 2. Migrate the discovered API sites, helpers, inherited contexts, auth doubles, rerenders and disposals according to the table above. Preserve all assertions and role/clock/JSInterop fixtures. Retain strict JSInterop; register only the module/invocations actually needed by existing components. 3. Execute existing render, auth, event, async wait/disposal and representative domain tests before running the full project. If async services require disposal, use the runner's actual v2/v3 lifecycle signatures; do not block on async disposal or declare it complete without awaiting it. 4. Run the full project, compare discovered/executed/skipped results to BU-01, inspect resolved packages and test output. No removed tests, blanket skips, disabled warning policies, deleted behavioral assertions or new arbitrary delays are allowed as migration fixes. 5. Run affected neighboring tests/builds when a central pin or shared helper changed. Record actual runtime-dependent suites separately, including what fixtures are required to close them. 6. Record after graph/TRX and commit test dependencies/tests/docs only, one repository/project slice per commit. Leave production UI and Theme release versions unchanged. Keep the previous complete dependency/test commit for rollback; do not mix old helper binaries with the new package. ## Task BU-03: Verify Theme's existing stable baseline **Cwd:** `/Users/dohertj2/Desktop/scadaproj/ZB.MOM.WW.Theme`. **Files:** `Directory.Packages.props`; `tests/ZB.MOM.WW.Theme.Tests/ZB.MOM.WW.Theme.Tests.csproj`; existing test fixtures under `tests/ZB.MOM.WW.Theme.Tests/`. Follow the shared migration steps: retain bUnit 2.7.2; verify the parser direct reference resolves the chosen patched candidate. Run `dotnet test tests/ZB.MOM.WW.Theme.Tests/ZB.MOM.WW.Theme.Tests.csproj -c Release --filter 'FullyQualifiedName~CommonControlsTests|FullyQualifiedName~ThemeShellTests|FullyQualifiedName~TechButtonExtensionsTests|FullyQualifiedName~TreeTableTests'`, then the full project. Expected: render/query/event/class/disabled/tree behavior stays green with no binary parser errors. Record the exact graph; existing documentation is not evidence of this run. Commit `test(theme): verify standard bUnit dependency baseline` if pins/docs actually change; otherwise record a verification-only evidence commit. ## Task BU-04: Verify ScadaBridge 2.7.2 and reconcile its parser suppression **Cwd:** `/Users/dohertj2/Desktop/ScadaBridge`. **Files:** `Directory.Packages.props`; `tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests.csproj`; test fixture/helper files beneath that test directory. Retain bUnit 2.7.2. The current graph/suppression is specifically part of this task: evaluate the patched candidate with actual runtime renders; add a direct test-only parser reference if necessary, using central management. Update historical incompatibility comments only after evidence; do not erase the warning by disabling audit. Run `dotnet test tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests.csproj -c Release --filter 'FullyQualifiedName~ComponentRenderingTests|FullyQualifiedName~DataConnectionFormTests|FullyQualifiedName~TopologyPageTests'`, then the full project and affected dependency suites. Retain current BunitContext/Render and test doubles where already migrated. Commit `test(scadabridge): validate bUnit parser and render compatibility`. ## Task BU-05: Upgrade Secrets UI tests and enforce its real parser reference **Cwd:** `/Users/dohertj2/Desktop/scadaproj/ZB.MOM.WW.Secrets`. **Files:** `Directory.Packages.props`; `tests/ZB.MOM.WW.Secrets.Ui.Tests/ZB.MOM.WW.Secrets.Ui.Tests.csproj`; all eight current UI test fixture files (SecretEditorTests, SecretEditorAddExistingTests, SecretsListTests, ConfirmDeleteModalTests, RevealButtonTests, ComponentAuthorizationTests, RevealAuditFailureTests, AuditFailureAfterCommitTests). Set central bUnit to 2.7.2. Add an explicit `` to the UI test project if needed so its selected central version is actually consumed; a central entry alone previously left cached 1.2.0. Migrate BunitContext/Render/AddAuthorization and helper signatures, including callback-driven rerenders and context disposal. Run `dotnet test tests/ZB.MOM.WW.Secrets.Ui.Tests/ZB.MOM.WW.Secrets.Ui.Tests.csproj -c Release --filter 'FullyQualifiedName~ComponentAuthorizationTests|FullyQualifiedName~SecretEditorTests|FullyQualifiedName~RevealAuditFailureTests|FullyQualifiedName~AuditFailureAfterCommitTests'`, then the full UI test project and tests affected by the central change. Expected: audit-before-reveal, success-after-commit/audit-failure and handler authorization remain unchanged. Commit `test(secrets): migrate UI suites to bUnit 2.7.2`. ## Task BU-06: Upgrade Overview tests and preserve timer lifecycle assertions **Cwd:** `/Users/dohertj2/Desktop/scadaproj/ZB.MOM.WW.Overview`. **Files:** `tests/ZB.MOM.WW.Overview.Tests/ZB.MOM.WW.Overview.Tests.csproj`; `InstanceCardTests.cs`, `OverviewPageTests.cs` in that test directory; its global using/helper declarations if affected. Pin bUnit 2.7.2 directly; retain/validate the patched parser pin using BU-02. Migrate TestContext/RenderComponent and shared render helper return types; preserve fake clock, store publication, synchronization and disposal behavior. Run `dotnet test tests/ZB.MOM.WW.Overview.Tests/ZB.MOM.WW.Overview.Tests.csproj -c Release --filter 'FullyQualifiedName~InstanceCardTests|FullyQualifiedName~OverviewPageTests'`, then the full project including boot/probe tests. Expected: pause/adopt/resume, stale aging and event unsubscription assertions stay green without adding sleeps. Commit `test(overview): migrate renderer fixtures to bUnit 2.7.2`. ## Task BU-07: Replace OtOpcUa's preview while preserving xUnit v3 cancellation **Cwd:** `/Users/dohertj2/Desktop/OtOpcUa`. **Files:** `Directory.Packages.props`; `tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/ZB.MOM.WW.OtOpcUa.AdminUI.Tests.csproj`; discovered bUnit fixtures under that directory, especially `Pages/DeleteConfirmRenderTests.cs` and renderer/auth helpers. Replace preview 2.0.33 with exactly 2.7.2. Add a central/direct test-only parser pin if validated; revisit the TypeLoadException explanation and scoped advisory suppression using evidence. Current BunitContext/Render use reduces rename work but does not establish compatibility with stable release. Preserve xunit.v3 3.2.2, its runner and Akka.TestKit.Xunit: **Xunit.TestContext.Current.CancellationToken stays unchanged**. Migrate only bUnit authorization/double/obsolete APIs found by discovery. Run `dotnet test tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/ZB.MOM.WW.OtOpcUa.AdminUI.Tests.csproj -c Release --filter FullyQualifiedName~DeleteConfirmRenderTests`, then the full AdminUI test project; classify SQL fixture prerequisites explicitly. Run affected central-package consumers once. Expected: real delete confirmation, authorization, event dispatch and cancellation regressions remain protected. Commit `test(otopcua): replace bUnit preview with 2.7.2`. ## Task BU-08: Upgrade HistorianGateway dashboard fixtures **Cwd:** `/Users/dohertj2/Desktop/HistorianGateway`. **Files:** `tests/ZB.MOM.WW.HistorianGateway.Tests/ZB.MOM.WW.HistorianGateway.Tests.csproj`; dashboard fixtures `GalaxyBrowserPageRenderTests.cs`, `StatusPageRenderTests.cs`, `HealthPageRenderTests.cs`, `HistorianConsolePageRenderTests.cs`, `LayoutRenderTests.cs`, `ApiKeysPageRenderTests.cs`, `LayoutNavAuthorizationTests.cs` under `Dashboard/`. Pin bUnit 2.7.2 and validated parser dependency in this test project; migrate contexts/render/auth/doubles and any async lifetime handling. Keep test-only framework references supporting rendered components. Run `dotnet test tests/ZB.MOM.WW.HistorianGateway.Tests/ZB.MOM.WW.HistorianGateway.Tests.csproj -c Release --filter FullyQualifiedName~Dashboard`, then the full project. Expected: Viewer/Admin gating, history query payloads and write gating still pass; no real historian write is required. Preserve native/Windows fixture distinctions. Commit `test(historiangateway): migrate dashboard tests to bUnit 2.7.2`. ## Task BU-09: Upgrade BTDB fixture helpers and navigation/auth doubles **Cwd:** `/Users/dohertj2/Desktop/BTDB`. **Files:** `tests/ZB.MOM.WW.BTDB.Manager.Tests/ZB.MOM.WW.BTDB.Manager.Tests.csproj`; helpers `Auth/RealPolicyAuthorization.cs`, `Shared/AuthorizeTestHelper.cs`; bUnit fixtures beneath `Layout/`, `Shared/`, `Pages/` discovered by BU-01. Pin bUnit 2.7.2 directly; no new central package-management file. Validate parser pin; migrate TestContext/RenderComponent/auth helpers and FakeNavigationManager types where actually used. Preserve real policy registration rather than replacing it with unconditional authorization. Run `dotnet test tests/ZB.MOM.WW.BTDB.Manager.Tests/ZB.MOM.WW.BTDB.Manager.Tests.csproj -c Release --filter 'FullyQualifiedName~MachineFormTests|FullyQualifiedName~DialogServiceTests|FullyQualifiedName~EditableRowsTests|FullyQualifiedName~MainLayoutRailTests'`, then the full Manager test project and existing Manager.Core tests. Expected: Cancel rollback, row snapshot identity, full timestamp precision, role gates and host boot regressions stay covered. Do not alter navigation production code in this migration. Commit `test(btdb): migrate component fixtures to bUnit 2.7.2`. ## Task BU-10: Verify cross-project consistency and close GB **Files:** update compatibility/baseline records and add `/Users/dohertj2/Desktop/scadaproj/components/ui-theme/validation/bunit-2.7.2/ACCEPTANCE.md`; add the same actual package/commit/TRX references to each repository's relevant test documentation. Update stale bUnit/parser comments and test examples; runtime UI recommendations remain historical evidence. 1. Re-discover authored bUnit consumers and assert the set matches the recorded inventory. Use `dotnet list package --include-transitive` and resolved assets to prove **all seven resolve bunit/2.7.2** with no legacy core/web generation. Central declarations alone do not prove this. 2. Run each migrated test project in Release from a clean restore against approved configured sources, with a fresh test output directory. Preserve vulnerability checks. Verify parser/Css/Diffing/framework/runner versions match the accepted matrix and the same assembly versions actually load at render runtime. 3. Compare before/after discovery and TRX by test identity, passed/failed/skipped totals and reasons. A parameterized-test count change must be explained rather than mistaken for missing coverage. No unexplained loss, new blanket skip, weakened assertion, binary load error or hang may remain. 4. Exercise the representative runtime contracts: render/query/click/rerender; allowed/denied role/policy; strict JSInterop; async completion/waits; cancellation; context/component/service disposal. Use synthetic fixtures; no production mutation. Run impacted non-bUnit suites only as warranted by central/shared changes. 5. Inspect release/publish graphs: bUnit, AngleSharp test pins and xUnit must not newly enter production package/runtime dependencies. Archive actual package versions, warnings/advisory disposition, source commits and test evidence; exclude real secrets and generated build trees. 6. Close **GB only after every bUnit project and its required affected behavior is verified**. Missing fixture/infrastructure or dependency-policy incompatibility leaves the exact check incomplete and blocks Theme/UI execution; record the required next action. Do not lower the bUnit target or bypass this gate because two projects were already on it. 7. Commit `docs(testing): record family bUnit 2.7.2 acceptance`. Then execute the original Theme-first UI sequence unchanged in design scope. ## Rollback and completion This phase changes test dependencies, fixtures/helpers and their documentation only. Roll back a failed slice as one coherent test/dependency commit, retaining the prior graph and evidence; do not restore a single DLL, publish a downgraded Theme, mutate data or revert unrelated production code. If any project returns to an old bUnit version, reopen GB. Later UI chapters must not silently reintroduce old APIs or package versions. - [ ] Seven projects freshly resolve exact stable 2.7.2, including existing adopters and OtOpcUa preview replacement. - [ ] AngleSharp family and .NET/test-runner compatibility verified by actual runtime tests and acceptable audit policy. - [ ] All applicable existing tests migrated with behavior and discovery preserved; explicit results for environment-dependent checks. - [ ] Async lifecycle and auth/navigation/JSInterop behavior validated without broad mocks/suppression/skips. - [ ] Later plan snippets use BunitContext/Render/AddAuthorization; framework HtmlRenderer and Xunit.TestContext remain untouched. - [ ] GB evidence recorded before any Theme or application UI task begins. No upgrade or test execution occurs while writing this plan. Expected results above are future acceptance criteria.