-
-
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.
adding tests for AutoRegisterForNavigation - fixes #2088
- Loading branch information
Showing
12 changed files
with
186 additions
and
43 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
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Moq" Version="4.13.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Forms\Prism.Forms\Prism.Forms.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Prism.Core\Prism.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,55 @@ | ||
using System; | ||
using Moq; | ||
using Prism; | ||
using Prism.Behaviors; | ||
using Prism.Common; | ||
using Prism.Ioc; | ||
using Prism.Logging; | ||
using Prism.Modularity; | ||
using Prism.Navigation; | ||
|
||
namespace MockApp | ||
{ | ||
[AutoRegisterForNavigation] | ||
public class MockPrismApp : PrismApplicationBase, IApplicationProvider | ||
{ | ||
public Mock<IContainerExtension> MockContainer { get; private set; } | ||
|
||
public static Func<Type, string> PageNameDelegate { get; set; } | ||
|
||
protected override void Initialize() | ||
{ | ||
ContainerLocator.ResetContainer(); | ||
MockContainer = new Mock<IContainerExtension>(); | ||
MockContainer.Setup(x => x.Resolve(typeof(IModuleCatalog))) | ||
.Returns(new ModuleCatalog()); | ||
MockContainer.Setup(x => x.Resolve(typeof(INavigationService), NavigationServiceName)) | ||
.Returns(new PageNavigationService(MockContainer.Object, this, new PageBehaviorFactory(), new EmptyLogger())); | ||
base.Initialize(); | ||
} | ||
|
||
protected override IContainerExtension CreateContainerExtension() | ||
{ | ||
return MockContainer.Object; | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
// Clean up the Delegate for the next test. | ||
PageNameDelegate = null; | ||
} | ||
|
||
protected override void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
|
||
} | ||
|
||
protected override string GetNavigationSegmentNameFromType(Type pageType) | ||
{ | ||
if(PageNameDelegate is null) | ||
return base.GetNavigationSegmentNameFromType(pageType); | ||
|
||
return PageNameDelegate(pageType); | ||
} | ||
} | ||
} |
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,8 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace MockApp.Views | ||
{ | ||
public abstract class AbstractPage : ContentPage | ||
{ | ||
} | ||
} |
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,8 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace MockApp.Views | ||
{ | ||
public class AnotherPage : ContentPage | ||
{ | ||
} | ||
} |
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,8 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace MockApp.Views | ||
{ | ||
public class FooBarPage : ContentPage | ||
{ | ||
} | ||
} |
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,8 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace MockApp.Views | ||
{ | ||
public class SomePage : ContentPage | ||
{ | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/Forms/Prism.Forms.Tests/Ioc/AutoRegisterForNavigationFixture.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,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Humanizer; | ||
using MockApp; | ||
using MockApp.Views; | ||
using Moq; | ||
using Xamarin.Forms; | ||
using Xunit; | ||
|
||
namespace Prism.Forms.Tests.Ioc | ||
{ | ||
public class AutoRegisterForNavigationFixture | ||
{ | ||
public AutoRegisterForNavigationFixture() | ||
{ | ||
Xamarin.Forms.Mocks.MockForms.Init(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(typeof(SomePage))] | ||
[InlineData(typeof(AnotherPage))] | ||
[InlineData(typeof(FooBarPage))] | ||
[InlineData(typeof(NavigationPage))] | ||
[InlineData(typeof(TabbedPage))] | ||
public void RegistersExpectedPagesWithTypeName(Type pageName) | ||
{ | ||
var app = new MockPrismApp(); | ||
app.MockContainer.Verify(x => x.Register(typeof(object), pageName, pageName.Name)); | ||
} | ||
|
||
[Fact] | ||
public void DoesNotAutoRegisterAbstractPage() | ||
{ | ||
var app = new MockPrismApp(); | ||
|
||
app.MockContainer.Verify(x => x.Register(typeof(object), typeof(AbstractPage), nameof(AbstractPage)), Times.Never); | ||
} | ||
|
||
[Theory] | ||
[InlineData(typeof(SomePage), "somePage")] | ||
[InlineData(typeof(AnotherPage), "anotherPage")] | ||
[InlineData(typeof(FooBarPage), "fooBarPage")] | ||
[InlineData(typeof(NavigationPage), "navigationPage")] | ||
[InlineData(typeof(TabbedPage), "tabbedPage")] | ||
public void RegistersExpectedPagesWithCustomNames(Type pageName, string expectedName) | ||
{ | ||
MockPrismApp.PageNameDelegate = t => t.Name.Camelize(); | ||
var app = new MockPrismApp(); | ||
app.MockContainer.Verify(x => x.Register(typeof(object), pageName, expectedName)); | ||
} | ||
} | ||
} |
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