public void request_login_from_login_services_using_LoginDto()
        {
            Isolate.WhenCalled(() => LoginServices.IsLoggedIn(string.Empty)).WillReturn(true);

            SetEnvironmentOnController();
            _controller.Login(_user);

            Isolate.Verify.WasCalledWithExactArguments(() => LoginServices.Login(_user));
        }
        public void return_an_action_result_with_an_exception_message_when_environment_has_not_been_set_before_login()
        {
            var userName = _user.UserName;

            Isolate.WhenCalled(() => LoginServices.IsLoggedIn(userName)).WillReturn(false);

            var result = _controller.Login(_user);

            Assert.AreEqual(LoginController.NoEnvironmentMessage, ActionResultParser.GetPropertyValue <string>(result, "message"));
        }
        public void store_the_environment_name_in_the_HttpContextSession_collection()
        {
            var userName = _user.UserName;

            Isolate.WhenCalled(() => LoginServices.IsLoggedIn(userName)).WillReturn(true);

            SetEnvironmentOnController();
            _controller.Login(_user);
            Isolate.Verify.WasCalledWithAnyArguments(() => _sessionState.Add(LoginController.EnvironmentSetting, Testgenform));
        }
        public void return_success_is_true_when_password_change_for_valid_user()
        {
            Isolate.WhenCalled(() => LoginServices.ChangePassword(_user, TempPassword)).IgnoreCall();
            Isolate.WhenCalled(() => LoginServices.CheckPassword(TempPassword)).WillReturn(true);

            SetEnvironmentOnController();
            var result = _controller.ChangePassword(ValidUser, ValidPassword, TempPassword);

            Isolate.Verify.WasCalledWithAnyArguments(() => LoginServices.ChangePassword(_user, TempPassword));
            Assert.IsTrue(GetSuccessValueFromActionResult(result), "Password was not changed");
        }
        public void ask_login_services_if_user_is_logged_in()
        {
            var name = _user.UserName;

            Isolate.WhenCalled(() => LoginServices.IsLoggedIn(name)).WillReturn(true);

            SetEnvironmentOnController();
            _controller.Login(_user);

            Isolate.Verify.WasCalledWithExactArguments(() => LoginServices.IsLoggedIn(name));
        }
        public void return_success_is_false_when_invalid_login()
        {
            var userName = _user.UserName;

            Isolate.WhenCalled(() => LoginServices.IsLoggedIn(userName)).WillReturn(false);

            SetEnvironmentOnController();
            var result = _controller.Login(_user);

            Assert.IsFalse(GetSuccessValueFromActionResult(result));
        }
        public void not_change_the_password_when_not_logged_in()
        {
            Isolate.Fake.StaticMethods(typeof(LoginServices));
            Isolate.WhenCalled(() => LoginServices.ChangePassword(_user, "newpassword")).IgnoreCall();

            SetEnvironmentOnController();
            var result = _controller.ChangePassword("foo", "oldpassword", "newpassword");

            Isolate.Verify.WasCalledWithAnyArguments(() => LoginServices.ChangePassword(_user, "newpassword"));

            Assert.IsFalse(GetSuccessValueFromActionResult(result), "Password was not changed");
        }
        public void append_a_cookie_to_response_when_successfull_login()
        {
            var cookie = Isolate.Fake.Instance <HttpCookie>();

            Isolate.WhenCalled(() => LoginServices.IsLoggedIn(ValidUser)).WillReturn(true);
            Isolate.WhenCalled(() => _controller.Response).WillReturn(_response);

            SetEnvironmentOnController();
            _controller.Login(_user);

            Isolate.Verify.WasCalledWithAnyArguments(() => _response.AppendCookie(cookie));
        }
        public void return_success_is_true_when_valid_user_login()
        {
            // Setup
            Isolate.WhenCalled(() => LoginServices.IsLoggedIn(ValidUser)).WillReturn(true);
            Isolate.WhenCalled(() => LoginServices.GetLoggedIn()).WillReturn(ValidUser);
            Isolate.WhenCalled(() => _controller.Response).ReturnRecursiveFake();

            SetEnvironmentOnController();
            var result = _controller.Login(_user);

            Assert.IsTrue(GetSuccessValueFromActionResult(result));
        }
        public void MyTestInitialize()
        {
            _sessionState = Isolate.Fake.Instance <HttpSessionStateBase>();
            ObjectFactory.Configure(x => x.For <HttpSessionStateBase>().Use(_sessionState));
            _controller = ObjectFactory.GetInstance <LoginController>();

            Isolate.WhenCalled(() => EnvironmentServices.SetEnvironment("Test")).IgnoreCall();
            Isolate.WhenCalled(() => SessionStateManager.InitializeDatabase(_sessionState)).IgnoreCall();

            _user = new UserLoginDto
            {
                UserName    = "******",
                Password    = "******",
                Environment = Testgenform
            };
            Isolate.WhenCalled(() => LoginServices.Login(_user)).IgnoreCall();

            _response = Isolate.Fake.Instance <HttpResponseBase>();
            Isolate.WhenCalled(() => _controller.Response).WillReturn(_response);

            _context = Isolate.Fake.Instance <HttpContextBase>();
            Isolate.WhenCalled(() => _controller.HttpContext).WillReturn(_context);
            Isolate.WhenCalled(() => _context.Session).WillReturn(_sessionState);
        }