Skip to content

Ensure LazyAssemblyLoader is mockable in testing #24815

@egil

Description

@egil

Testing Blazor components that uses LazyAssemblyLoader is likely not going to be possible with bUnit without making it possible for the test to provide its own implementation of LazyAssemblyLoader as a mock.

Right now, the type is a sealed class, which will make mocking it hard (assuming this is the one that will ship in P8: .../Components/WebAssembly/WebAssembly/src/Services/LazyAssemblyLoader.cs - I did not find any other implementations while searching the repo).

Suggested solution - follow in NavigationManager's footsteps

Consider making LazyAssemblyLoader an abstract class, and with an abstract LoadAssembliesAsync(...) method. Then you can provide a sealed internal implementation which is used in production, and users are able to mock it during testing.

This works reasonably well with NavigationManager. Alternatively, expose the feature as an ILazyAssemblyLoader. This makes mocking even more intuitive for testers.

cc. @captainsafia

Related: bUnit-dev/bUnit#115

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: Won't FixResolved because we decided not to change the behavior reported in this issue.Status: Resolvedarea-blazorIncludes: Blazor, Razor Componentsfeature-blazor-lazy-loadingIssues related to adding support for lazy-loading in Blazorfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions