Reputation: 179
I'm using Typemock Isolator version 8.6.2.0. I have the following classes:
public class A
{
public B b { get; }
public A()
{
b = new B();
}
}
public class B
{
public B()
{
Console.WriteLine("In B c'tor");
}
public void doSomething()
{
}
}
The test method is:
public void test()
{
Isolate.Fake.NextInstance<B>();
A a = new A();
var bObject = a.b;
bObject.doSomething();
Isolate.Verify.WasCalledWithAnyArguments(() => bObject.doSomething());
}
When I run the test I get the following exception:"Cannot verify on real object - use a fake object instead", but the object is faked! Does anyone know why it happens and how I can fix it?
Upvotes: 2
Views: 129
Reputation:
write your test like this: `
public void test()
{
var fake = Isolate.Fake.NextInstance<B>();
A a = new A();
var bObject = a.b;
bObject.doSomething();
Isolate.Verify.WasCalledWithAnyArguments(() => fake.doSomething());
}
`
Upvotes: 3
Reputation: 25100
NextInstance returns a handle that you can call Verify on. Right now, you throw the returned handle away.
Per the docs at http://www.typemock.com/docs/?book=Isolator&page=Documentation%2FHtmlDocs%2Ffakingfutureinstances.htm
Verifying is done on the instance returned from Isolate.Fake.NextInstance.
Upvotes: 3