public async void StartAutoSubscribing_ShouldGarbageCollectPageAndBindingContext() { var navPage = new AutoNavigationPage(new Page()); navPage.RegisterAction("TestAction2") .Pop(); var subPage = new Page(); var testViewModel = new TestViewModel(); subPage.BindingContext = testViewModel; await navPage.Navigation.PushAsync(subPage); await testViewModel.InvokeRequest("TestAction2"); WeakReference pageReference = new WeakReference(subPage); WeakReference contextReference = new WeakReference(testViewModel); subPage = null; testViewModel = null; //give controle to another thread to clean up the navigation stack properly, //if not the page/context wont be collected await Task.Delay(1); GC.Collect(); Assert.False(contextReference.IsAlive); Assert.False(pageReference.IsAlive); }
public async void RegisterAction_ShouldRegisterAction() { var navigationPage = new AutoNavigationPage(new Page()); string actionName = "actionName"; navigationPage.RegisterAction(actionName); Exception exc = await Record.ExceptionAsync(() => navigationPage.Navigation.ExecuteAction(actionName)); Assert.Null(exc); }
public async void StartAutoSubscribing_ShouldAutoSubscribenewPages() { var navPage = new AutoNavigationPage(new Page()); navPage.RegisterAction("TestAction") .Pop(); var subPage = new Page(); var testViewModel = new TestViewModel(); subPage.BindingContext = testViewModel; await navPage.Navigation.PushAsync(subPage); Assert.Equal(2, navPage.Navigation.NavigationStack.Count); await testViewModel.InvokeRequest("TestAction"); Assert.Equal(1, navPage.Navigation.NavigationStack.Count); }