-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2354 from PrismLibrary/di-navservice-fix
Fixing DI NavigationService resolution
- Loading branch information
Showing
15 changed files
with
335 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
tests/Forms/Prism.DI.Forms.Tests/Fixtures/Navigation/NavigationServiceFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
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<XamlViewMockA>(mainPage); | ||
Assert.NotNull(vm); | ||
|
||
var page = ((IPageAware)vm.NavigationService).Page; | ||
Assert.IsType<XamlViewMockA>(mainPage); | ||
Assert.Same(mainPage, page); | ||
} | ||
|
||
[Fact] | ||
public void ContentPage_InNavigationPage_GetsCorrectNavService() | ||
{ | ||
var app = CreateMockApplication(); | ||
app.NavigationService.NavigateAsync("NavigationPage/XamlViewMockA"); | ||
|
||
var mainPage = app.MainPage; | ||
Assert.IsType<NavigationPage>(mainPage); | ||
|
||
var view = mainPage.Navigation.NavigationStack[0] as XamlViewMockA; | ||
Assert.NotNull(view); | ||
|
||
var vm = view.BindingContext as XamlViewMockAViewModel; | ||
Assert.NotNull(vm); | ||
|
||
var page = ((IPageAware)vm.NavigationService).Page; | ||
Assert.IsType<XamlViewMockA>(page); | ||
Assert.Same(view, page); | ||
} | ||
|
||
[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 page = ((IPageAware)tpVm.NavigationService).Page; | ||
Assert.IsType<XamlTabbedViewMock>(page); | ||
Assert.Same(tp, page); | ||
} | ||
|
||
[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 page = ((IPageAware)vm.NavigationService).Page; | ||
Assert.IsType<XamlViewMockA>(page); | ||
Assert.Same(view, page); | ||
} | ||
|
||
[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 page = ((IPageAware)vm.NavigationService).Page; | ||
Assert.IsType<XamlViewMockA>(page); | ||
Assert.Same(view, page); | ||
} | ||
|
||
[Fact] | ||
public void TabbedPage_InNavigationPage_GetsCorrectNavService() | ||
{ | ||
var app = CreateMockApplication(); | ||
app.NavigationService.NavigateAsync("NavigationPage/XamlTabbedViewMock"); | ||
|
||
var mainPage = app.MainPage; | ||
Assert.IsType<NavigationPage>(mainPage); | ||
|
||
var tp = mainPage.Navigation.NavigationStack[0] as TabbedPage; | ||
Assert.NotNull(tp); | ||
|
||
var tpVm = tp.BindingContext as XamlTabbedViewMockViewModel; | ||
Assert.NotNull(tpVm); | ||
|
||
var page = ((IPageAware)tpVm.NavigationService).Page; | ||
Assert.IsType<XamlTabbedViewMock>(page); | ||
Assert.Same(tp, page); | ||
} | ||
|
||
[Fact] | ||
public void MasterDetail_GetsCorrectNavService() | ||
{ | ||
var app = CreateMockApplication(); | ||
app.NavigationService.NavigateAsync("XamlMasterDetailViewMock"); | ||
|
||
var mainPage = app.MainPage; | ||
Assert.IsType<XamlMasterDetailViewMock>(mainPage); | ||
|
||
var vm = mainPage.BindingContext as XamlMasterDetailViewMockViewModel; | ||
Assert.NotNull(vm); | ||
|
||
var page = ((IPageAware)vm.NavigationService).Page; | ||
Assert.IsType<XamlMasterDetailViewMock>(page); | ||
Assert.Same(mainPage, page); | ||
} | ||
|
||
[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 page = ((IPageAware)vm.NavigationService).Page; | ||
Assert.IsType<XamlViewMockA>(page); | ||
Assert.Same(view, page); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlMasterDetailViewMockViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/Forms/Prism.DI.Forms.Tests/Mocks/ViewModels/XamlTabbedViewMockViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:prism="http://prismlibrary.com" | ||
xmlns:local="clr-namespace:Prism.DI.Forms.Tests.Mocks.Views" | ||
prism:ViewModelLocator.AutowireViewModel="True" | ||
x:Class="Prism.DI.Forms.Tests.Mocks.Views.XamlMasterDetailViewMock"> | ||
|
||
<MasterDetailPage.Master> | ||
<ContentPage Title="Master"> | ||
|
||
</ContentPage> | ||
</MasterDetailPage.Master> | ||
|
||
<MasterDetailPage.Detail> | ||
<NavigationPage> | ||
<x:Arguments> | ||
<local:XamlViewMockA Title="View A" /> | ||
</x:Arguments> | ||
</NavigationPage> | ||
</MasterDetailPage.Detail> | ||
|
||
</MasterDetailPage> |
12 changes: 12 additions & 0 deletions
12
tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlMasterDetailViewMock.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace Prism.DI.Forms.Tests.Mocks.Views | ||
{ | ||
public partial class XamlMasterDetailViewMock : MasterDetailPage | ||
{ | ||
public XamlMasterDetailViewMock() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:prism="http://prismlibrary.com" | ||
xmlns:local="clr-namespace:Prism.DI.Forms.Tests.Mocks.Views" | ||
prism:ViewModelLocator.AutowireViewModel="True" | ||
x:Class="Prism.DI.Forms.Tests.Mocks.Views.XamlTabbedViewMock"> | ||
|
||
<NavigationPage Title="View A"> | ||
<x:Arguments> | ||
<local:XamlViewMockA Title="View A" /> | ||
</x:Arguments> | ||
</NavigationPage> | ||
|
||
<local:XamlViewMockA Title="View B" /> | ||
|
||
</TabbedPage> |
12 changes: 12 additions & 0 deletions
12
tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlTabbedViewMock.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace Prism.DI.Forms.Tests.Mocks.Views | ||
{ | ||
public partial class XamlTabbedViewMock : TabbedPage | ||
{ | ||
public XamlTabbedViewMock() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
tests/Forms/Prism.DI.Forms.Tests/Mocks/Views/XamlViewMockA.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<ContentPage | ||
<ContentPage x:Class="Prism.DI.Forms.Tests.Mocks.Views.XamlViewMockA" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:xaml="clr-namespace:Prism.Navigation.Xaml;assembly=Prism.Forms" | ||
Title="{Binding Title}" | ||
x:Class="Prism.DI.Forms.Tests.Mocks.Views.XamlViewMockA"> | ||
xmlns:prism="http://prismlibrary.com" | ||
prism:ViewModelLocator.AutowireViewModel="True" | ||
Title="{Binding Title}" > | ||
<Button x:Name="testButton" Command="{xaml:NavigateTo 'XamlViewMockB'}"> | ||
<Button.CommandParameter> | ||
<xaml:NavigationParameters> | ||
<xaml:NavigationParameter Key="Foo" Value="Bar"/> | ||
</xaml:NavigationParameters> | ||
</Button.CommandParameter> | ||
</Button> | ||
</ContentPage> | ||
</ContentPage> |
Oops, something went wrong.