Hi,
Thanks for your reply. I changed my setup to your suggestion. However, you need one change as you'll get an ambiguous reflection error otherwise:
this.mockHttpContext = MockManager.MockObject(typeof(HttpContext), Constructor.Mocked, new object[] { null });
However, I'm having trouble deciphering the expectations so that I can test my code correctly. Heres an example of the code I am testing:
if (this.context.Session["attempts"] != null)
{
int attempts = (int)this.context.Session["attempts"];
}
else
{
this.context.Session["attempts"] = 1;
}
// This is what we expect to do next
this.context.Session["previous action"] = "show login";
this.context.Session["action"] = "accept login";
And my unit test looks something like this:
this.mockHttpContext.ExpectGet("Session", this.httpSessionState);
this.mockHttpSessionState.ExpectGetIndex(null).Args("attempts");
// code should set attempts to 1 and set up the actions.
this.mockHttpSessionState.ExpectSetIndex(1).Args("attempts", 1);
this.mockHttpSessionState.ExpectSetIndex(1).Args("previous action", "show login");
this.mockHttpSessionState.ExpectSetIndex(1).Args("action", "accept login");
Presenter engine = new VelocityPresenter();
engine.TemplatePath = String.Empty;
LoginPage login = new LoginPage(this.httpContext, engine);
// The call we are testing via mocks should also return true.
Assert.IsTrue(login.ShowLoginForm(true));
Frankly I'm having trouble matching my expected sets and gets on the session to the setup required on my mock instance.
Can you provide any advice? I'm just shotgun debugging right now.
Thanks for your help so far! Its much appreciated! :D