Skip to content

test(Table): add unload BootstrapBlazor_DynamicAssembly unit test#7909

Merged
ArgoZhang merged 4 commits intomainfrom
test-table
Apr 23, 2026
Merged

test(Table): add unload BootstrapBlazor_DynamicAssembly unit test#7909
ArgoZhang merged 4 commits intomainfrom
test-table

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Apr 23, 2026

Link issues

fixes #7908

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add unit tests to verify table behavior with dynamic contexts and ensure dynamic assemblies are not retained by Blazor change detection caching.

Enhancements:

  • Tidy table checkbox markup to better distinguish dynamic-object and non-dynamic-object selection handling.

Tests:

  • Add tests covering row selection in card view mode for dynamic objects using GUID-based checkboxes.
  • Add tests for header checkbox selection and deselection with dynamic contexts, including filtering selectable rows via ShowRowCheckboxCallback.
  • Add a test validating that dynamically generated types from BootstrapBlazor_DynamicAssembly are not cached in Blazor's change detection immutable types cache after table disposal.

Copilot AI review requested due to automatic review settings April 23, 2026 07:39
@bb-auto bb-auto Bot added the bug Something isn't working label Apr 23, 2026
@bb-auto bb-auto Bot added this to the v10.5.0 milestone Apr 23, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 23, 2026

Reviewer's Guide

Adds new unit tests around Table dynamic context selection behavior and BootstrapBlazor_DynamicAssembly unloadability, and slightly refactors checkbox markup to support dynamic-object GUID-based selection correctly.

Sequence diagram for Table row selection with dynamic objects

sequenceDiagram
    participant User as actor_User
    participant Table as TableComponent
    participant Item as RowItem
    participant Checkbox as CheckboxComponent

    User->>Table: Trigger row selection (click header/row)
    Table->>Item: Evaluate type
    alt Item implements IDynamicObject
        Table->>Checkbox: Render with Value = item.DynamicObjectPrimaryKey
        Table->>Checkbox: Set State = RowCheckState(item)
        Table->>Checkbox: Set OnStateChanged = OnCheckGuid
    else Regular item
        Table->>Checkbox: Render with Value = item
        Table->>Checkbox: Set State = RowCheckState(item)
        Table->>Checkbox: Set OnStateChanged = OnCheck
    end

    User->>Checkbox: Click checkbox
    Checkbox-->>Table: Invoke OnCheckGuid or OnCheck with new state
    Table->>Table: Update selected row collection based on Value
    Table-->>User: UI reflects updated selection state
Loading

File-Level Changes

Change Details Files
Add tests verifying DynamicContext selection behavior in CardView and header checkbox modes, including ShowRowCheckboxCallback filtering.
  • Render Table in CardView mode with multiple selection and verify per-row Checkbox toggling updates SelectedRows with DynamicObjectPrimaryKey
  • Render table with header checkbox in standard table mode and assert header toggle selects/deselects all dynamic rows
  • Render table with ShowRowCheckboxCallback that disables selection for some rows and assert header checkbox only selects allowed rows
test/UnitTest/Components/TableTest.cs
Add test ensuring dynamically generated BootstrapBlazor_DynamicAssembly types are not cached by Blazor ChangeDetection, so assemblies can be unloaded.
  • Render and dispose a dynamic Table instance to trigger ChangeDetection caching behavior
  • Use reflection to access internal _immutableObjectTypesCache ConcurrentDictionary on Microsoft.AspNetCore.Components.ChangeDetection
  • Assert no types from BootstrapBlazor_DynamicAssembly remain in the cache after disposal
test/UnitTest/Components/TableTest.cs
Adjust table row checkbox markup to use DynamicObjectPrimaryKey with GUID-valued checkboxes while preserving existing selection callbacks.
  • Split Checkbox attributes over multiple lines for clarity
  • Bind Checkbox Value to IDynamicObject.DynamicObjectPrimaryKey for dynamic rows and to the row item for non-dynamic rows
  • Keep OnStateChanged handlers wired to OnCheckGuid/OnCheck and StopPropagation enabled
