Skip to content

Commit

Permalink
Rider Refactor
Browse files Browse the repository at this point in the history
A final refactor for all of the changes made
  • Loading branch information
Axemasta committed Apr 3, 2024
1 parent baf08b0 commit 38734a0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 44 deletions.
17 changes: 9 additions & 8 deletions src/Moq.INavigationService/MockNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,44 @@
namespace Moq;

/// <summary>
/// Mock Navigation Service, Capable of mocking the <see cref="PageNavigationService"/> during a unit test.
/// Mock Navigation Service, Capable of mocking the <see cref="PageNavigationService" /> during a unit
/// test.
/// </summary>
public class MockNavigationService : Mock<INavigationService>, INavigationService, IRegistryAware
{
#region INavigationService

/// <inheritdoc/>
/// <inheritdoc />
public Task<INavigationResult> GoBackAsync(INavigationParameters parameters)
{
return Object.GoBackAsync(parameters);
}

/// <inheritdoc/>
/// <inheritdoc />
public Task<INavigationResult> GoBackAsync(string viewName, INavigationParameters parameters)
{
return Object.GoBackAsync(viewName, parameters);
}

/// <inheritdoc/>
/// <inheritdoc />
public Task<INavigationResult> GoBackToAsync(string name, INavigationParameters parameters)
{
return Object.GoBackToAsync(name, parameters);
}

/// <inheritdoc/>
/// <inheritdoc />
public Task<INavigationResult> GoBackToRootAsync(INavigationParameters parameters)
{
return Object.GoBackToRootAsync(parameters);
}

/// <inheritdoc/>
/// <inheritdoc />
public Task<INavigationResult> NavigateAsync(Uri uri, INavigationParameters parameters)
{
return Object.NavigateAsync(uri, parameters);
}

/// <inheritdoc/>
/// <inheritdoc />
public Task<INavigationResult> SelectTabAsync(string name, INavigationParameters parameters)
{
return Object.SelectTabAsync(name, parameters);
Expand All @@ -48,7 +49,7 @@ public Task<INavigationResult> SelectTabAsync(string name, INavigationParameters

#region IRegistryAware

/// <inheritdoc/>
/// <inheritdoc />
public IViewRegistry Registry { get; } = new MockViewRegistry();

#endregion IRegistryAware
Expand Down
21 changes: 14 additions & 7 deletions src/Moq.INavigationService/SetupNavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Moq;

/// <summary>
/// Setup Methods For The Mock <see cref="INavigationService"/>
/// Setup Methods For The Mock <see cref="INavigationService" />
/// </summary>
public static class SetupNavigationExtensions
{
Expand All @@ -26,7 +26,8 @@ public static void SetupAllNavigationReturns(this Mock<INavigationService> navig
}

/// <summary>
/// This setup method will ensure all navigation calls will return a failed <see cref="INavigationResult"/> with the given exception.
/// This setup method will ensure all navigation calls will return a failed
/// <see cref="INavigationResult" /> with the given exception.
/// </summary>
/// <param name="navigationServiceMock">The mock navigation service</param>
/// <param name="exception">The exception that caused the navigation failure</param>
Expand All @@ -45,7 +46,7 @@ public static void SetupAllNavigationFails(this Mock<INavigationService> navigat
}

/// <summary>
/// Setup Navigation For The Given <see cref="Uri"/>
/// Setup Navigation For The Given <see cref="Uri" />
/// </summary>
/// <param name="navigationServiceMock">The mock navigation service</param>
/// <param name="destination">The destination uri</param>
Expand All @@ -56,7 +57,7 @@ public static ISetup<INavigationService, Task<INavigationResult>> SetupNavigatio
}

/// <summary>
/// Setup Navigation For The Given <see cref="Uri"/> &amp; <see cref="INavigationParameters"/>
/// Setup Navigation For The Given <see cref="Uri" /> &amp; <see cref="INavigationParameters" />
/// </summary>
/// <param name="navigationServiceMock">The mock navigation service</param>
/// <param name="destination">The destination uri</param>
Expand All @@ -73,7 +74,10 @@ public static ISetup<INavigationService, Task<INavigationResult>> SetupNavigatio
/// <param name="navigationServiceMock">The mock navigation service</param>
/// <param name="destination">The destination string</param>
/// <returns>Moq Setup</returns>
/// <exception cref="NotSupportedException">This will be thrown if the string is not a valid <see cref="Uri"/></exception>
/// <exception cref="NotSupportedException">
/// This will be thrown if the string is not a valid
/// <see cref="Uri" />
/// </exception>
public static ISetup<INavigationService, Task<INavigationResult>> SetupNavigation(this Mock<INavigationService> navigationServiceMock, string destination)
{
if (!Uri.TryCreate(destination, UriKind.RelativeOrAbsolute, out var destinationUri))
Expand All @@ -85,13 +89,16 @@ public static ISetup<INavigationService, Task<INavigationResult>> SetupNavigatio
}

/// <summary>
/// Setup Navigation For The Given Destination String &amp; <see cref="INavigationParameters"/>
/// Setup Navigation For The Given Destination String &amp; <see cref="INavigationParameters" />
/// </summary>
/// <param name="navigationServiceMock">The mock navigation service</param>
/// <param name="destination">The destination string</param>
/// <param name="navigationParameters">The expected parameters</param>
/// <returns>Moq Setup</returns>
/// <exception cref="NotSupportedException">This will be thrown if the string is not a valid <see cref="Uri"/></exception>
/// <exception cref="NotSupportedException">
/// This will be thrown if the string is not a valid
/// <see cref="Uri" />
/// </exception>
public static ISetup<INavigationService, Task<INavigationResult>> SetupNavigation(this Mock<INavigationService> navigationServiceMock, string destination, INavigationParameters navigationParameters)
{
if (!Uri.TryCreate(destination, UriKind.RelativeOrAbsolute, out var destinationUri))
Expand Down
2 changes: 1 addition & 1 deletion src/Moq.INavigationService/VerifyNavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Moq;

/// <summary>
/// Setup Methods For The Mock <see cref="INavigationService"/>
/// Setup Methods For The Mock <see cref="INavigationService" />
/// </summary>
public static class VerifyNavigationExtensions
{
Expand Down
55 changes: 27 additions & 28 deletions tests/Moq.INavigationService.Tests/EquivalenceHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,66 +26,65 @@ public void AreEquivalent_Should_DetermineCorrectly(object? a, object? b, bool e
{
{
// Both are null, expect true
null,
null,
true
null, null, true
},
{
// Both object are Uri, same value, expect true
new Uri("navigation://NavigationPage/HomePage"),
new Uri("navigation://NavigationPage/HomePage"),
true
new Uri("navigation://NavigationPage/HomePage"), new Uri("navigation://NavigationPage/HomePage"), true
},
{
// One object is Uri, other is null, expect false
new Uri("navigation://NavigationPage/HomePage"),
null,
false
new Uri("navigation://NavigationPage/HomePage"), null, false
},
{
// One object is Uri, other is null, expect false
null,
new Uri("navigation://NavigationPage/HomePage"),
false
null, new Uri("navigation://NavigationPage/HomePage"), false
},
{
// Both object are Uri, different values, expect false
new Uri("navigation://NavigationPage/HomePage"),
new Uri("https://www.github.com"),
false
new Uri("navigation://NavigationPage/HomePage"), new Uri("https://www.github.com"), false
},
{
// Both object are NavigationParameters, same values, expect true
new NavigationParameters()
new NavigationParameters
{
{ "KeyOne", "Hello World" },
{
"KeyOne", "Hello World"
},
},
new NavigationParameters()
new NavigationParameters
{
{ "KeyOne", "Hello World" },
{
"KeyOne", "Hello World"
},
},
true
},
{
// Both object are NavigationParameters, different values, expect false
new NavigationParameters()
new NavigationParameters
{
{ "KeyOne", "Hello World" },
{
"KeyOne", "Hello World"
},
},
new NavigationParameters()
new NavigationParameters
{
{ "ThisIsANumber", 1928 },
{
"ThisIsANumber", 1928
},
},
false
},
{
// One object is INavigationParameters, other is null, expect false
new NavigationParameters()
new NavigationParameters
{
{ "KeyOne", "Hello World" },
{
"KeyOne", "Hello World"
},
},
null,
false
}
null, false
},
};
}

0 comments on commit 38734a0

Please sign in to comment.