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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I have this production code:
    public interface AbstractView<T> where T: MyAbstract
    {
        void FreeHandle(MoreStruct mySt, object er);
    }

    public class PresenterFull<T> where T: MyAbstract
    {
        public AbstractView<T> View
        { get; private set; }
        public PresenterFull(AbstractView<T> view)
        {
            View = view;
        }

        public void FreeHandle()
        {
            View.FreeHandle(new MoreStruct(5), null);
        }
    }

    public class MoreStruct
    {
        public double X
        {
            get; private set;
        }
        public MoreStruct(double x)
        {
            X = x;
        }

        public override bool Equals(object obj)
        {
            return X==((MoreStruct)obj).X;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }


and this test code
        [Test, Isolated]
        public void TestVerifyFail()
        {
            PresenterFull<MyAbstract> classList = Isolate.Fake.Instance<PresenterFull<MyAbstract>>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(()=>classList.FreeHandle()).CallOriginal();
            classList.FreeHandle();
            Isolate.Verify.WasCalledWithExactArguments(() => classList.View.FreeHandle(new MoreStruct(5), null));
        }


The code will fail with this exception:
failed: TypeMock.TypeMockException : 
*** Isolate.Verify does not support objects that were not faked using Isolate.Fake.Instance(), or passed through WhenCalled()
   at ce.a()
   at ew.a(Delegate A_0)
   at ew.c(Action A_0)
   
   at TypeMock.MethodDecorator.CallRealMethod()
   at TypeMock.DecoratorAttribute.CallDecoratedMethod()
   at TypeMock.ArrangeActAssert.IsolatedAttribute.Execute()
   at TypeMock.DecoratorAttribute.CallDecoratedMethod()
   at TypeMock.ClearMocksAttribute.Execute()
   at TypeMock.MethodDecorator.a()
   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)


However, this code will pass:
        [Test, Isolated]
        public void TestVerifyPass()
        {
            PresenterFull<MyAbstract> classList = Isolate.Fake.Instance<PresenterFull<MyAbstract>>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => classList.FreeHandle()).CallOriginal();
            classList.FreeHandle();
            MoreStruct ms = new MoreStruct(5);
            Isolate.Verify.WasCalledWithExactArguments(() => classList.View.FreeHandle(ms, null));
        }

________
Ford SVT Contour specifications
asked by nsoonhui (59.1k points)

2 Answers

0 votes
Is this case related to this one?
________
Mazda B platform specifications
answered by nsoonhui (59.1k points)
0 votes
Yes you are correct- the problem here is the same one.

The workaround is quite simple as well - just introduce am intermediate variable and pass it as a parameter to to the FreeHandle function inside the verify code block.
answered by dhelper (11.9k points)
...