コード例 #1
0
        public void Reset_ResetsAccount()
        {
            Account          account = context.Set <Account>().AsNoTracking().Single();
            AccountResetView view    = ObjectFactory.CreateAccountResetView();

            hasher.HashPassword(view.NewPassword).Returns("Reset");
            account.RecoveryTokenExpirationDate = null;
            account.RecoveryToken = null;
            account.Passhash      = "Reset";

            service.Reset(view);

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

            Assert.Equal(expected.RecoveryTokenExpirationDate, actual.RecoveryTokenExpirationDate);
            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.Equal(expected.RoleId, actual.RoleId);
            Assert.Equal(expected.Email, actual.Email);
            Assert.Equal(expected.Id, actual.Id);
        }
コード例 #2
0
        public void CanReset_CanNotResetAccountWithExpiredToken()
        {
            Account account = context.Set <Account>().Single();

            account.RecoveryTokenExpirationDate = DateTime.Now.AddMinutes(-5);
            context.SaveChanges();

            Assert.False(validator.CanReset(ObjectFactory.CreateAccountResetView()));
        }
コード例 #3
0
        public void SetUp()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountRecovery = ObjectFactory.CreateAccountRecoveryView();
            accountReset    = ObjectFactory.CreateAccountResetView();
            accountLogin    = ObjectFactory.CreateAccountLoginView();
            account         = new AccountView();

            controller = Substitute.ForPartsOf <AuthController>(validator, service);
            controller.ControllerContext = new ControllerContext();
        }
コード例 #4
0
        public void CanReset_ExpiredToken_ReturnsFalse()
        {
            account.RecoveryTokenExpirationDate = DateTime.Now.AddMinutes(-5);
            context.SaveChanges();

            Boolean canReset = validator.CanReset(ObjectFactory.CreateAccountResetView());
            Alert   alert    = validator.Alerts.Single();

            Assert.False(canReset);
            Assert.Equal(0, alert.Timeout);
            Assert.Empty(validator.ModelState);
            Assert.Equal(AlertType.Danger, alert.Type);
            Assert.Equal(Validations.ExpiredToken, alert.Message);
        }
コード例 #5
0
        public void SetUp()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountRecovery = ObjectFactory.CreateAccountRecoveryView();
            accountReset    = ObjectFactory.CreateAccountResetView();
            accountLogin    = ObjectFactory.CreateAccountLoginView();
            account         = new AccountView();

            controller     = Substitute.ForPartsOf <AuthController>(service, validator);
            controller.Url = new UrlHelper(new HttpMock().HttpContext.Request.RequestContext);
            controller.ControllerContext = new ControllerContext();
        }
コード例 #6
0
        public void CanReset_AddsErorrMessageThenCanNotResetAccountWithExpiredToken()
        {
            Account account = context.Set <Account>().Single();

            account.RecoveryTokenExpirationDate = DateTime.Now.AddMinutes(-5);
            context.SaveChanges();

            validator.CanReset(ObjectFactory.CreateAccountResetView());

            String expected = Validations.RecoveryTokenExpired;
            String actual   = validator.Alerts.Single().Message;

            Assert.AreEqual(expected, actual);
        }
コード例 #7
0
        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 = ObjectFactory.CreateAccountRecoveryView();
            accountReset    = ObjectFactory.CreateAccountResetView();
            accountLogin    = ObjectFactory.CreateAccountLoginView();
        }
コード例 #8
0
        public void CanReset_AddsErorrMessageThenCanNotResetAccountWithExpiredToken()
        {
            Account account = context.Set <Account>().Single();

            account.RecoveryTokenExpirationDate = DateTime.Now.AddMinutes(-5);
            context.SaveChanges();

            validator.CanReset(ObjectFactory.CreateAccountResetView());

            Alert actual = validator.Alerts.Single();

            Assert.Equal(Validations.RecoveryTokenExpired, actual.Message);
            Assert.Equal(AlertType.Danger, actual.Type);
            Assert.Equal(0, actual.FadeoutAfter);
        }
コード例 #9
0
        public AuthControllerTests()
        {
            mailClient = Substitute.For <IMailClient>();
            service    = Substitute.For <IAccountService>();
            validator  = Substitute.For <IAccountValidator>();
            controller = Substitute.ForPartsOf <AuthController>(validator, service, mailClient);
            HttpContextBase context = HttpContextFactory.CreateHttpContextBase();

            controller.Url = new UrlHelper(context.Request.RequestContext);
            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = context;

            accountRecovery = ObjectFactory.CreateAccountRecoveryView();
            accountReset    = ObjectFactory.CreateAccountResetView();
            accountLogin    = ObjectFactory.CreateAccountLoginView();
        }
コード例 #10
0
        public void Reset_ResetsAccount()
        {
            AccountResetView accountReset = ObjectFactory.CreateAccountResetView();
            Account          expected     = context.Set <Account>().AsNoTracking().Single();

            hasher.HashPassword(accountReset.NewPassword).Returns("Reset");

            service.Reset(accountReset);

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

            expected.RecoveryTokenExpirationDate = null;
            expected.RecoveryToken = null;
            expected.Passhash      = "Reset";

            TestHelper.PropertyWiseEqual(expected, actual);
        }
コード例 #11
0
 public void CanReset_ValidAccount()
 {
     Assert.True(validator.CanReset(ObjectFactory.CreateAccountResetView()));
     Assert.Empty(validator.ModelState);
     Assert.Empty(validator.Alerts);
 }
コード例 #12
0
        public void CanReset_InvalidState_ReturnsFalse()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanReset(ObjectFactory.CreateAccountResetView()));
        }
コード例 #13
0
        public void CanReset_CanNotResetAccountWithInvalidModelState()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanReset(ObjectFactory.CreateAccountResetView()));
        }