bUnit-dev/bUnit

I got a execption in .NET 8: Method not found: 'System.String Microsoft.AspNetCore.Components.CascadingParameterAttributeBase.get_Name()'.

ElderJames opened this issue · 1 comments

Describe the bug

Example:
Testing this component:

Component under test

With this test:

   [Fact]
    //PR #1906 https://github.com/ant-design-blazor/ant-design-blazor/pull/1906#issuecomment-912615575
    public void Keep_value_when_corresponding_item_in_DataSource_removed() 
    {
        //Arrange
        JSInterop.Setup<AntDesign.JsInterop.DomRect>(JSInteropConstants.GetBoundingClientRect, _ => true)
            .SetResult(new AntDesign.JsInterop.DomRect());
        var selectedPersion = _persons[2];
        int value = 0;
        Action<int> ValueChanged = (v) => value = v;        
        var cut = Render<AntDesign.Select<int, Person>>(
            @<AntDesign.Select DataSource="@_persons"
                LabelName="@nameof(Person.Name)"
                ValueName="@nameof(Person.Id)"
                Value="@selectedPersion.Id"
                ValueChanged="@ValueChanged"
                >
            </AntDesign.Select>
        );
        var prevSelectedItem = cut.Find(".ant-select-selection-item").TextContent.Trim();
        //Act
        _persons.Remove(_persons.First(x => x.Id == value));        
        cut.SetParametersAndRender(parameters => parameters.Add(p => p.DataSource, _persons));
        //Assert        
        prevSelectedItem.Should().Be(selectedPersion.Name);
        cut.Invoking(c => c.Find(".ant-select-selection-item"))
            .Should().Throw<Bunit.ElementNotFoundException>();
        value.Should().Be(selectedPersion.Id);
        cut.Instance.Value.Should().Be(selectedPersion.Id);
    }

Results in this output:

 System.MissingMethodException : Method not found: 'System.String Microsoft.AspNetCore.Components.CascadingParameterAttributeBase.get_Name()'.
  Stack Trace:
     at Bunit.ComponentParameterCollectionBuilder`1.GetParameterInfo[TValue](Expression`1 parameterSelector)
   at Bunit.ComponentParameterCollectionBuilder`1.Add[TValue](Expression`1 parameterSelector, TValue value) in /_/src/bunit.core/ComponentParameterCollectionBuilder.cs:line 51
   at AntDesign.Tests.Select.Select_Value_Tests.<>c__DisplayClass7_0.<Keep_value_when_corresponding_item_in_DataSource_removed>b__3(ComponentParameterCollectionBuilder`1 parameters) in D:\Work\StudyCode\ant-design-blazor\tests\AntDesign.Tests\Select\Select.Value.Tests.razor:line 59
   at Bunit.ComponentParameterCollectionBuilder`1..ctor(Action`1 parameterAdder) in /_/src/bunit.core/ComponentParameterCollectionBuilder.cs:line 38
   at Bunit.RenderedComponentRenderExtensions.SetParametersAndRender[TComponent](IRenderedComponentBase`1 renderedComponent, Action`1 parameterBuilder) in /_/src/bunit.core/Extensions/RenderedComponentRenderExtensions.cs:line 75
   at AntDesign.Tests.Select.Select_Value_Tests.Keep_value_when_corresponding_item_in_DataSource_removed() in D:\Work\StudyCode\ant-design-blazor\tests\AntDesign.Tests\Select\Select.Value.Tests.razor:line 59      
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Expected behavior:

Version info:

  • bUnit version: bunit.web 1.23.9
  • .NET Runtime and Blazor version: .NET 8
  • OS type and version:

Additional context:

Ok, I found this #1239