So I have this controller that I want to test:
[HttpPost]
public ActionResult Login(FormCollection Form)
{
bool Authenticated = WebSecurity.Login(Form["UserName"], Form["Password"], false);
if (Authenticated)
{
string Return_Url = Request.QueryString["ReturnUrl"];
if (Return_Url == null)
{
return Redirect("~/Igras/Index");
}
else
{
Response.Redirect(Return_Url);
}
}
return View("Login");
}
This is my test:
[TestMethod]
public void testLogin()
{
FormCollection form = new FormCollection();
form.Set("UserName", "renej");
form.Set("Password", "renej");
//form.Add("UserName", "renej");
//form.Add("Password", "renej");
accountCTRL = new AccountController();
ViewResult r = accountCTRL.Login(form) as ViewResult;
Assert.AreEqual("Login", r.ViewName);
}
If I try to run the test, it gives me an error that the object is not set to an instance of an object(so null) on the parameter "authenticated" in the Login controller. Does anyone know how I would pass my username
and password
into the FormCollection
so the test would give it to the controller properly?