Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Builder Relative / Absolute Navigation Api's #5

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Moq.INavigationService/NavigationExpressionArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@

var useModal = useModalArgument.GetExpressionValue<bool>();

builder.AddSegment(segmentType.Name, useModal);

Check warning on line 145 in src/Moq.INavigationService/NavigationExpressionArgs.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
}
else
{
builder.AddSegment(segmentType.Name);

Check warning on line 149 in src/Moq.INavigationService/NavigationExpressionArgs.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
}

break;
Expand All @@ -156,7 +156,7 @@
{
var argument = call.Arguments.FirstOrDefault();

var parameters = argument.GetExpressionValue<INavigationParameters>();

Check warning on line 159 in src/Moq.INavigationService/NavigationExpressionArgs.cs

View workflow job for this annotation

GitHub Actions / test

Possible null reference argument for parameter 'expression' in 'INavigationParameters? ExpressionExtension.GetExpressionValue<INavigationParameters>(Expression expression)'.

if (parameters is null)
{
Expand Down Expand Up @@ -201,6 +201,18 @@
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
}
Loading