Moq vs Typemock – Simple solution to It.Is(expression)

So I thought I just add one more post about this subject. Previous posts:

As I stated I don’t like the predicate that gives me an object[0], so why not do something about it.

public static class IArgumentsMatcherExtensions
{
    public static void Matching<T>(this IArgumentsMatcher matcher, Predicate<T> verify)
    {
        matcher.Matching(args => verify.Invoke((T)args[0]));
    }
}

With this code I can now write tests like:

[Test, Isolated]
public void TheTest3()
{
    var args = new MyArgsWithoutEquals();
    var fake = Isolate.Fake.Instance<MyClassUnderTest>();
    fake.MyMethod(args);

    Isolate.Verify.WasCalledWithArguments(
        () => fake.MyMethod(args)).Matching<IMyArgs>(a1 => a1.Id == 1);
}

Instead of

[Test]
public void TheTest4()
{
    var args = new MyArgsWithoutEquals();
    var fake = Isolate.Fake.Instance<MyClassUnderTest>();
    fake.MyMethod(args);

    Isolate.Verify.WasCalledWithArguments(
        () => fake.MyMethod(args)).Matching(x => ((IMyArgs)x[0]).Id == 1);
}

I hope I will see something like this in Typemock in the future.

//Daniel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s