示例#1
0
        public void CanEdit_Account_InvalidState_ReturnsFalse()
        {
            validator.ModelState.AddModelError("Test", "Test");

            Assert.False(validator.CanEdit(ObjectsFactory.CreateAccountEditView(account.Id + 1)));
            Assert.Single(validator.ModelState);
        }
        public void CanEdit_Account_ToSameEmail()
        {
            AccountEditView view = ObjectsFactory.CreateAccountEditView(account.Id);

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

            Assert.True(validator.CanEdit(view));
        }
示例#3
0
        public void CanEdit_Account_ToSameUsername()
        {
            AccountEditView view = ObjectsFactory.CreateAccountEditView();

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

            Assert.True(validator.CanEdit(view));
        }
示例#4
0
        public void CanEdit_Account_UsedEmail_ReturnsFalse()
        {
            AccountEditView view = ObjectsFactory.CreateAccountEditView(2);

            view.Email = account.Email;

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validation.For <AccountView>("UniqueEmail"), validator.ModelState[nameof(AccountEditView.Email)].Errors.Single().ErrorMessage);
        }
示例#5
0
        public void CanEdit_Account_UsedUsername_ReturnsFalse()
        {
            AccountEditView view = ObjectsFactory.CreateAccountEditView(account.Id + 1);

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

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validation.For <AccountView>("UniqueUsername"), validator.ModelState[nameof(AccountEditView.Username)].Errors.Single().ErrorMessage);
        }
示例#6
0
        public AccountsTests()
        {
            service       = Substitute.For <IAccountService>();
            account       = ObjectsFactory.CreateAccountView(0);
            validator     = Substitute.For <IAccountValidator>();
            accountEdit   = ObjectsFactory.CreateAccountEditView(0);
            accountCreate = ObjectsFactory.CreateAccountCreateView(0);
            controller    = Substitute.ForPartsOf <Accounts>(validator, service);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            controller.Authorization.Returns(Substitute.For <IAuthorization>());
            controller.ControllerContext.RouteData = new RouteData();
        }
示例#7
0
        public AccountsControllerTests()
        {
            validator = Substitute.For <IAccountValidator>();
            service   = Substitute.For <IAccountService>();

            accountCreate = ObjectsFactory.CreateAccountCreateView();
            accountEdit   = ObjectsFactory.CreateAccountEditView();
            account       = ObjectsFactory.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>();
        }
示例#8
0
        public void CanEdit_Account_UsedEmail_ReturnsFalse()
        {
            Account usedAccount = ObjectsFactory.CreateAccount(1);

            context.Add(usedAccount);
            context.SaveChanges();

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

            view.Email = usedAccount.Email;

            Boolean canEdit = validator.CanEdit(view);

            Assert.False(canEdit);
            Assert.Single(validator.ModelState);
            Assert.Equal(Validation.For <AccountView>("UniqueEmail"), validator.ModelState["Email"].Errors.Single().ErrorMessage);
        }
        public void Edit_Account()
        {
            AccountEditView view = ObjectsFactory.CreateAccountEditView();

            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);
        }
 public void CanEdit_ValidAccount()
 {
     Assert.True(validator.CanEdit(ObjectsFactory.CreateAccountEditView(account.Id)));
     Assert.Empty(validator.ModelState);
     Assert.Empty(validator.Alerts);
 }