I am trying to test the Login method, which, when the user and password parameters are correct, sets the value of two session variables and three cookies and finally returns true.
I read a few posts about unit testing, but for some reason this didn't completely help me. I know that there should be only one statement per unit test, although you can use more than one while you test one “logical concept”.
The login method is correct only if it correctly sets each session variable and cookie and returns the expected value, so I'm not sure it would be good to check all these values at once (this will result in using six statements in the unit test, I think it's a little dirty) , or if I have to check the value of each session variable and cookie separately in different tests.
[TestMethod()]
public void SuccessfulLoginTest()
{
String username = "foo";
String password = "correct password";
Boolean remember = true;
Boolean actual = Login(username, password, remember);
Assert.IsTrue(actual);
Assert.AreEqual("foo", HttpContext.Current.Session["Username"]);
Assert.AreEqual(1, HttpContext.Current.Session["Group"]);
Assert.AreEqual("foo", HttpContext.Current.Response.Cookies["Username"].Value);
Assert.AreEqual("en", HttpContext.Current.Response.Cookies["Lang1"].Value);
Assert.AreEqual("es", HttpContext.Current.Response.Cookies["Lang2"].Value);
}
source
share