chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I posted this over at Beginners a few weeks ago, and haven't gotten a reply yet. At this point I'm assuming it's a bug:

(original post:

The codez:
    public class ClassToTest
        public void TestMe()
            var youllBeFaked = new ClassToFake();

    public class ClassToFake
        public void VerifyMe()
            throw new Exception("I wasn't faked!");

The test:
    public class TestBase
        protected ClassToFake fake { get; private set; }

        public void SetUp()
            fake = Isolate.Fake.Instance<ClassToFake>();

        public void TearDown()
    public class ClassToTestTest : TestBase

        /// <summary>
        ///A test for TestMe
        public void TestMeTest()
            ClassToTest target = new ClassToTest();
            Isolate.Verify.WasCalledWithAnyArguments(() => fake.VerifyMe());

The exception:
TypeMock.TypeMockException :
*** Isolate.Verify does not support objects that were not faked using Isolate.Fake.Instance(), or passed through WhenCalled()
at cp.a()
at du.a()
at db.a(Boolean A_0)
at dh.b(Boolean A_0)
at b3.b(Delegate A_0)
at b3.b(Action A_0)
at SomeProjectTest.ClassToTestTest.TestMeTest() in ClassToTestTest.cs: line 54

What am I doing wrong?

Thx for the help.
asked by Guillaume (3.5k points)

1 Answer

0 votes
Hi Guillaume,

This is not a bug but an expected behavior. Isolate.Verify verifies all of the call chain that you give it. You write:

Isolate.Verify.WasCalledWithAnyArguments(() => fake.VerifyMe());

Now, sicne fake is a property it tries to verify that the getter of fake was called - but it was never called, and not only that - it is defined as a property on the test class, and you can not verify that property, since the test class was not faked (obviously...)

There is a very simple fix for this - change the property to a field.
answered by yoel (1.9k points)