-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
234 additions
and
54 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
119 changes: 119 additions & 0 deletions
119
Xamarin.BetterNavigation.UnitTests/Navigation/NavigationParameters.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,119 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Autofac; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
using Xamarin.BetterNavigation.Core; | ||
using Xamarin.BetterNavigation.Forms; | ||
using Xamarin.BetterNavigation.UnitTests.Common; | ||
using Xamarin.BetterNavigation.UnitTests.Common.Pages; | ||
using Xamarin.BetterNavigation.UnitTests.Fakes.FakeXamarinForms; | ||
using Xamarin.Forms; | ||
|
||
namespace Xamarin.BetterNavigation.UnitTests.Navigation | ||
{ | ||
[TestFixture] | ||
public class NavigationParameters | ||
{ | ||
public IServiceLocator ServiceLocator { get; private set; } | ||
|
||
// create dummy item to ensure that Assembly is added | ||
private NavigationService _dummyInstance = new NavigationService(null, null); | ||
|
||
[OneTimeSetUp] | ||
public void ResourcesFixture() | ||
{ | ||
// Always call this to ensure that XamarinForms is initialized! | ||
FakeXamarinForms.Init(); | ||
} | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
var testedAssembly = AppDomain.CurrentDomain.GetAssemblies() | ||
.Where(assembly => assembly.GetName().Name.Contains("Xamarin.BetterNavigation")); | ||
|
||
InitializeIoC(testedAssembly.ToArray()); | ||
} | ||
|
||
[Test] | ||
public Task NavigationParametersUserAsksParameterWithWrongType() | ||
{ | ||
return ServiceLocator.BeginLifetimeScopeAsync(async serviceLocator => | ||
{ | ||
var service = serviceLocator.Get<INavigationService>(); | ||
await service.GoToAsync(ApplicationPage.LoginPage, true, ("SomeKey", 4)); | ||
try | ||
{ | ||
service.NavigationParameters<string>("SomeKey"); | ||
Assert.Fail(); | ||
} | ||
catch (Exception e) | ||
{ | ||
e.Should().BeOfType<InvalidCastException>() | ||
.Which.Message.Should().Contain($"parameterKey is not a type of {typeof(string)}."); | ||
} | ||
}); | ||
} | ||
|
||
[Test] | ||
public Task NavigationParametersUserAsksParameterWithWrongKey() | ||
{ | ||
return ServiceLocator.BeginLifetimeScopeAsync(async serviceLocator => | ||
{ | ||
var service = serviceLocator.Get<INavigationService>(); | ||
await service.GoToAsync(ApplicationPage.LoginPage, true, ("SomeKey", 4)); | ||
try | ||
{ | ||
service.NavigationParameters<string>("SomeKey2"); | ||
Assert.Fail(); | ||
} | ||
catch (Exception e) | ||
{ | ||
e.Should().BeOfType<KeyNotFoundException>() | ||
.Which.Message.Should().Contain("parameterKey was not found in NavigationParameters"); | ||
} | ||
}); | ||
} | ||
|
||
private void InitializeIoC(params Assembly[] assemblies) | ||
{ | ||
ServiceLocator = new ServiceLocator(builder => | ||
{ | ||
// Register Forms NavigationService | ||
builder.Register(e => new NavigationPage(e.Resolve<MainPage>()).Navigation) | ||
.As<INavigation>() | ||
.InstancePerLifetimeScope(); | ||
// Register self | ||
builder.Register(e => ServiceLocator) | ||
.As<IServiceLocator>() | ||
.SingleInstance(); | ||
// Register all other things | ||
builder.RegisterType<PageLocator>() | ||
.As<IPageLocator>() | ||
.SingleInstance(); | ||
// Register services | ||
builder.RegisterAssemblyTypes(assemblies) | ||
.Where(t => t.Name.EndsWith("Service")) | ||
.AsImplementedInterfaces() | ||
.InstancePerLifetimeScope(); | ||
// Register ViewModels | ||
builder.RegisterAssemblyTypes(assemblies) | ||
.Where(t => t.Name.EndsWith("ViewModel")); | ||
// Register Pages | ||
builder.RegisterAssemblyTypes(assemblies) | ||
.Where(t => t.Name.EndsWith("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
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
Oops, something went wrong.