-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specifying the expected number of occurrences in IsIn() #1214
Comments
It is sometimes a pity that static classes cannot be extended that way, right? Nevertheless, I think it doesn't make sense to add all possible kinds of specific predicates to Moq's (There are some fairly specific |
Ok, that sounds reasonable. Is it actually possible to create the same logic using current constructs and custom argument matchers? If so, could show an example? |
I think you've already figured out how to use custom matchers for this. But here goes. You can replace From there, it should be easy to adjust the predicate so it checks for You could then wrap this up similar to how you've done already: static T IsExactlyIn<T>(IEnumerable<T> items, int times)
{
return It.Is(x => items.Count(y => y == x) == times);
} (I probably wouldn't even go down the custom matcher path for this; wrapping |
Thank you. I'll close this. |
In a verification step, I would like to specify the number of times an expected value should occur.
Using the current version:
But that does not catch cases where you need to verify an exact number of times an expected value is allowed, it just verifies that the value is in the list.
I did an honest attempt to make this possible. Since the
It
class is static and sealed, it is not possible to create an extension method nor inherit fromIt
, so I made my static class and method:This would require that the mock is only called once for either of the expected values in
expectedListOfValues
.I took the current implementation of
IsIn()
and added a requirement:I'm wondering whether I should create a PR for this or you don't see any reason to add this Moq?
The text was updated successfully, but these errors were encountered: