From 095f8989f91240979a931151e69b40f988d01f22 Mon Sep 17 00:00:00 2001 From: Brian Lagunas Date: Wed, 24 Feb 2021 15:45:36 -0700 Subject: [PATCH 1/4] writing tests to verify di scoping issue --- .../HelloWorld.Android.csproj | 5 + e2e/Forms/src/HelloWorld/App.xaml.cs | 2 +- .../src/ModuleA/ViewModels/ViewAViewModel.cs | 3 +- .../Navigation/NavigationServiceFixture.cs | 112 ++++++++++++++++++ .../Mocks/PrismApplicationMock.cs | 1 + .../ViewModels/XamlTabbedViewMockViewModel.cs | 15 +++ .../ViewModels/XamlViewMockAViewModel.cs | 7 ++ .../Mocks/Views/XamlTabbedViewMock.xaml | 17 +++ .../Mocks/Views/XamlTabbedViewMock.xaml.cs | 12 ++ .../Prism.DI.Forms.Tests.projitems | 12 ++ 10 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs create mode 100644 tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlTabbedViewMockViewModel.cs create mode 100644 tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml create mode 100644 tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml.cs diff --git a/e2e/Forms/src/HelloWorld.Android/HelloWorld.Android.csproj b/e2e/Forms/src/HelloWorld.Android/HelloWorld.Android.csproj index 3eaa3e3ae6..7552a0cbd4 100644 --- a/e2e/Forms/src/HelloWorld.Android/HelloWorld.Android.csproj +++ b/e2e/Forms/src/HelloWorld.Android/HelloWorld.Android.csproj @@ -105,4 +105,9 @@ + + + + + \ No newline at end of file diff --git a/e2e/Forms/src/HelloWorld/App.xaml.cs b/e2e/Forms/src/HelloWorld/App.xaml.cs index 11a98cafde..ebf74b5013 100644 --- a/e2e/Forms/src/HelloWorld/App.xaml.cs +++ b/e2e/Forms/src/HelloWorld/App.xaml.cs @@ -62,7 +62,7 @@ protected override void OnInitialized() { InitializeComponent(); - NavigationService.NavigateAsync($"MyMasterDetail/MyTabbedPage").OnNavigationError(OnNavigationError); + NavigationService.NavigateAsync($"MyTabbedPage").OnNavigationError(OnNavigationError); } private void OnNavigationError(Exception ex) diff --git a/e2e/Forms/src/ModuleA/ViewModels/ViewAViewModel.cs b/e2e/Forms/src/ModuleA/ViewModels/ViewAViewModel.cs index 814f80f9ca..2544c703c9 100644 --- a/e2e/Forms/src/ModuleA/ViewModels/ViewAViewModel.cs +++ b/e2e/Forms/src/ModuleA/ViewModels/ViewAViewModel.cs @@ -79,7 +79,8 @@ private void Save() async void Navigate() { CanNavigate = false; - await _navigationService.SelectTabAsync("ViewC"); + //await _navigationService.SelectTabAsync("ViewC"); + await _navigationService.NavigateAsync("ViewC"); CanNavigate = true; } diff --git a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs new file mode 100644 index 0000000000..6f74ad5f00 --- /dev/null +++ b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs @@ -0,0 +1,112 @@ +using Prism.Common; +using Prism.DI.Forms.Tests.Mocks.ViewModels; +using Prism.DI.Forms.Tests.Mocks.Views; +using Xamarin.Forms; +using Xunit; +using Xunit.Abstractions; + +namespace Prism.DI.Forms.Tests.Fixtures.Navigation +{ + public class NavigationServiceFixture : FixtureBase + { + public NavigationServiceFixture(ITestOutputHelper testOutputHelper) + : base(testOutputHelper) + { + } + + [Fact] + public void ContentPage_GetsCorrectNavService() + { + var app = CreateMockApplication(); + app.NavigationService.NavigateAsync("XamlViewMockA"); + + var mainPage = app.MainPage; + var vm = mainPage.BindingContext as XamlViewMockAViewModel; + + Assert.IsType(mainPage); + Assert.NotNull(vm); + + var correctPage = ((IPageAware)vm.NavigationService).Page == mainPage; + Assert.True(correctPage); + } + + [Fact] + public void ContentPage_InNavigationPage_GetsCorrectNavService() + { + var app = CreateMockApplication(); + app.NavigationService.NavigateAsync("NavigationPage/XamlViewMockA"); + + var mainPage = app.MainPage; + Assert.IsType(mainPage); + + var view = mainPage.Navigation.NavigationStack[0] as XamlViewMockA; + Assert.NotNull(view); + + var vm = view.BindingContext as XamlViewMockAViewModel; + Assert.NotNull(vm); + + var correctPage = ((IPageAware)vm.NavigationService).Page == view; + Assert.True(correctPage); + } + + [Fact] + public void TabbedPage_GetsCorrectNavService() + { + var app = CreateMockApplication(); + app.NavigationService.NavigateAsync("XamlTabbedViewMock"); + + var tp = app.MainPage as TabbedPage; + Assert.NotNull(tp); + + var tpVm = tp.BindingContext as XamlTabbedViewMockViewModel; + Assert.NotNull(tpVm); + + var correctNavService = ((IPageAware)tpVm.NavigationService).Page == tp; + Assert.True(correctNavService); + } + + [Fact] + public void TabbedPage_ContentPage_NestedNavigationPage_GetsCorrectNavService() + { + var app = CreateMockApplication(); + app.NavigationService.NavigateAsync("XamlTabbedViewMock"); + + var tp = app.MainPage as TabbedPage; + Assert.NotNull(tp); + + var tab = tp.Children[0]; + Assert.NotNull(tab); + + var navPage = tab as NavigationPage; + Assert.NotNull(navPage); + + var view = navPage.CurrentPage; + Assert.NotNull(view); + + var vm = view.BindingContext as XamlViewMockAViewModel; + Assert.NotNull(vm); + + var correctPageNavService = ((IPageAware)vm.NavigationService).Page == view; + Assert.True(correctPageNavService); + } + + [Fact] + public void TabbedPage_ContentPage_GetsCorrectNavService() + { + var app = CreateMockApplication(); + app.NavigationService.NavigateAsync("XamlTabbedViewMock"); + + var tp = app.MainPage as TabbedPage; + Assert.NotNull(tp); + + var view = tp.Children[1]; + Assert.NotNull(view); + + var vm = view.BindingContext as XamlViewMockAViewModel; + Assert.NotNull(vm); + + var correctPageNavService = ((IPageAware)vm.NavigationService).Page == view; + Assert.True(correctPageNavService); + } + } +} diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/PrismApplicationMock.cs b/tests/Forms/Prism.DI.Forms.Tests/Mocks/PrismApplicationMock.cs index 9184de38c9..02f35e76fe 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Mocks/PrismApplicationMock.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/PrismApplicationMock.cs @@ -57,6 +57,7 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry) containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); ViewModelLocationProvider.Register(); } diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlTabbedViewMockViewModel.cs b/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlTabbedViewMockViewModel.cs new file mode 100644 index 0000000000..adf80b907a --- /dev/null +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlTabbedViewMockViewModel.cs @@ -0,0 +1,15 @@ +using Prism.Mvvm; +using Prism.Navigation; + +namespace Prism.DI.Forms.Tests.Mocks.ViewModels +{ + public class XamlTabbedViewMockViewModel : BindableBase + { + public INavigationService NavigationService { get; } + + public XamlTabbedViewMockViewModel(INavigationService navigationService) + { + NavigationService = navigationService; + } + } +} diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlViewMockAViewModel.cs b/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlViewMockAViewModel.cs index 49b02822b3..a95682e860 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlViewMockAViewModel.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlViewMockAViewModel.cs @@ -20,6 +20,13 @@ public string Test set => SetProperty(ref _test, value); } + public INavigationService NavigationService { get; set; } + + public XamlViewMockAViewModel(INavigationService navigationService) + { + NavigationService = navigationService; + } + public void OnNavigatedFrom(INavigationParameters parameters) { } diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml new file mode 100644 index 0000000000..8e31e95530 --- /dev/null +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml.cs b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml.cs new file mode 100644 index 0000000000..7ae46327c3 --- /dev/null +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml.cs @@ -0,0 +1,12 @@ +using Xamarin.Forms; + +namespace Prism.DI.Forms.Tests.Mocks.Views +{ + public partial class XamlTabbedViewMock : TabbedPage + { + public XamlTabbedViewMock() + { + InitializeComponent(); + } + } +} diff --git a/tests/Forms/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems b/tests/Forms/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems index 946780be28..50bdf49bef 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems +++ b/tests/Forms/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems @@ -12,6 +12,7 @@ + @@ -33,6 +34,7 @@ + @@ -46,6 +48,10 @@ + + XamlTabbedViewMock.xaml + Code + XamlViewMock.xaml @@ -75,4 +81,10 @@ MSBuild:UpdateDesignTimeXaml + + + Designer + MSBuild:UpdateDesignTimeXaml + + \ No newline at end of file From e90a6f7d0641275d1be51f341433f19287b6762a Mon Sep 17 00:00:00 2001 From: Brian Lagunas Date: Wed, 24 Feb 2021 15:56:35 -0700 Subject: [PATCH 2/4] added tabbed page test --- .../Navigation/NavigationServiceFixture.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs index 6f74ad5f00..cf5879d1d3 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs @@ -108,5 +108,24 @@ public void TabbedPage_ContentPage_GetsCorrectNavService() var correctPageNavService = ((IPageAware)vm.NavigationService).Page == view; Assert.True(correctPageNavService); } + + [Fact] + public void TabbedPage_InNavigationPage_GetsCorrectNavService() + { + var app = CreateMockApplication(); + app.NavigationService.NavigateAsync("NavigationPage/XamlTabbedViewMock"); + + var mainPage = app.MainPage; + Assert.IsType(mainPage); + + var tp = mainPage.Navigation.NavigationStack[0] as TabbedPage; + Assert.NotNull(tp); + + var tpVm = tp.BindingContext as XamlTabbedViewMockViewModel; + Assert.NotNull(tpVm); + + var correctNavService = ((IPageAware)tpVm.NavigationService).Page == tp; + Assert.True(correctNavService); + } } } From 55e3923d59900b75bfaa7b3f60229c0b6bc573ef Mon Sep 17 00:00:00 2001 From: Brian Lagunas Date: Wed, 24 Feb 2021 16:24:00 -0700 Subject: [PATCH 3/4] added master detail tests --- .../Navigation/NavigationServiceFixture.cs | 38 +++++++++++++++++++ .../Mocks/PrismApplicationMock.cs | 1 + .../XamlMasterDetailViewMockViewModel.cs | 14 +++++++ .../Mocks/Views/XamlMasterDetailViewMock.xaml | 23 +++++++++++ .../Views/XamlMasterDetailViewMock.xaml.cs | 12 ++++++ .../Mocks/Views/XamlViewMockA.xaml | 9 +++-- .../Prism.DI.Forms.Tests.projitems | 11 ++++++ 7 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlMasterDetailViewMockViewModel.cs create mode 100644 tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml create mode 100644 tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml.cs diff --git a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs index cf5879d1d3..1e1bbf55bf 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs @@ -127,5 +127,43 @@ public void TabbedPage_InNavigationPage_GetsCorrectNavService() var correctNavService = ((IPageAware)tpVm.NavigationService).Page == tp; Assert.True(correctNavService); } + + [Fact] + public void MasterDetail_GetsCorrectNavService() + { + var app = CreateMockApplication(); + app.NavigationService.NavigateAsync("XamlMasterDetailViewMock"); + + var mainPage = app.MainPage; + Assert.IsType(mainPage); + + var vm = mainPage.BindingContext as XamlMasterDetailViewMockViewModel; + Assert.NotNull(vm); + + var correctNavService = ((IPageAware)vm.NavigationService).Page == mainPage; + Assert.True(correctNavService); + } + + [Fact] + public void MasterDetail_Detail_GetsCorrectNavService() + { + var app = CreateMockApplication(); + app.NavigationService.NavigateAsync("XamlMasterDetailViewMock"); + + var mainPage = app.MainPage as XamlMasterDetailViewMock; + Assert.NotNull(mainPage); + + var detail = mainPage.Detail as NavigationPage; + Assert.NotNull(detail); + + var view = detail.CurrentPage as XamlViewMockA; + Assert.NotNull(view); + + var vm = view.BindingContext as XamlViewMockAViewModel; + Assert.NotNull(vm); + + var correctNavService = ((IPageAware)vm.NavigationService).Page == view; + Assert.True(correctNavService); + } } } diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/PrismApplicationMock.cs b/tests/Forms/Prism.DI.Forms.Tests/Mocks/PrismApplicationMock.cs index 02f35e76fe..98bd4bc40c 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Mocks/PrismApplicationMock.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/PrismApplicationMock.cs @@ -58,6 +58,7 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry) containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); ViewModelLocationProvider.Register(); } diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlMasterDetailViewMockViewModel.cs b/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlMasterDetailViewMockViewModel.cs new file mode 100644 index 0000000000..a51190af0a --- /dev/null +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlMasterDetailViewMockViewModel.cs @@ -0,0 +1,14 @@ +using Prism.Navigation; + +namespace Prism.DI.Forms.Tests.Mocks.ViewModels +{ + public class XamlMasterDetailViewMockViewModel + { + public INavigationService NavigationService { get; } + + public XamlMasterDetailViewMockViewModel(INavigationService navigationService) + { + NavigationService = navigationService; + } + } +} diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml new file mode 100644 index 0000000000..d41fe52be5 --- /dev/null +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml.cs b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml.cs new file mode 100644 index 0000000000..8e6d766413 --- /dev/null +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml.cs @@ -0,0 +1,12 @@ +using Xamarin.Forms; + +namespace Prism.DI.Forms.Tests.Mocks.Views +{ + public partial class XamlMasterDetailViewMock : MasterDetailPage + { + public XamlMasterDetailViewMock() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlViewMockA.xaml b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlViewMockA.xaml index fc16680945..193e03efdf 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlViewMockA.xaml +++ b/tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlViewMockA.xaml @@ -1,10 +1,11 @@ - + xmlns:prism="http://prismlibrary.com" + prism:ViewModelLocator.AutowireViewModel="True" + Title="{Binding Title}" > - \ No newline at end of file + diff --git a/tests/Forms/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems b/tests/Forms/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems index 50bdf49bef..f4bd042e30 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems +++ b/tests/Forms/Prism.DI.Forms.Tests/Prism.DI.Forms.Tests.projitems @@ -34,6 +34,7 @@ + @@ -48,6 +49,10 @@ + + XamlMasterDetailViewMock.xaml + Code + XamlTabbedViewMock.xaml Code @@ -87,4 +92,10 @@ MSBuild:UpdateDesignTimeXaml + + + Designer + MSBuild:UpdateDesignTimeXaml + + \ No newline at end of file From b9e600c603d1b4e1bfcdb5e97ccc6e8b367d7591 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Thu, 25 Feb 2021 08:45:04 -0800 Subject: [PATCH 4/4] fixing NavigationService Scoping --- .../Prism.Forms/Navigation/Xaml/Navigation.cs | 29 +++++++++----- .../Navigation/NavigationServiceFixture.cs | 40 +++++++++++-------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/Forms/Prism.Forms/Navigation/Xaml/Navigation.cs b/src/Forms/Prism.Forms/Navigation/Xaml/Navigation.cs index 3c7b224d2a..3a4e5de348 100644 --- a/src/Forms/Prism.Forms/Navigation/Xaml/Navigation.cs +++ b/src/Forms/Prism.Forms/Navigation/Xaml/Navigation.cs @@ -95,15 +95,7 @@ public static INavigationService GetNavigationService(Page page) if (!currentScope.IsAttached) page.SetValue(NavigationScopeProperty, currentScope); - currentScope.IsAttached = true; - - navService = currentScope.Resolve(); - if (navService is IPageAware pa) - { - pa.Page = page; - } - - page.SetValue(NavigationServiceProperty, navService); + navService = CreateNavigationService(currentScope, page); } else if(navService is IPageAware pa && pa.Page != page) { @@ -116,6 +108,25 @@ public static INavigationService GetNavigationService(Page page) return navService; } + private static INavigationService CreateNavigationService(IScopedProvider scope, Page page) + { + var navService = scope.Resolve(); + switch(navService) + { + case IPageAware pa when pa.Page is null: + pa.Page = page; + break; + case IPageAware pa1 when pa1.Page != page: + return CreateNavigationService(ContainerLocator.Container.CreateScope(), page); + } + + page.SetValue(NavigationScopeProperty, scope); + scope.IsAttached = true; + page.SetValue(NavigationServiceProperty, navService); + + return navService; + } + internal static Action GetRaiseCanExecuteChangedInternal(BindableObject view) => (Action)view.GetValue(RaiseCanExecuteChangedInternalProperty); internal static void SetRaiseCanExecuteChangedInternal(BindableObject view, Action value) => view.SetValue(RaiseCanExecuteChangedInternalProperty, value); diff --git a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs index 1e1bbf55bf..4def2f4172 100644 --- a/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs +++ b/tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs @@ -26,8 +26,9 @@ public void ContentPage_GetsCorrectNavService() Assert.IsType(mainPage); Assert.NotNull(vm); - var correctPage = ((IPageAware)vm.NavigationService).Page == mainPage; - Assert.True(correctPage); + var page = ((IPageAware)vm.NavigationService).Page; + Assert.IsType(mainPage); + Assert.Same(mainPage, page); } [Fact] @@ -45,8 +46,9 @@ public void ContentPage_InNavigationPage_GetsCorrectNavService() var vm = view.BindingContext as XamlViewMockAViewModel; Assert.NotNull(vm); - var correctPage = ((IPageAware)vm.NavigationService).Page == view; - Assert.True(correctPage); + var page = ((IPageAware)vm.NavigationService).Page; + Assert.IsType(page); + Assert.Same(view, page); } [Fact] @@ -61,8 +63,9 @@ public void TabbedPage_GetsCorrectNavService() var tpVm = tp.BindingContext as XamlTabbedViewMockViewModel; Assert.NotNull(tpVm); - var correctNavService = ((IPageAware)tpVm.NavigationService).Page == tp; - Assert.True(correctNavService); + var page = ((IPageAware)tpVm.NavigationService).Page; + Assert.IsType(page); + Assert.Same(tp, page); } [Fact] @@ -86,8 +89,9 @@ public void TabbedPage_ContentPage_NestedNavigationPage_GetsCorrectNavService() var vm = view.BindingContext as XamlViewMockAViewModel; Assert.NotNull(vm); - var correctPageNavService = ((IPageAware)vm.NavigationService).Page == view; - Assert.True(correctPageNavService); + var page = ((IPageAware)vm.NavigationService).Page; + Assert.IsType(page); + Assert.Same(view, page); } [Fact] @@ -105,8 +109,9 @@ public void TabbedPage_ContentPage_GetsCorrectNavService() var vm = view.BindingContext as XamlViewMockAViewModel; Assert.NotNull(vm); - var correctPageNavService = ((IPageAware)vm.NavigationService).Page == view; - Assert.True(correctPageNavService); + var page = ((IPageAware)vm.NavigationService).Page; + Assert.IsType(page); + Assert.Same(view, page); } [Fact] @@ -124,8 +129,9 @@ public void TabbedPage_InNavigationPage_GetsCorrectNavService() var tpVm = tp.BindingContext as XamlTabbedViewMockViewModel; Assert.NotNull(tpVm); - var correctNavService = ((IPageAware)tpVm.NavigationService).Page == tp; - Assert.True(correctNavService); + var page = ((IPageAware)tpVm.NavigationService).Page; + Assert.IsType(page); + Assert.Same(tp, page); } [Fact] @@ -140,8 +146,9 @@ public void MasterDetail_GetsCorrectNavService() var vm = mainPage.BindingContext as XamlMasterDetailViewMockViewModel; Assert.NotNull(vm); - var correctNavService = ((IPageAware)vm.NavigationService).Page == mainPage; - Assert.True(correctNavService); + var page = ((IPageAware)vm.NavigationService).Page; + Assert.IsType(page); + Assert.Same(mainPage, page); } [Fact] @@ -162,8 +169,9 @@ public void MasterDetail_Detail_GetsCorrectNavService() var vm = view.BindingContext as XamlViewMockAViewModel; Assert.NotNull(vm); - var correctNavService = ((IPageAware)vm.NavigationService).Page == view; - Assert.True(correctNavService); + var page = ((IPageAware)vm.NavigationService).Page; + Assert.IsType(page); + Assert.Same(view, page); } } }