Skip to content

Adding cascading parameters with parameterbuilder using expression-based .Add() does not work correctly. #196

@benjaminsampica

Description

@benjaminsampica

Describe the bug or question
The bUnit section here describes three different ways of populating cascading parameters. The first and second way do currently work, but the third however does not. This tripped me up for an hour while I finally narrowed it down to bUnit being the issue.

The below classes/tests are all pulled directly from the above docs.

Example:
Testing this component:

    public class CascadingParams : ComponentBase
    {
        [CascadingParameter]
        public bool IsDarkTheme { get; set; }

        [CascadingParameter(Name = "LoggedInUser")]
        public string UserName { get; set; }

        [CascadingParameter(Name = "LoggedInEmail")]
        public string Email { get; set; }
    }

With this test:

            using var ctx = new TestContext();
            var isDarkTheme = true;

            // Using factory method
            var cut1 = ctx.RenderComponent<CascadingParams>(
              CascadingValue(isDarkTheme)
            );

            // Using parameter builder
            var cut2 = ctx.RenderComponent<CascadingParams>(parameters => parameters
              .Add(isDarkTheme)
            );

            // Using parameter builder and selecting unnamed cascading parameter
            var cut3 = ctx.RenderComponent<CascadingParams>(parameters => parameters
              .Add(p => p.IsDarkTheme, isDarkTheme)
            );

            cut1.Instance.IsDarkTheme.Should().BeTrue();
            cut2.Instance.IsDarkTheme.Should().BeTrue();
            cut3.Instance.IsDarkTheme.Should().BeTrue();

Results in this output:

Result Message:	Expected cut3.Instance.IsDarkTheme to be true, but found False.

Expected behavior:
cut3 assertion should be true.

Version info:

  • Library version: 1.0.0-beta-9
  • .NET Core/Blazor version: 3.1, 5.0

Additional context:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions