Try the following code
public class DerivedController:System.Web.Mvc.Controller
{
}
[TestFixture, ClearMocks]
public class ControllerTest
{
[Test, Isolated]
public void FirstController()
{
var controller = Isolate.Fake.Instance<DerivedController>();
Isolate.WhenCalled(()=>controller.Session).ReturnRecursiveFake();
Isolate.WhenCalled(() => controller.Session["a"])
.WillReturn("a");
Assert.IsNull(controller.Session["b"]);
}
}
There is this exception:
failed: TypeMock.TypeMockException :
*** Unexpected Call to System.Web.HttpSessionStateBase.get_Item()
at b3.b(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at System.Web.HttpSessionStateBase.get_Item(String name)
C:developmentEsteem7 .Net2ELockRecordWebSourceELockRecordWebELockRecordWebTestControllerControllerTest.cs(27,0): at ELockRecordWebTest.Controller.ControllerTest.FirstController()
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)
But if you comment this line:
Isolate.WhenCalled(() => controller.Session["a"])
.WillReturn("a");
Then the test can pass.
I suspect that the above line disturbs the states in Isolator.
This is quite an urgent case for me because it lies in my production code. Do have a check
________
Babi Mac Breakaway