So I just posted this post where I wanted the It.IsAny syntax in Typemock. Without giving any long thought on this I wrote two simple solutions:
Solution 1
public static class IVerifyHandlerExtensions
{
public static void WasCalledWithAnyArguments<T>(this IVerifyHandler handler, Action<T> action)
{
handler.WasCalledWithAnyArguments(() => action.Invoke(default(T)));
}
}
[Test, Isolated]
public void TheTest()
{
var fake = Isolate.Fake.Instance<MyClassUnderTest>();
fake.MyMethod(new MyArgsWithoutEquals());
Isolate.Verify.WasCalledWithAnyArguments<MyArgsWithoutEquals>(fake.MyMethod);
}
Solution 2
public static class IsAny<T>
{
public static T Item = default(T);
}
[Test, Isolated]
public void TheTest2()
{
var fake = Isolate.Fake.Instance<MyClassUnderTest>();
fake.MyMethod(new MyArgsWithoutEquals());
Isolate.Verify.WasCalledWithAnyArguments(() => fake.MyMethod(IsAny<IMyArgs>.Item));
}
As I said. Not much thinking in there so I’m probably missing something. It worked for me. Now I don’t have to type “null” any more.
//Daniel
Pingback: Tweets that mention I put together a post instead. -- Topsy.com
Pingback: Moq vs Typemock – Simple solution to It.Is(expression) « Daniel Wertheim