Skip to content
Nuvyntra Labs

Documentation

Testing

FakeNavigator, LeakProbe, AppearAsync, and net10.0 tests without a Uno Platform visual tree.

Testing

Plugin.Uno.MVVMExpress.Testing is net10.0. ViewModels in the template live in a shared net10.0 project so they can be tested without Uno Platform. FakeNavigator is InMemoryNavigator — assert Current, Stack, and CanGoBack. LeakProbe.Track returns a WeakReference; IsCollected takes that reference. Drop the strong reference before the assert. AppearAsync / DisappearAsync drive lifecycle without a page. ScopedNavigator covers page-scope push/pop GC.

[Fact]
public async Task OpenDetails_pushes_details()
{
    var navigator = new FakeNavigator()
        .Map<ProductDetailsViewModel>("details");
    var vm = new ProductListViewModel(navigator);

    await vm.AppearAsync();
    await vm.OpenDetailsAsync(42);

    Assert.Equal(typeof(ProductDetailsViewModel), navigator.Current);
    Assert.True(navigator.CanGoBack);
}

[Fact]
public void Dispose_makes_the_viewmodel_collectable()
{
    Assert.True(LeakProbe.IsCollected(CreateAndDispose()));
}

static WeakReference CreateAndDispose()
{
    var vm = new HomeViewModel();
    var leak = LeakProbe.Track(vm);
    vm.Dispose();
    return leak;
}

Discussion

Comment on Plugin.Uno.MVVMExpress. The thread lives on this component's GitHub repository (nuvyntralabs/Plugin.Uno.MVVMExpress). Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.