Exemple #1
0
        public void CanLogin_InvalidState_ReturnsFalse()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanLogin(ObjectsFactory.CreateAccountLoginView(account.Id)));
            Assert.Single(validator.ModelState);
        }
        public void CanLogin_IsCaseInsensitive()
        {
            AccountLoginView view = ObjectsFactory.CreateAccountLoginView(0);

            view.Username = view.Username.ToUpper();

            Assert.True(validator.CanLogin(view));
        }
        public AuthControllerTests()
        {
            mail       = Substitute.For <IMailClient>();
            service    = Substitute.For <IAccountService>();
            validator  = Substitute.For <IAccountValidator>();
            controller = Substitute.ForPartsOf <AuthController>(validator, service, mail);
            controller.ControllerContext.HttpContext = Substitute.For <HttpContext>();
            controller.TempData = Substitute.For <ITempDataDictionary>();
            controller.ControllerContext.RouteData = new RouteData();
            controller.Url = Substitute.For <IUrlHelper>();

            accountRecovery = ObjectsFactory.CreateAccountRecoveryView();
            accountReset    = ObjectsFactory.CreateAccountResetView();
            accountLogin    = ObjectsFactory.CreateAccountLoginView();
        }
        public void CanLogin_LockedAccount_ReturnsFalse()
        {
            AccountLoginView view = ObjectsFactory.CreateAccountLoginView(account.Id + 1);

            account          = context.Set <Account>().Single();
            account.IsLocked = true;
            context.SaveChanges();

            Boolean canLogin = validator.CanLogin(view);
            Alert   alert    = validator.Alerts.Single();

            Assert.False(canLogin);
            Assert.Equal(0, alert.Timeout);
            Assert.Empty(validator.ModelState);
            Assert.Equal(AlertType.Danger, alert.Type);
            Assert.Equal(Validation.For <AccountView>("LockedAccount"), alert.Message);
        }
        public void CanLogin_IncorrectPassword_ReturnsFalse()
        {
            account          = context.Set <Account>().Single();
            account.IsLocked = true;
            context.SaveChanges();

            AccountLoginView view = ObjectsFactory.CreateAccountLoginView(account.Id + 1);

            hasher.VerifyPassword(view.Password, Arg.Any <String>()).Returns(false);

            Boolean canLogin = validator.CanLogin(view);
            Alert   alert    = validator.Alerts.Single();

            Assert.False(canLogin);
            Assert.Equal(0, alert.Timeout);
            Assert.Empty(validator.ModelState);
            Assert.Equal(AlertType.Danger, alert.Type);
            Assert.Equal(Validation.For <AccountView>("IncorrectAuthentication"), alert.Message);
        }
 public void CanLogin_ValidAccount()
 {
     Assert.True(validator.CanLogin(ObjectsFactory.CreateAccountLoginView(0)));
     Assert.Empty(validator.ModelState);
     Assert.Empty(validator.Alerts);
 }