Esempio n. 1
0
    public void Login_Post_Model_Invalid_Test()
    {
      // arrange
      var model = new UserModel();
      _adminController.ModelState.AddModelError("UserName", "UserName is required");

      // act
      var actual = _adminController.Login(model, "/");

      // assert
      Assert.IsInstanceOf<ViewResult>(actual);
    }
Esempio n. 2
0
 public ActionResult LogOn(User model, string returnUrl)
 {
     UserModel um = new UserModel(model);
     if (ModelState.IsValid)
     {
         // Verify if user loggin is true
         if (_authProvider.Login(model))
         {
             //FormsAuthentication.RedirectFromLoginPage("", false);
             return RedirectToUrl(returnUrl);
         }
         else
         {
             ModelState.AddModelError("", "Username or Password Incorrect");
         }
     }
     return View(model);
 }
Esempio n. 3
0
    public void Login_Post_User_Invalid_Test()
    {
      // arrange
      var model = new UserModel { UserName = "******", Password = "******" };
      _authProvider.Stub(s => s.Login(model.UserName, model.Password)).Return(false);

      // act
      var actual = _adminController.Login(model, "/");

      // assert
      Assert.IsInstanceOf<ViewResult>(actual);
      var modelStateErrors = _adminController.ModelState[""].Errors;
      Assert.IsTrue(modelStateErrors.Count > 0);
      Assert.AreEqual("The user name or password provided is incorrect.", modelStateErrors[0].ErrorMessage);
    }
Esempio n. 4
0
    public void Login_Post_User_Valid_Test()
    {
      // arrange
      var model = new UserModel { UserName = "******", Password = "******" };
      _authProvider.Stub(s => s.Login(model.UserName, model.Password)).Return(true);

      // act
      var actual = _adminController.Login(model, "/");

      // assert
      Assert.IsInstanceOf<RedirectResult>(actual);
      Assert.AreEqual("/", ((RedirectResult)actual).Url);
    }