I just wrote a
simple example of this:
public interface IFlow
{
bool CanNavigate(int i);
}
public interface IController
{
bool CanNavigate(IFlow flow, int id, out bool can);
}
public class Flow : IFlow
{
private IController controller;
public bool CanNavigate(int id)
{
bool can;
if (this.controller.CanNavigate(this, id, out can))
{
return can;
}
return false;
}
public override string ToString()
{
return base.ToString();
}
}
class Program
{
static void Main(string[] args)
{
MockManager.Init();
using (MockScope scope = new MockScope())
{
Flow target = RecorderManager.CreateMockedObject<Flow>(Constructor.Mocked, StrictFlags.AllMethods);
Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject accessor = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(target);
IController controller = RecorderManager.CreateMockedObject<IController>(Constructor.Mocked, StrictFlags.AllMethods);
accessor.SetField("controller", controller);
int id = 10;
bool can = false;
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.DefaultBehavior.CheckArguments();
target.CanNavigate(id);
recorder.CallOriginal();
recorder.ExpectAndReturn(controller.CanNavigate(target, id, out can), true);
}
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(can, target.CanNavigate(id));
}
}
}
Unhandled Exception: TypeMock.VerifyException:
TypeMock Verification: Unexpected Call to Flow.ToString()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Object p1, Object p2, Object p3)
at MockIController.CanNavigate(IFlow , Int32 , Boolean& )
at Flow.CanNavigate(Int32 id)
at Program.Main(String[] args)
Just comment out the ToString() implementation or record an expectation for 2 calls to ToString().