c# typemock taking mocked result of last case

88 Views Asked by At

I am trying to mock using a method call using typeMock. I have mocked method in different cases but every time I am getting the same result. Following is code:

[TestFixture]
public class HomeControllerSpec
{
    User _fakeUser;
    ProfileSettingsBL _profileSettingBL = null;

    [SetUp]
    public void SetUp()
    {
        // Inital setup
    }


    [TestCase]
    public void DisconnectOutlookCalendarForUserRegisterWithEmail()
    {
        _fakeUser = new User();
        _fakeUser.LoginType = 4; // This is be different in each case

        Isolate.WhenCalled(() => _profileSettingBL.RetrieveUserProfile()).WillReturn(_fakeUser);

        HomeController ctrl = new HomeController();
        var result = ctrl.Disconnect();

        Assert.IsTrue(result.Content);
    }



    [TestCase]
    public void DisconnectOutlookCalendarForUserRegisterWithName()
    {

        _fakeUser = new User();
        _fakeUser.LoginType = 5; // This is be different in each case

        Isolate.WhenCalled(() => _profileSettingBL.RetrieveUserProfile()).WillReturn(_fakeUser);

        HomeController ctrl = new HomeController();
        var result = ctrl.Disconnect();

        Assert.IsTrue(result.Content);
    }

}

When different test case calling Disconnect method of HomeController I am getting _fakeUser.LoginType == 4 always. But when I am removing one of test case both cases running perfectly.

Any Idea?

1

There are 1 best solutions below

0
JamesR On

Maybe you can try using the [Isolated] attribute? It instructs Typemock Isolator to clean up the result of the test after the test is completed.