src/BootstrapBlazor/Components/Table/Table.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#7908 Ensure that use of Table with DynamicContext does not prevent the BootstrapBlazor_DynamicAssembly from being unloaded (i.e., no lingering references such as in Blazor's ChangeDetection cache). The PR adds several unit tests, including DynamicContext_ChangeDetection_Ok, which verifies that types from the BootstrapBlazor_DynamicAssembly are not present in the Blazor ChangeDetection immutable types cache. However, the only change to production code (Table.razor) is a formatting change to the Checkbox markup, which does not alter behavior. The tests validate behavior but do not modify any logic that would affect assembly unloading, so the bug fix itself is not implemented by this PR.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang added test This is unit test and removed bug Something isn't working labels Apr 23, 2026
@bb-auto bb-auto Bot added bug Something isn't working and removed test This is unit test labels Apr 23, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The DynamicContext_ChangeDetection_Ok test relies on the internal type name and private field _immutableObjectTypesCache via reflection, which may be brittle across framework versions; consider centralizing these string literals (e.g., constants) and/or adding a defensive early-return if the type/field is not found rather than failing the test.
  • In DynamicContext_ChangeDetection_Ok, the assembly name "BootstrapBlazor_DynamicAssembly" is hard-coded; consider using a shared constant or deriving it from the dynamic context/assembly creation logic to keep the test resilient to future renames.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `DynamicContext_ChangeDetection_Ok` test relies on the internal type name and private field `_immutableObjectTypesCache` via reflection, which may be brittle across framework versions; consider centralizing these string literals (e.g., constants) and/or adding a defensive early-return if the type/field is not found rather than failing the test.
- In `DynamicContext_ChangeDetection_Ok`, the assembly name `"BootstrapBlazor_DynamicAssembly"` is hard-coded; consider using a shared constant or deriving it from the dynamic context/assembly creation logic to keep the test resilient to future renames.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (dd9fff8) to head (0ba7193).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #7909      +/-   ##
===========================================
+ Coverage   99.98%   100.00%   +0.01%     
===========================================
  Files         764       764              
  Lines       34337     34337              
  Branches     4711      4711              
===========================================
+ Hits        34333     34337       +4     
+ Misses          3         0       -3     
+ Partials        1         0       -1     
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ArgoZhang ArgoZhang merged commit b0f9989 into main Apr 23, 2026
10 checks passed
@ArgoZhang ArgoZhang deleted the test-table branch April 23, 2026 07:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new unit tests around Table<DynamicObject> selection behavior (Guid-backed checkbox values) and a regression test intended to ensure dynamically emitted assemblies remain unloadable (Issue #7908).

Changes:

  • Added bUnit tests for DynamicContext multi-select scenarios (CardView row toggle, header select-all, and ShowRowCheckboxCallback filtering).
  • Added a regression test that inspects Blazor ChangeDetection’s internal immutable type cache to ensure BootstrapBlazor_DynamicAssembly types are not retained.
  • Minor formatting-only change to CardView row checkbox markup in Table.razor.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/UnitTest/Components/TableTest.cs Adds new DynamicContext selection tests and a ChangeDetection cache regression test for dynamic assembly unloadability.
src/BootstrapBlazor/Components/Table/Table.razor Reflows CardView checkbox markup (no functional change expected).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6583 to +6595
var type = typeof(ComponentBase).Assembly.GetType("Microsoft.AspNetCore.Components.ChangeDetection");
Assert.NotNull(type);

var fieldInfo = type.GetField("_immutableObjectTypesCache", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
Assert.NotNull(fieldInfo);

IEnumerable<Type>? items = null;
if (fieldInfo.GetValue(null) is ConcurrentDictionary<Type, bool> cache)
{
items = cache.Keys.Where(i => i.Assembly.GetName().Name == "BootstrapBlazor_DynamicAssembly");
}
Assert.NotNull(items);
Assert.Empty(items);
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test relies on Blazor internal implementation details (internal type name Microsoft.AspNetCore.Components.ChangeDetection and private static field _immutableObjectTypesCache, plus a concrete ConcurrentDictionary<Type, bool> shape). Because CI uses a floating SDK (10.0.x), a framework patch could rename/move the type/field or change the cache type and cause unrelated test failures. Consider rewriting the assertion to validate unload without depending on private runtime fields (e.g., keep a WeakReference to a dynamically emitted type/assembly, dispose the component, force GC, and assert it can be collected), or at least tolerate missing/changed members by conditionally skipping/failing with a clearer message.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(Table): add BootstrapBlazor_DynamicAssembly unload test

2 participants