Hi,
First of all the solution. Since you are using Natural Mocks, you can easily write this test:
[TestMethod]
[VerifyMocks]
public void MockSession()
{
IHttpContextLocatorService _httpContextService = RecorderManager.CreateMockedObject<IHttpContextLocatorService>();
MockProcessController _controller = new MockProcessController(_httpContextService);
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.ExpectAndReturn(_controller.Context.Session["SessionParam1"], "expectedValue");
}
Assert.AreEqual("expectedValue", _controller.Context.Session["SessionParam1"]);
}
What you are trying to mock is called a "chain". It's very simple to mock using Natural Mocks.
Now, if I may, the code you posted seems a bit complex. You are mixing both reflective and Natural mocks unnecessarily. I would suggest the following:
1. Use Natural mocks when possible. It makes the code more readable.
2. When you use RecorderManager.CreateMockedObject, use it inside the recording block, unless the code outside uses the object.
Let me know if this works for you.
Thanks,