Skip to content

Commit 08a651b

Browse files
committed
Added OfType method to RouteActionResultValidator
1 parent 9dd2e47 commit 08a651b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/MyTested.AspNetCore.Mvc.Controllers.ActionResults/Utilities/Validators/RouteActionResultValidator.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,37 @@ public static void ValidateUrlHelper(
235235
/// <summary>
236236
/// Validates whether UrlHelper contains the same type as the provided one from action result containing such property.
237237
/// </summary>
238-
/// <typeparam name="TUrlHelper">Type of IUrlHelper.</typeparam>
239238
/// <param name="actionResult">Action result with UrlHelper.</param>
240239
/// <param name="failedValidationAction">Action to call in case of failed validation.</param>
241-
public static void ValidateUrlHelperOfType<TUrlHelper>(
240+
/// <param name="urlHelperType"></param>
241+
public static void ValidateUrlHelperOfType(
242242
dynamic actionResult,
243-
Action<string, string, string> failedValidationAction)
244-
where TUrlHelper : IUrlHelper
243+
Action<string, string, string> failedValidationAction,Type urlHelperType)
245244
{
246245
RuntimeBinderValidator.ValidateBinding(() =>
247246
{
248247
var actualUrlHelper = (IUrlHelper)actionResult.UrlHelper;
249248
if (actualUrlHelper == null ||
250-
Reflection.AreDifferentTypes(typeof(TUrlHelper), actualUrlHelper.GetType()))
249+
Reflection.AreDifferentTypes(urlHelperType, actualUrlHelper.GetType()))
251250
{
252251
failedValidationAction(
253252
"URL helper",
254-
$"to be of {typeof(TUrlHelper).Name} type",
253+
$"to be of {urlHelperType.Name} type",
255254
$"instead received {actualUrlHelper.GetName()}");
256255
}
257256
});
258257
}
258+
259+
/// <summary>
260+
/// Validates whether UrlHelper contains the same type as the provided one from action result containing such property.
261+
/// </summary>
262+
/// <typeparam name="TUrlHelper">Type of IUrlHelper.</typeparam>
263+
/// <param name="actionResult">Action result with UrlHelper.</param>
264+
/// <param name="failedValidationAction">Action to call in case of failed validation.</param>
265+
public static void ValidateUrlHelperOfType<TUrlHelper>(
266+
dynamic actionResult,
267+
Action<string, string, string> failedValidationAction)
268+
where TUrlHelper : IUrlHelper
269+
=> RouteActionResultValidator.ValidateUrlHelperOfType(actionResult, failedValidationAction, typeof(TUrlHelper));
259270
}
260271
}

0 commit comments

Comments
 (0)