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
Advertisement