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, if I return a mock concrete object in the place of an interface, AAA syntax may fail to handle the WasCalledWithExactArguments correctly.

Here's the production code:
    public interface IItemFactory 
    {
        void Submit(string url);
    }
    public class ItemFactory:IItemFactory
    {

        #region IItemFactory Members

        public void Submit(string url)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class ItemController:Controller
    {

        public RedditCloneTests.TypeMockTesting.IItemFactory Factory
        {
            get;private set;
        
        }
        public ItemController()
            : this(null)
        {

        }
        public ItemController(IItemFactory itemFactory)
        {
            Factory = itemFactory ?? new ItemFactory();
        }

        public ActionResult Login()
        {
            return View("Hi", 1);
        }

        public ActionResult Submit(string url)
        {
            Factory.Submit(url);
            return RedirectToAction("Main");
        }
    }


Here's the test code:
         [Test, Isolated]
         public void TestConcrete()
         {
             ItemController controller = Isolate.Fake.Instance<ItemController>(Members.CallOriginal);
             ItemFactory factory = Isolate.Fake.Instance<ItemFactory>(Members.ReturnRecursiveFakes);
             Isolate.WhenCalled(() => controller.Factory).WillReturn(factory);
             controller.Submit("");
             Isolate.Verify.WasCalledWithExactArguments(()=>controller.Factory.Submit(""));
         }

         [Test, Isolated]
         public void TestAbstract()
         {
             ItemController controller = Isolate.Fake.Instance<ItemController>(Members.CallOriginal);
             IItemFactory factory = Isolate.Fake.Instance<IItemFactory>(Members.ReturnRecursiveFakes);
             Isolate.WhenCalled(() => controller.Factory).WillReturn(factory);
             controller.Submit("");
             Isolate.Verify.WasCalledWithExactArguments(() => controller.Factory.Submit(""));
         }


TestConcrete fails but TestAbstract passes, both of them should pass anyway. Here's the stacktrace for the failure:
failed: 
TypeMock Verification: Method Factory.Submit() was expected but was not called
   TypeMock.VerifyException
   Message: 
   TypeMock Verification: Method Factory.Submit() was expected but was not called
   Source: TypeMock
   StackTrace:
   at ew.b(ae A_0, b5 A_1)
   at ew.c(Action A_0)
   D:C#TestRedditCloneRedditCloneTestsTypeMockTestingTestNestedCall.cs(22,0): at RedditCloneTests.TypeMockTesting.ItemFactoryDifficult.TestConcrete()
   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)

________
BONGS
asked by nsoonhui (59.1k points)

2 Answers

0 votes
Hi Soon Hui,

Interesting issue - I'll have a look and let you know
answered by dhelper (11.9k points)
0 votes
It seems we had a bug that caused checking & verifying of wrong return values.
I will send you a patch and this issue shall be resolved in the next version of isolator (5.1.3)
answered by dhelper (11.9k points)
...