Ejemplo n.º 1
0
        public void can_not_send_empty_form()
        {
            var form = new LogOnForm
            {
                Login = "******",
                Password = "******",
            };

            controller.ModelState.AddModelError("error", "error");

            var result = controller.LogOn(form) as ViewResult;

            Assert.Empty(result.ViewName);
            Assert.Equal(form, result.Model);
        }
Ejemplo n.º 2
0
        public ActionResult LogOn(LogOnForm form)
        {
            if (!ModelState.IsValid)
                return View(form);

            var user = _userRepository.Users.FirstOrDefault(u =>
                u.Login == form.Login &&
                u.Password == form.Password &&
                u.IsActive
                );
            var exist = user != null;

            if (exist)
            {
                _authProvider.Authenticate(user);
                return RedirectToAction("List", "Companies");
            }

            return View(form);
        }
Ejemplo n.º 3
0
        public void user_can_login_if_user_have_in_database_and_active()
        {
            var form = new LogOnForm
                           {
                               Login = "******",
                               Password = "******",
                           };

            usersMock.Setup(r => r.Users).Returns(new List<User>
                                                      {
                                                          new User
                                                              {
                                                                  Login = form.Login,
                                                                  Password = form.Password,
                                                                  IsActive = true
                                                              }
                                                      }.AsQueryable());

            controller.LogOn(form);

            authMock.Verify(a => a.Authenticate(It.Is<User>(u => u.Login == form.Login)), Times.Once());
        }
Ejemplo n.º 4
0
        public void user_can_not_login_if_user_exist_in_database_but_not_active()
        {
            var form = new LogOnForm
                           {
                               Login = "******",
                               Password = "******",
                           };

            usersMock.Setup(r => r.Users).Returns(new List<User>
                                                      {
                                                          new User
                                                              {
                                                                  Login = form.Login,
                                                                  Password = form.Password,
                                                                  IsActive = false
                                                              }
                                                      }.AsQueryable());

            controller.LogOn(form);

            authMock.Verify(a => a.Authenticate(It.IsAny<User>()), Times.Never());
        }
Ejemplo n.º 5
0
        public void when_user_login_success_should_redirect_to_Companies_List()
        {
            var form = new LogOnForm
            {
                Login = "******",
                Password = "******",
            };

            usersMock.Setup(r => r.Users).Returns(new List<User>
                                                      {
                                                          new User
                                                              {
                                                                  Login = form.Login,
                                                                  Password = form.Password,
                                                                  IsActive = true
                                                              }
                                                      }.AsQueryable());

            var result = controller.LogOn(form) as RedirectToRouteResult;

            Assert.Equal(result.RouteValues["action"], "List");
            Assert.Equal(result.RouteValues["controller"], "Companies");
        }
Ejemplo n.º 6
0
        public void when_user_login_fail_should_return_current_page()
        {
            var form = new LogOnForm
            {
                Login = "******",
                Password = "******",
            };

            var result = controller.LogOn(form) as ViewResult;

            Assert.Empty(result.ViewName);
            Assert.Equal(form, result.Model);
        }
Ejemplo n.º 7
0
        public void user_can_not_login_if_user_not_exist_in_database()
        {
            var form = new LogOnForm
                           {
                               Login = "******",
                               Password = "******",
                           };

            controller.LogOn(form);

            authMock.Verify(a => a.Authenticate(It.IsAny<User>()), Times.Never());
        }