I suggest you ...

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?

5 votes
Vote 0 votes Vote Vote
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    I agree to the terms of service

    You'll receive a confirmation email with a link to create a password (optional).

    Signed in as (Sign out)
    You have left! (?) (thinking…)
    andreisterandreister shared this idea  ·   ·  Admin →
    completed

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      I agree to the terms of service

      You'll receive a confirmation email with a link to create a password (optional).

      Signed in as (Sign out)
      Submitting...
      • kzuAdminkzu (Admin, moq) commented  · 

        Implemented in the trunk. Will be available in the 3.0 release!

      • kzuAdminkzu (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.

      Knowledge Base and Helpdesk