public void Recover_Information()
        {
            AccountRecoveryView view = ObjectsFactory.CreateAccountRecoveryView();

            account.RecoveryTokenExpirationDate = DateTime.Now.AddMinutes(30);
            String?oldToken = account.RecoveryToken;

            view.Email = view.Email?.ToUpper();

            account.RecoveryToken = service.Recover(view);

            Account actual   = context.Set <Account>().AsNoTracking().Single();
            Account expected = account;

            Assert.InRange(actual.RecoveryTokenExpirationDate !.Value.Ticks,
                           expected.RecoveryTokenExpirationDate.Value.Ticks - TimeSpan.TicksPerSecond,
                           expected.RecoveryTokenExpirationDate.Value.Ticks + TimeSpan.TicksPerSecond);
            Assert.Equal(expected.RecoveryToken, actual.RecoveryToken);
            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.IsLocked, actual.IsLocked);
            Assert.Equal(expected.Passhash, actual.Passhash);
            Assert.Equal(expected.Username, actual.Username);
            Assert.NotEqual(oldToken, actual.RecoveryToken);
            Assert.Equal(expected.RoleId, actual.RoleId);
            Assert.Equal(expected.Email, actual.Email);
            Assert.Equal(expected.Id, actual.Id);
            Assert.NotNull(actual.RecoveryToken);
        }
Beispiel #2
0
        public void CanRecover_InvalidState_ReturnsFalse()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanRecover(ObjectsFactory.CreateAccountRecoveryView(account.Id + 1)));
            Assert.Single(validator.ModelState);
        }
        public void Recover_NoEmail_ReturnsNull()
        {
            AccountRecoveryView view = ObjectsFactory.CreateAccountRecoveryView();

            view.Email = "*****@*****.**";

            Assert.Null(service.Recover(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 CanRecover_ValidAccount()
 {
     Assert.True(validator.CanRecover(ObjectsFactory.CreateAccountRecoveryView(0)));
     Assert.Empty(validator.ModelState);
     Assert.Empty(validator.Alerts);
 }