Skip to content

Commit

Permalink
Merge pull request #9 from Axemasta/feature/prism-stable
Browse files Browse the repository at this point in the history
Upgrade Prism & Add GoBack Support
  • Loading branch information
Axemasta authored Aug 21, 2024
2 parents da829f9 + 454a5ed commit 8e941d7
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 27 deletions.
2 changes: 1 addition & 1 deletion directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup>
<MauiVersion>8.0.14</MauiVersion>
<MauiVersion>8.0.20</MauiVersion>
<StandardTargetFramework>net8.0</StandardTargetFramework>
</PropertyGroup>

Expand Down
8 changes: 8 additions & 0 deletions src/Moq.INavigationService/ExpressionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ internal static class ExpressionExtension
return default;
}
}

public static string GetExpressionMethodName(this Expression expression)
{
var methodCall = (expression as LambdaExpression)?.Body as MethodCallExpression;
var methodName = methodCall?.Method.Name ?? throw new InvalidOperationException("Could not determine calling method name");

return methodName;
}
}
14 changes: 4 additions & 10 deletions src/Moq.INavigationService/MockNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ public Task<INavigationResult> GoBackAsync(INavigationParameters parameters)
}

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

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

/// <inheritdoc />
Expand All @@ -40,9 +34,9 @@ public Task<INavigationResult> NavigateAsync(Uri uri, INavigationParameters para
}

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

#endregion INavigationService
Expand Down
2 changes: 1 addition & 1 deletion src/Moq.INavigationService/Moq.INavigationService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<ItemGroup>
<PackageReference Include="Moq" Version="4.20.70"/>
<PackageReference Include="Prism.Maui" Version="9.0.401-pre"/>
<PackageReference Include="Prism.Maui" Version="9.0.537" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
23 changes: 19 additions & 4 deletions src/Moq.INavigationService/NavigationExpressionArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,26 @@ public static NavigationExpressionArgs FromNavigationBuilderExpression(Expressio
};
}

public static NavigationExpressionArgs FromUriExpression(Expression expression)
public static NavigationExpressionArgs FromNavigateUriExpression(Expression expression)
{
return new NavigationExpressionArgs
{
NavigationUri = GetNavigationUriFrom(expression),
NavigationUri = GetNavigationUriFrom(expression, 1),
NavigationParameters = ExpressionInspector.GetArgOf<NavigationParameters>(expression),
};
}

public static NavigationExpressionArgs FromGoBackToExpression(Expression expression)
{
var methodCall = (MethodCallExpression)((LambdaExpression)expression).Body;

var index = methodCall.Arguments.Any(a => a.Type == typeof(NavigationParameters))
? 0
: 1;

return new NavigationExpressionArgs
{
NavigationUri = GetNavigationUriFrom(expression, index),
NavigationParameters = ExpressionInspector.GetArgOf<NavigationParameters>(expression),
};
}
Expand Down Expand Up @@ -225,11 +240,11 @@ private static (Uri Uri, INavigationParameters? NavigationParameters) ParseUriBu
return fieldValue;
}

private static Uri GetNavigationUriFrom(Expression expression)
private static Uri GetNavigationUriFrom(Expression expression, int index)
{
var methodCall = (MethodCallExpression)((LambdaExpression)expression).Body;

var destination = methodCall.Arguments[1];
var destination = methodCall.Arguments[index];

if (destination.Type == typeof(Uri))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Moq.INavigationService/SetupNavigationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static ISetup<INavigationService, Task<INavigationResult>> SetupNavigatio
GuardVerifyExpressionIsForNavigationExtensions(expression);

// Workout uri
var verifyNavigationExpression = VerifyNavigationExpression.From(expression);
var verifyNavigationExpression = VerifyNavigationExpression.FromNavigateExpression(expression);

return ApplySetup(
navigationServiceMock,
Expand Down
15 changes: 13 additions & 2 deletions src/Moq.INavigationService/VerifyNavigationExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ internal class VerifyNavigationExpression
public required Expression? DestinationUriExpression { get; set; }
public required Expression? NavigationParametersExpression { get; set; }

public static VerifyNavigationExpression From(Expression expression)
public static VerifyNavigationExpression FromNavigateExpression(Expression expression)
{
return expression.ToString().Contains("CreateBuilder")
? ParseNavigationBuilderExpression(expression)
: ParseUriNavigationExpression(expression);
}

public static VerifyNavigationExpression FromGoBackToExpression(Expression expression)
{
return new VerifyNavigationExpression
{
Args = NavigationExpressionArgs.FromGoBackToExpression(expression),
DestinationStringExpression = ExpressionInspector.GetArgExpressionOf<string>(expression),
DestinationUriExpression = null,
NavigationParametersExpression = ExpressionInspector.GetArgExpressionOf<NavigationParameters>(expression),
};
}

private static VerifyNavigationExpression ParseUriNavigationExpression(Expression expression)
{
return new VerifyNavigationExpression
{
Args = NavigationExpressionArgs.FromUriExpression(expression),
Args = NavigationExpressionArgs.FromNavigateUriExpression(expression),
DestinationStringExpression = ExpressionInspector.GetArgExpressionOf<string>(expression),
DestinationUriExpression = ExpressionInspector.GetArgExpressionOf<Uri>(expression),
NavigationParametersExpression = ExpressionInspector.GetArgExpressionOf<NavigationParameters>(expression),
Expand Down
Loading

0 comments on commit 8e941d7

Please sign in to comment.