adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
588 stars 49 forks source link

Exception thrown with random control types when finding with a timespan #219

Closed powerdude closed 7 months ago

powerdude commented 7 months ago

Describe the bug I have a test that ultimately does this:

        var mainPage = TemplateHost.Create(new ShellPage()); 
        var shell = mainPage.Find<MauiControls.Shell>("MainShell");
        var muscleGroups = shell.Find<MauiControls.ShellContent>("MuscleGroups");

        shell.CurrentItem = muscleGroups;

        var name = await mainPage.Find<MauiControls.Label>("mg1-name", TimeSpan.FromSeconds(30));
        name.Text.Should()
            .Be("muscle group name 1");

An exception is thrown while finding:

System.InvalidOperationException: Unable to convert from type Microsoft.Maui.Controls.DatePicker to type Microsoft.Maui.Controls.BindableObject when getting the native control
   at MauiReactor.VisualNode`1.MauiReactor.IVisualNodeWithNativeControl.GetNativeControl[TResult]()
   at MauiReactor.VisualNode.MauiReactor.Internals.IAutomationItemContainer.Descendants[T]()+MoveNext()
   at MauiReactor.VisualNode.MauiReactor.Internals.IAutomationItemContainer.Descendants[T]()+MoveNext()
   at MauiReactor.VisualNode.MauiReactor.Internals.IAutomationItemContainer.Descendants[T]()+MoveNext()
   at MauiReactor.VisualNode.MauiReactor.Internals.IAutomationItemContainer.Descendants[T]()+MoveNext()
   at MauiReactor.VisualNode.MauiReactor.Internals.IAutomationItemContainer.Descendants[T]()+MoveNext()
   at MauiReactor.VisualNode.MauiReactor.Internals.IAutomationItemContainer.Descendants[T]()+MoveNext()
   at MauiReactor.VisualNode.MauiReactor.Internals.IAutomationItemContainer.Descendants[T]()+MoveNext()
   at MauiReactor.Internals.AutomationItemContainerExtensions.FindOptional[T](IAutomationItemContainer automationItemContainer, String automationId)
   at MauiReactor.TemplateHostExtensions.FindOptional[T](ITemplateHost templateHost, String automationId)
   at MauiReactor.TemplateHostExtensions.FindOptional[T](ITemplateHost templateHost, String automationId, TimeSpan timeout, CancellationToken cancellationToken)
   at Mobile.Tests.ShellMuscleGroupsPageIntegrationTests.ShouldInitialize() in X:\src\Maui2\Mobile.Tests\ShellMuscleGroupsPageIntegrationTests.cs:line 45
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass46_0.<<InvokeTestMethodAsync>b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 253
--- End of stack trace from previous location ---
   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90

Even though it says DatePicker above, the control type is different every time.

Expected behavior no exception

adospace commented 7 months ago

I believe that a disconnected visual tree causes the problem: in other words, it visits a node that has been unmounted thus the native control has been migrated to another node or disposed of. I'm working on a fix.

adospace commented 7 months ago

Can you check out version 2.0.31?

powerdude commented 7 months ago

I'm not getting the random errors anymore.