Skip to content

Instantly share code, notes, and snippets.

@rcollette
Last active September 26, 2023 19:15
Show Gist options
  • Save rcollette/3f46b1fa2efc540b4d4a895ebce60b13 to your computer and use it in GitHub Desktop.
Save rcollette/3f46b1fa2efc540b4d4a895ebce60b13 to your computer and use it in GitHub Desktop.
moq enumerable matcher
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;
});
}
}
@rcollette
Copy link
Author

rcollette commented Sep 26, 2023

sut.Setup(s => s.SearchAsync(criteriaList.CreateEnumerableMatcher())).ReturnsAsync(searchResultDto)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment