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