Checkers are part of the older API (Reflective/Natural) and can be used from that API:
[Test]
public void Authenticated ()
{
Authentication authenticator = new Authentication();
MockManager.Init ();
// the Logger class is now being mocked
Mock logMock = MockManager.Mock(typeof(Logger));
// set up our expectations
logMock.ExpectCall("Log").Args(Logger.NORMAL,Check.IsAny());
logMock.ExpectCall("Log").Args(Logger.FAILED,Check.IsAny());
Assert.IsFalse(authenticator.IsAuthenticated("user","password"));
MockManager.Verify();
}
<Test()> Public Sub Authenticated ()
Dim authenticator As Authentication = new Authentication
MockManager.Init()
' the Logger class is now being mocked
Dim logMock As Mock = MockManager.Mock(GetType(Logger))
' set up our expectations
logMock.ExpectCall("Log").Args(Logger.NORMAL,Check.IsAny())
logMock.ExpectCall("Log").Args(Logger.FAILED,Check.IsAny())
Assert.IsFalse(authenticator.IsAuthenticated("user","password"))
MockManager.Verify()
End Sub
To find more a about the available checkers see:
https://www.typemock.com/Docs/UserGuide/ ... ildIn.html
In the newer AAA API we use DoInstead that uses a delegate to check for specific arguments:
[TestMethod]
[Isolated]
public void TestDoInstead()
{
var fake = Isolate.Fake.Instance<ProductShelf>();
// When GetProductQuantity will be called, our anonymous delegate will run.
// GetProductQuantity will return the value based on the custom logic inside the delegate.
Isolate.WhenCalled(()=> fake.GetProductQuantity("")).DoInstead(callContext=>
{
// Access method arguments
string name = callContext.Parameters[0] as string;
if(name == "MyProduct")
{
return 10;
}
return 5;
});
// Assert - out custom behavior is returned when the method is called
Assert.AreEqual(10, (int)fake.GetProductQuantity("MyProduct"));
Assert.AreEqual(5, (int)fake.GetProductQuantity("OtherProduct"));
}