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
Hi folks,

I recently tried Isolate.Verify.WasNotCalled() with a method in my system under test. Naturally, it failed because this only works on methods on fakes. Is there some way I can verify if a particular method in my system under test is or is not called?

For instance, I call sut.MyMethod(). Inside MyMethod, I have a conditional: if (foo > 5) { OtherMethod; }. OtherMethod is another method in the system under test. How do I verify that I got inside that conditional or did not get inside that conditional when this is not a method on a fake?

Thanks!
asked by lant3rn1969 (3.4k points)

1 Answer

0 votes
Hi Jack,

In order to verify a live object's method was called (or static method for class that wasn't faked)
you have to use an Isolator API first on that object, in order for it to track methods of that object, including non-publics.

One way to do it, is use Call Original on one of the methods.

For example :
        [TestMethod]
        public void Verify_CallWasMade()
        {
            RealClass realObject = new RealClass();

            Isolate.WhenCalled(() => realObject.RealMethod(2)).CallOriginal();
            realObject.RealMethod(2);
            Isolate.Verify.NonPublic.WasCalled(realObject, "InsideRealMethod");
        }

        class RealClass
        {
            public void RealMethod(int x)
            {
                if (x > 0)
                {
                    InsideRealMethod();
                }
            }

            private void InsideRealMethod()
            {
                
            }
        }
answered by Shai Barak (1.5k points)
...