Simplify custom matchers
Hi,
It would be great if you simplify custom matchers - instead of declaring TWO methods, allow to declare just ONE.
So - for now, to replace in my tests
===============================
It.Is<string>(it => it.Equals("foo"))
===============================
I need two overloads:
===============================
[Matcher]
private static string Param(string test) { return null; }
public static bool Param(string s, string test) { return s.Equals(test); }
===============================
However, it looks like just one is enough - it could be something like just
===============================
[Matcher]
private static Match<string> Param(string test)
{
return new Match<string> {Test = (x => x.Equals(test))};
}
===============================
Where Match is defined within Moq, as
===============================
public class Match<T>
{
public Func<T, bool> Test;
public Match(Func<T, bool> test)
{
Test = test;
}
public static implicit operator T(Match<T> t)
{
return default(T);
}
}
===============================
Implicit conversion would satisfy the compiler, and Func would be used to build the actual matcher within MatcherFactory.CreateMatcher (see http://code.google.com/p/moq/source/browse/trunk/Source/MatcherFactory.cs).
Or, perhaps I'm missing something and it's not possible for other reasons?
2 comments
-
Adminkzu (Admin, moq) commented
Implemented in the trunk. Will be available in the 3.0 release!
-
Adminkzu (Admin, moq) commented
This sounds like very interesting approach to improve custom matchers!
I'll let Brian (who implemented the feature) evaluate an actual implementation.