I’ve got a strange behavior when using Match.Create with Moq.
The following code snippet doesn’t pass, when I extract Match.Create as a variable:
var mock = new Mock<IA>();
mock.Object.Method ("muh");
mock.Verify (m => m.Method (Match.Create<string> (s => s.Length == 3)));
public interface IA
{
void Method (string arg);
}
What is the reason?
Thanks both of you. But I found another good solution for this. As in the quick start described, you can also use a method. First I thought it would make no difference, whether I use a variable or method. But obviously Moq is clever enough. So the expression and predicate stuff can be converted into:
I think this is great, because it reduces the noise in unit tests.