Hi,
I'm having trouble setting up a mocked HttpSession where I have different keys and want to return the same value for each key. Here is a rough break down of the method I am testing:
String previousaction = (String)context.Session["previous action"];
if (previousaction == null || previousaction.Length == 0)
{
Log("Previous action not valid");
return false;
}
// We weren't called from ShowLogin. So do that instead of this.
if (!previousaction.Equals("show login"))
{
context.Session.Remove("previous action");
return false;
}
// Check that this is not the fourth attempt at logging in and that
// the account is not locked.
int attempts = 0;
if (context.Session["attempts"] != null)
{
attempts = (int)context.Session["attempts"];
}
So I always want to return the same value for a given parameter. This
is my current test setup for the state (I've got the context stuff setup as per my previous post):
// Setup a valid post - these are correct user credentials
NameValueCollection formvars = new NameValueCollection();
formvars.Add("USERNAME", "proctos");
// This is wrong - need the right password before running this method!!
formvars.Add("PASSWORD", "testing");
this.mockHttpRequest.ExpectGetAlways("Form", formvars);
// Setup a valid session.
// We originally showed the login form. Now we are accepting login details
this.mockHttpSessionState.ExpectGetIndexAlways("show login").Args("previous action");
this.mockHttpSessionState.ExpectGetIndexAlways("accept login").Args("action");
Trouble is, when the test runs I'm getting errors because I don't think I'm using ExpectGetIndexAlways correctly.
My aim is to be able to setup a session environment tailored to a code path and then be able to test that the correct code path executes, the correct session vars are set and cleared (and so on).
Any advice?
Ta, S