Skip to content

Commit

Permalink
Merge pull request #5 from Axemasta/use-navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Axemasta authored Sep 8, 2023
2 parents 3aed710 + b2ce7f6 commit 5a3ef22
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Moq.INavigationService/NavigationExpressionArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ private static (Uri Uri, INavigationParameters? NavigationParameters) ParseUriBu
break;
}

case nameof(INavigationBuilder.UseAbsoluteNavigation):
{
builder.UseAbsoluteNavigation();
break;
}

case nameof(INavigationBuilder.UseRelativeNavigation):
{
builder.UseRelativeNavigation();
break;
}

case nameof(INavigationBuilder.AddTabbedSegment):
{
throw new NotSupportedException("This api has not been mapped and is not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ public async Task<INavigationResult> NavigateToNavigationHomePage()
.NavigateAsync();
}

public async Task<INavigationResult> NavigateToHomePageUsingRelativeNavigation()
{
return await navigationService.CreateBuilder()
.UseRelativeNavigation()
.AddSegment<HomePage>()
.NavigateAsync();
}

public async Task<INavigationResult> NavigateToHomePageUsingAbsoluteNavigation()
{
return await navigationService.CreateBuilder()
.UseAbsoluteNavigation()
.AddSegment<HomePage>()
.NavigateAsync();
}

public async Task<INavigationResult> NavigateToModalHomePageViaSegment()
{
return await navigationService.CreateBuilder()
Expand Down
40 changes: 40 additions & 0 deletions tests/Moq.INavigationService.Tests/SetupBuilderViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,45 @@ public async Task NavigateToModalHomePageViaParameter_WhenSetupIsNotMatched_Shou
Assert.Null(result);
}

[Fact]
public async Task NavigateToHomePageUsingRelativeNavigation_WhenSetupIsMatched_ShouldReturnResult()
{
// Arrange
var expectedNavigationResult = new NavigationResult();

navigationService.SetupNavigation(nav => nav.CreateBuilder()
.UseRelativeNavigation()
.AddSegment<HomePage>()
.NavigateAsync())
.ReturnsAsync(expectedNavigationResult);

// Act
var result = await Sut.NavigateToHomePageUsingRelativeNavigation();

// Assert
Assert.Equal(expectedNavigationResult, result);
navigationService.Verify();
}

[Fact]
public async Task NavigateToHomePageUsingAbsoluteNavigation_WhenSetupIsMatched_ShouldReturnResult()
{
// Arrange
var expectedNavigationResult = new NavigationResult();

navigationService.SetupNavigation(nav => nav.CreateBuilder()
.UseAbsoluteNavigation()
.AddSegment<HomePage>()
.NavigateAsync())
.ReturnsAsync(expectedNavigationResult);

// Act
var result = await Sut.NavigateToHomePageUsingAbsoluteNavigation();

// Assert
Assert.Equal(expectedNavigationResult, result);
navigationService.Verify();
}

#endregion Tests
}
34 changes: 34 additions & 0 deletions tests/Moq.INavigationService.Tests/VerifyBuilderViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,5 +303,39 @@ public async Task Verify_WhenVerificationDoesntMatchSetup_ShouldThrow()
Assert.IsType<VerifyNavigationException>(ex);
}

[Fact]
public async Task NavigateToHomePageUsingRelativeNavigation_WhenCalled_ShouldVerify()
{
// Arrange

// Act
await Sut.NavigateToHomePageUsingRelativeNavigation();

// Assert
navigationService.VerifyNavigation(
nav => nav.CreateBuilder()
.UseRelativeNavigation()
.AddSegment<HomePage>()
.NavigateAsync(),
Times.Once());
}

[Fact]
public async Task NavigateToHomePageUsingAbsoluteNavigation_WhenCalled_ShouldVerify()
{
// Arrange

// Act
await Sut.NavigateToHomePageUsingAbsoluteNavigation();

// Assert
navigationService.VerifyNavigation(
nav => nav.CreateBuilder()
.UseAbsoluteNavigation()
.AddSegment<HomePage>()
.NavigateAsync(),
Times.Once());
}

#endregion Tests
}

0 comments on commit 5a3ef22

Please sign in to comment.