Last active
September 26, 2023 19:15
-
-
Save rcollette/3f46b1fa2efc540b4d4a895ebce60b13 to your computer and use it in GitHub Desktop.
moq enumerable matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Moq; | |
public static class MatcherExtensions | |
{ | |
public static T[] CreateEnumerableMatcher<T>(this T[] expectation) | |
{ | |
return Match.Create<T[]>( | |
inputCollection => | |
{ | |
bool result = expectation.All(inputCollection.Contains); | |
return result; | |
}); | |
} | |
public static IEnumerable<T> CreateEnumerableMatcher<T>(this IEnumerable<T> expectation) | |
{ | |
return Match.Create<IEnumerable<T>>( | |
inputCollection => | |
{ | |
bool result = expectation.All(inputCollection.Contains); | |
return result; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sut.Setup(s => s.SearchAsync(criteriaList.CreateEnumerableMatcher())).ReturnsAsync(searchResultDto)