Skip to content

Commit

Permalink
Merge branch 'hotfix/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kkolodziejczak committed Feb 24, 2019
2 parents 86451fe + b044548 commit 3c40113
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ coverage-hits.txt
OpenCover.xml
[Aa]rtifacts/
[Aa]rtifacts.*

StrykerOutput/

# User-specific files
*.suo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<id>Xamarin.BetterNavigation.Core</id>
<version>@version</version>
<title>Better navigation Plugin for Xamarin Forms</title>
<authors>Krzysztof Kołodziejczak</authors>
<authors>Krzysztof Kolodziejczak</authors>
<licenseUrl>https://github.com/kkolodziejczak/XamarinIoCNavigation/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/kkolodziejczak/XamarinIoCNavigation</projectUrl>
<releaseNotes>https://github.com/kkolodziejczak/XamarinIoCNavigation/releases</releaseNotes>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Core interfaces to use in MVVM library and Xamarin.BetterNavigation.Forms in Xamarin.Forms.</description>
<summary>Xamarin Forms plugin to navigate easily and fluently. Core interfaces to easily incorporate to MVVM library.</summary>
Expand Down
19 changes: 12 additions & 7 deletions Xamarin.BetterNavigation.Forms/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public bool ContainsParameterKey(string parameterKey)
/// <exception cref="ArgumentNullException"><paramref name="parameterKey"/> is null.</exception>
public bool TryGetValue<T>(string parameterKey, out T value)
{
var result = _navigationParameters.TryGetValue(parameterKey, out var commonValue);
var navigationParametersContainsKey = _navigationParameters.TryGetValue(parameterKey, out var commonValue);

if (result == true)
if (navigationParametersContainsKey)
{
if (commonValue is T returnValue)
{
Expand All @@ -96,9 +96,12 @@ public bool TryGetValue<T>(string parameterKey, out T value)
throw new InvalidCastException($"{nameof(parameterKey)} is not a type of {typeof(T)}.");
}
}
else
{
value = default;
}

value = default;
return result;
return navigationParametersContainsKey;
}

