示例#1
0
        public void Edit_Account()
        {
            AccountEditView view = ObjectFactory.CreateAccountEditView(account.Id);

            account       = context.Set <Account>().AsNoTracking().Single();
            view.IsLocked = account.IsLocked = !account.IsLocked;
            view.Username = account.Username + "Test";
            view.RoleId   = account.RoleId = null;
            view.Email    = account.Email + "s";

            service.Edit(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.Username, actual.Username);
            Assert.Equal(expected.Passhash, actual.Passhash);
            Assert.Equal(expected.RoleId, actual.RoleId);
            Assert.Equal(expected.Email, actual.Email);
            Assert.Equal(expected.Id, actual.Id);
        }
示例#2
0
        public void CanEdit_Account_ToSameEmail()
        {
            AccountEditView view = ObjectFactory.CreateAccountEditView(account.Id);

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

            Assert.True(validator.CanEdit(view));
        }
        public void Edit_RefreshesAuthorizationProvider()
        {
            AccountEditView account = ObjectFactory.CreateAccountEditView();

            service.Edit(account);

            Authorization.Provider.Received().Refresh();
        }
示例#4
0
        public void Edit_RefreshesAuthorization()
        {
            AccountEditView view = ObjectFactory.CreateAccountEditView();

            service.Edit(view);

            authorizationProvider.Received().Refresh();
        }
示例#5
0
        public void Edit_RefreshesAuthorization()
        {
            AccountEditView view = ObjectFactory.CreateAccountEditView(account.Id);

            view.RoleId = account.RoleId;

            service.Edit(view);

            Authorization.Provider.Received().Refresh();
        }
示例#6
0
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.CreateAccountView();

            controller = Substitute.ForPartsOf <AccountsController>(validator, service);
            controller.ActionContext.RouteData = new RouteData();
        }
示例#7
0
        public void MapAccounts_MapsAccountEditViewToAccount()
        {
            AccountEditView view = ObjectFactory.CreateAccountEditView();

            Account         actual   = Mapper.Map <AccountEditView, Account>(view);
            AccountEditView expected = view;

            Assert.AreEqual(expected.EntityDate, actual.EntityDate);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.AreEqual(expected.RoleId, actual.RoleId);
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.IsNull(actual.Passhash);
            Assert.IsNull(actual.Role);
        }
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.CreateAccountView();

            controller = Substitute.ForPartsOf <AccountsController>(validator, service);
            controller.ControllerContext.HttpContext = Substitute.For <HttpContext>();
            controller.TempData = Substitute.For <ITempDataDictionary>();
            controller.ControllerContext.RouteData = new RouteData();
            controller.Url = Substitute.For <IUrlHelper>();
        }
示例#9
0
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectFactory.CreateAccountCreateView();
            accountEdit   = ObjectFactory.CreateAccountEditView();
            account       = ObjectFactory.CreateAccountView();

            Authorization.Provider       = Substitute.For <IAuthorizationProvider>();
            controller                   = Substitute.ForPartsOf <AccountsController>(validator, service);
            controller.ControllerContext = new ControllerContext {
                RouteData = new RouteData()
            };
        }
示例#10
0
        public void CanEdit_Account_UsedEmail_ReturnsFalse()
        {
            Account usedAccount = ObjectFactory.CreateAccount(1);

            context.Set <Account>().Add(usedAccount);
            context.SaveChanges();

            AccountEditView view = ObjectFactory.CreateAccountEditView(account.Id);

            view.Email = usedAccount.Email;

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueEmail, validator.ModelState["Email"].Errors.Single().ErrorMessage);
        }
        public void CanEdit_Account_UsedUsername_ReturnsFalse()
        {
            Account takenAccount = ObjectFactory.CreateAccount(1);

            context.Set <Account>().Add(takenAccount);
            context.SaveChanges();

            AccountEditView view = ObjectFactory.CreateAccountEditView(account.Id);

            view.Username = takenAccount.Username.ToLower();

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validations.UniqueUsername, validator.ModelState["Username"].Errors.Single().ErrorMessage);
        }
示例#12
0
        public void Edit_EditsAccountsRoleOnly()
        {
            AccountEditView accountEdit = ObjectFactory.CreateAccountEditView();
            Account         account     = context.Set <Account>().AsNoTracking().Single();

            account.RoleId        = accountEdit.RoleId = null;
            accountEdit.Username += "Edition";

            service.Edit(accountEdit);

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

            Assert.AreEqual(expected.RecoveryTokenExpirationDate, actual.RecoveryTokenExpirationDate);
            Assert.AreEqual(expected.RecoveryToken, actual.RecoveryToken);
            Assert.AreEqual(expected.CreationDate, actual.CreationDate);
            Assert.AreEqual(expected.Username, actual.Username);
            Assert.AreEqual(expected.Passhash, actual.Passhash);
            Assert.AreEqual(expected.RoleId, actual.RoleId);
            Assert.AreEqual(expected.Email, actual.Email);
            Assert.AreEqual(expected.Id, actual.Id);
        }
示例#13
0
 public void CanEdit_ValidAccount()
 {
     Assert.True(validator.CanEdit(ObjectFactory.CreateAccountEditView(account.Id)));
     Assert.Empty(validator.ModelState);
     Assert.Empty(validator.Alerts);
 }
示例#14
0
        public void CanEdit_Account_InvalidState_ReturnsFalse()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanEdit(ObjectFactory.CreateAccountEditView(account.Id)));
        }
示例#15
0
 public void CanEdit_ValidAccount()
 {
     Assert.True(validator.CanEdit(ObjectFactory.CreateAccountEditView()));
 }
示例#16
0
        public void CanEdit_CanNotEditAccountWithInvalidModelState()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanEdit(ObjectFactory.CreateAccountEditView()));
        }