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 have the production code:
    public class ItemController:Controller
    {
        public IItemFactory factory;
        public RedditCloneTests.TypeMockTesting.IItemFactory Factory
        {
            get { return factory; }
            set { factory = value; }
        }
        public ItemController()
            : this(null)
        {

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

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


and the test code
    [TestFixture, ClearMocks]
    public class TestItemFactory
    {
        private ItemController controllerFake;
        private ItemController controller;
        private ItemFactory itemFactoryFake;
        public TestItemFactory()
        {

        }


        [SetUp]
        public void Init()
        {

            controllerFake = Isolate.Fake.Instance<ItemController>(Members.CallOriginal);
            Isolate.SwapNextInstance<ItemController>().With(controllerFake);

            controller = new ItemController();
        }

        [Test, Isolated]
        public void TestLogin()
        {
            Isolate.NonPublic.WhenCalled(controllerFake, "View").WithGenericArguments(typeof(string), typeof(object)).WillReturn(null);
            controllerFake.Login();
        }


    }


But when I run the test method TestLogin, I got the following exception
Method View<String> in type RedditCloneTests.TypeMockTesting.ItemController has no matching overload that returns TypeMock.Mock+a.
   TypeMock.TypeMockException
   Message: 
   *** Method View<String> in type RedditCloneTests.TypeMockTesting.ItemController has no matching overload that returns TypeMock.Mock+a.
   Source: TypeMock
   StackTrace:
   at bt.b(Type A_0, String A_1, Type A_2, Type[] A_3)
   at TypeMock.Mock.a(String A_0, Object A_1, Boolean A_2, Boolean A_3, Int32 A_4, Type[] A_5)
   at TypeMock.Mock.a(String A_0, Object A_1, Boolean A_2, Boolean A_3, Type[] A_4)
   at TypeMock.Mock.AlwaysReturn(String method, Object ret, Type[] genericTypes)
   at x.WillReturn(Object value)


How to fix the failing test? The problem occurs at this line:
Isolate.NonPublic.WhenCalled(controllerFake, "View").WithGenericArguments(typeof(string), typeof(object)).WillReturn(null);

________
Ford Falcon (North America) picture
asked by nsoonhui (59.1k points)

5 Answers

0 votes
Hi
It looks like a bug.
It looks like the Isolator does not recognize the View as a generic method.
And surly the error message is bad :oops:

Can you post here the View method signature? Is it inherited from another class?
answered by ohad (35.4k points)
0 votes
Yes it is. It is a method of Controller, which is a class introduced in ASP.NET MVC.

There are quite a number of overloads for the View, such as

  1. View()
  2. View(string viewName, object model)


and so on.

Do let me know about the status of this case, thanks
________
Stobart VK M-Sport Ford Rally Team
answered by nsoonhui (59.1k points)
0 votes
Hi
It seems to me that the problem is that you are using the WithGenericArguments on non generic method.

I can see that you are trying to overcome the overloading problem but
currently we don't support this.
Having said that if you'll use:
Isolate.NonPublic.WhenCalled(controllerFake, "View").WillReturn(null);

it might work for you depends on the method list returned from ItemController class.
answered by ohad (35.4k points)
0 votes
Hi
It seems to me that the problem is that you are using the WithGenericArguments on non generic method.

I can see that you are trying to overcome the overloading problem but
currently we don't support this.
Having said that if you'll use:
Isolate.NonPublic.WhenCalled(controllerFake, "View").WillReturn(null);

it might work for you depends on the method list returned from ItemController class.


Thanks ohad, but since I need to call an overload method of "View", I afraid that the suggestion won't work.

Any plans to support non-generic argument? That would be tremendously useful for us.
________
Yamaha FJ1200
answered by nsoonhui (59.1k points)
0 votes
Hi
It seems to me that the problem is that you are using the WithGenericArguments on non generic method.

I can see that you are trying to overcome the overloading problem but
currently we don't support this.
Having said that if you'll use:
Isolate.NonPublic.WhenCalled(controllerFake, "View").WillReturn(null);

it might work for you depends on the method list returned from ItemController class.


Thanks ohad, but since I need to call an overload method of "View", I afraid that the suggestion won't work.

Any plans to support non-generic argument? That would be tremendously useful for us.
________
herbalaire vaporizer
answered by nsoonhui (59.1k points)
...