/// <summary>
Expand Down Expand Up @@ -259,10 +262,12 @@ private Task RemoveUnwantedPages(byte amount, Action actionBeforeLastPop, bool a

private void CheckIfWeCanPopThatManyPages(byte amount)
{
var lastPageIndex = GetLastPageIndex();
var weWantToPopOnlyFirstPage = amount == 1 && lastPageIndex == 0;
if (amount == 0)
{
throw new ArgumentOutOfRangeException(nameof(amount), "You want to remove 0 pages from the Navigation Stack.");

if (amount > lastPageIndex && !weWantToPopOnlyFirstPage)
}
if (amount > GetLastPageIndex())
{
throw new ArgumentOutOfRangeException(nameof(amount), "You want to remove too many pages from the Navigation Stack.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<id>Xamarin.BetterNavigation.Forms</id>
<version>@version</version>
<title>Better navigation Plugin for Xamarin Forms</title>
<authors>Krzysztof Kołodziejczak</authors>
<authors>Krzysztof Kolodziejczak</authors>
<licenseUrl>https://github.com/kkolodziejczak/XamarinIoCNavigation/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/kkolodziejczak/XamarinIoCNavigation</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
Xamarin.BetterNavigation.Forms contains inmplementation of Navigation service providing better navigation through application.
Xamarin.BetterNavigation.Core contains interfaces that easly allows to inverse dependencies in code and still being able to use navigation without knowing anything about Xamarin.Forms.
Xamarin.BetterNavigation.Forms contains implementation of Navigation service providing better navigation through application.
Xamarin.BetterNavigation.Core contains interfaces that allow to inverse dependencies in the code and still being able to use navigation without knowing anything about Xamarin.Forms.
</description>
<summary>Xamarin Forms plugin to navigate easily and fluently.</summary>
<tags>xamarin, forms, xamarin.forms, quick, easy, navigation</tags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public Task ContainsParameterKeyUnsuccessfulEmptyString()
try
{
service.ContainsParameterKey(null);
Assert.Fail();
}
catch (Exception e)
{
Expand Down
119 changes: 119 additions & 0 deletions Xamarin.BetterNavigation.UnitTests/Navigation/NavigationParameters.cs
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"));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public async Task NavigationService_ActionExecuted_beforePop_PopPageAsync()
var popInvoked = false;
var service = new NavigationService(ServiceLocator.Get<INavigation>(), ServiceLocator.Get<IPageLocator>(),
p => { popInvoked = true; }, null);
await service.GoToAsync(ApplicationPage.LoginPage);

await service.PopPageAsync();

Expand All @@ -140,6 +141,7 @@ public async Task NavigationService_ActionExecuted_beforePop_PopPageAsyncAnimate
var popInvoked = false;
var service = new NavigationService(ServiceLocator.Get<INavigation>(), ServiceLocator.Get<IPageLocator>(),
p => { popInvoked = true; }, null);
await service.GoToAsync(ApplicationPage.LoginPage);

await service.PopPageAsync(true);

Expand All @@ -152,6 +154,7 @@ public async Task NavigationService_ActionExecuted_beforePop_PopPageAsync_WithAm
var popInvoked = false;
var service = new NavigationService(ServiceLocator.Get<INavigation>(), ServiceLocator.Get<IPageLocator>(),
p => { popInvoked = true; }, null);
await service.GoToAsync(ApplicationPage.LoginPage);

await service.PopPageAsync(1);

Expand All @@ -164,6 +167,7 @@ public async Task NavigationService_ActionExecuted_beforePop_PopPageAsync_WithAm
var popInvoked = false;
var service = new NavigationService(ServiceLocator.Get<INavigation>(), ServiceLocator.Get<IPageLocator>(),
p => { popInvoked = true; }, null);
await service.GoToAsync(ApplicationPage.LoginPage);

await service.PopPageAsync(1, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public Task PopPageAndGoToAsyncPopTooManyPages()
try
{
await service.PopPageAndGoToAsync(5, ApplicationPage.LoginPage);
Assert.Fail();
}
catch (Exception e)
{
Expand All @@ -134,6 +135,7 @@ public Task PopPageAndGoToAsyncPopTooManyPagesAnimated()
try
{
await service.PopPageAndGoToAsync(5, ApplicationPage.LoginPage, true);
Assert.Fail();
}
catch (Exception e)
{
Expand Down
49 changes: 41 additions & 8 deletions Xamarin.BetterNavigation.UnitTests/Navigation/PopPageAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ public Task PopPageAsyncSuccessfulOnlyRootPage()
navigation.NavigationStack.Should().HaveCount(1);
await service.PopPageAsync();
navigation.NavigationStack.Should().HaveCount(1);
navigation.NavigationStack.Last().Should().BeOfType(typeof(MainPage));
try
{
await service.PopPageAsync();
Assert.Fail();
}
catch (Exception e)
{
e.Should().BeOfType<ArgumentOutOfRangeException>()
.Which.Message.Should().Contain("You want to remove too many pages from the Navigation Stack.");
}
});
}

Expand All @@ -97,10 +103,16 @@ public Task PopPageAsyncSuccessfulOnlyRootPageAnimated()
navigation.NavigationStack.Should().HaveCount(1);
await service.PopPageAsync(true);
navigation.NavigationStack.Should().HaveCount(1);
navigation.NavigationStack.Last().Should().BeOfType(typeof(MainPage));
try
{
await service.PopPageAsync(true);
Assert.Fail();
}
catch (Exception e)
{
e.Should().BeOfType<ArgumentOutOfRangeException>()
.Which.Message.Should().Contain("You want to remove too many pages from the Navigation Stack.");
}
});
}

Expand Down Expand Up @@ -170,6 +182,7 @@ public Task PopPageAsyncSuccessfulPop2PagesWhenThereAreOnly2PagesOnTheStack()
try
{
await service.PopPageAsync(2);
Assert.Fail();
}
catch (Exception e)
{
Expand All @@ -178,6 +191,26 @@ public Task PopPageAsyncSuccessfulPop2PagesWhenThereAreOnly2PagesOnTheStack()
});
}

[Test]
public Task PopPageAsyncPopping0PagesThrowsException()
{
return ServiceLocator.BeginLifetimeScopeAsync(async serviceLocator =>
{
var service = serviceLocator.Get<INavigationService>();
try
{
await service.PopPageAsync(0);
Assert.Fail();
}
catch (Exception e)
{
e.Should().BeOfType<ArgumentOutOfRangeException>()
.Which.Message.Should().Contain("You want to remove 0 pages from the Navigation Stack.");
}
});
}

private void InitializeIoC(params Assembly[] assemblies)
{
ServiceLocator = new ServiceLocator(builder =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ public Task TryGetValueUnsuccessfulWrongType()
try
{
service.TryGetValue("key", out string s);
Assert.Fail();
}
catch (Exception e)
{
e.Should().BeOfType<InvalidCastException>();
e.Should().BeOfType<InvalidCastException>()
.Which.Message.Should().Contain($"parameterKey is not a type of {typeof(string)}.");
}
});
}
Expand All @@ -79,10 +81,10 @@ public Task TryGetValueUnsuccessfulNullKey()
var service = serviceLocator.Get<INavigationService>();
await service.GoToAsync(ApplicationPage.LoginPage, ("key", 123));
try
{
service.TryGetValue(null, out int s);
Assert.Fail();
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
Expand All @@ -13,7 +13,11 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Xamarin.BetterNavigation.Core\Xamarin.BetterNavigation.Core.csproj" />
<DotNetCliToolReference Include="StrykerMutator.DotNetCoreCli" Version="*" />
<PackageReference Include="StrykerMutator.DotNetCoreCli" Version="*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Xamarin.BetterNavigation.Forms\Xamarin.BetterNavigation.Forms.csproj" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 3c40113

Please sign in to comment.