Skip to content

Commit fd6e7ff

Browse files
committed
Added OfType method to OutputFormatterValidator (#148)
1 parent 940a211 commit fd6e7ff

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,25 @@ public static void ValidateContainingOfOutputFormatter(
4141
public static void ValidateContainingOutputFormatterOfType<TOutputFormatter>(
4242
ObjectResult objectResult,
4343
Action<string, string, string> failedValidationAction)
44+
=> ValidateContainingOutputFormatterOfType(objectResult, failedValidationAction, typeof(TOutputFormatter));
45+
46+
/// <summary>
47+
/// Validates whether object result Formatters contains the provided type of output formatter.
48+
/// </summary>
49+
/// <param name="objectResult">Object result to test.</param>
50+
/// <param name="failedValidationAction">Action to call in case of failed validation.</param>
51+
/// <param name="outputFromatterType"></param>
52+
public static void ValidateContainingOutputFormatterOfType(
53+
ObjectResult objectResult,
54+
Action<string, string, string> failedValidationAction,Type outputFromatterType)
4455
{
4556
var outputFormatters = objectResult.Formatters;
46-
var typeOfExpectedOutputFormatter = typeof(TOutputFormatter);
4757

48-
if (outputFormatters.All(f => Reflection.AreDifferentTypes(f.GetType(), typeOfExpectedOutputFormatter)))
58+
if (outputFormatters.All(f => Reflection.AreDifferentTypes(f.GetType(), outputFromatterType)))
4959
{
5060
failedValidationAction(
5161
"output formatters",
52-
$"to contain formatter of {typeOfExpectedOutputFormatter.Name} type",
62+
$"to contain formatter of {outputFromatterType.Name} type",
5363
"such was not found");
5464
}
5565
}

0 commit comments

Comments
 (0)