private void Insert_Click(object sender, RoutedEventArgs e) { AccountEditView.IsEnabled = true; AccountEditView.Visibility = Visibility.Visible; AccountEditView.Initialize(); EditHeight.Height = new GridLength(120); }
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); }
public void Edit(AccountEditView model) { try { var account = Read(a => a.ID == model.ID); if (!account.HasValue()) { ValidationDictionary.AddPropertyError <Account>(a => a.ID, "ID not found."); return; } if (ReadAll() .Any(x => (x.Email.Equals(model.Email, StringComparison.InvariantCultureIgnoreCase) || x.UserNo.Equals(model.UserNo, StringComparison.InvariantCultureIgnoreCase) ) && x.ID != model.ID)) { ValidationDictionary.AddPropertyError <AccountEditView>(a => a.Email, "Email Duplicated."); //.AddGeneralError("Email Duplicated"); } else { model.MapTo(account); db.Repository <Account2Dept>().Delete(a => a.AccountId == model.ID); Array.ForEach( model.DepartmentIDs.OrEmptyIfNull().Concat(model.BureauDepartmentIDs.OrEmptyIfNull()).ToArray() , a => account.Account2Dept.Add(new Account2Dept(a))); db.Repository <Account2Role>().Delete(a => a.Account_id == model.ID); Array.ForEach(model.RoleIDs.OrEmptyIfNull().ToArray() , a => account.Account2Role.Add(new Account2Role(a))); Save(); } } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Edit_RefreshesAuthorizationProvider() { AccountEditView account = ObjectFactory.CreateAccountEditView(); service.Edit(account); Authorization.Provider.Received().Refresh(); }
public void Edit_RefreshesAuthorizationProvider() { AccountEditView account = service.GetView <AccountEditView>(accountId); service.Edit(account); Authorization.Provider.Received().Refresh(); }
public void Edit_RefreshesAuthorization() { AccountEditView view = ObjectFactory.CreateAccountEditView(); service.Edit(view); authorizationProvider.Received().Refresh(); }
public Boolean CanEdit(AccountEditView view) { Boolean isValid = IsUniqueUsername(view.Id, view.Username); isValid &= IsUniqueEmail(view.Id, view.Email); isValid &= ModelState.IsValid; return isValid; }
public void CanEdit_Account_ToSameUsername() { AccountEditView view = ObjectFactory.CreateAccountEditView(account.Id); view.Username = account.Username.ToUpper(); Assert.True(validator.CanEdit(view)); }
public void CanEdit_Account_ToSameEmail() { AccountEditView view = ObjectsFactory.CreateAccountEditView(account.Id); view.Email = account.Email.ToUpper(); Assert.True(validator.CanEdit(view)); }
public void Edit(AccountEditView view) { Account account = UnitOfWork.Get <Account>(view.Id) !; account.IsLocked = view.IsLocked; account.RoleId = view.RoleId; UnitOfWork.Update(account); UnitOfWork.Commit(); }
public void Edit_RefreshesAuthorization() { AccountEditView view = ObjectFactory.CreateAccountEditView(account.Id); view.RoleId = account.RoleId; service.Edit(view); Authorization.Provider.Received().Refresh(); }
public ActionResult Edit(AccountEditView account) { if (!Validator.CanEdit(account)) { return(View(account)); } Service.Edit(account); return(RedirectIfAuthorized("Index")); }
public void Edit(AccountEditView view) { Account account = UnitOfWork.Repository <Account>().GetById(view.Id); account.RoleId = view.RoleId; UnitOfWork.Repository <Account>().Update(account); UnitOfWork.Commit(); Authorization.Provider.Refresh(); }
private void Update_Click(object sender, RoutedEventArgs e) { if (AccountTable.SelectedIndex >= 0) { Account Item = (dynamic)AccountTable.SelectedItem; AccountEditView.IsEnabled = true; AccountEditView.Visibility = Visibility.Visible; AccountEditView.Initialize(Item); EditHeight.Height = new GridLength(120); } }
public void SetUp() { validator = Substitute.For <IAccountValidator>(); service = Substitute.For <IAccountService>(); accountEdit = new AccountEditView(); account = new AccountView(); controller = Substitute.ForPartsOf <AccountsController>(service, validator); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.RouteData = new RouteData(); }
public void Edit(AccountEditView view) { Account account = UnitOfWork.Get <Account>(view.Id); account.IsLocked = view.IsLocked; account.RoleId = view.RoleId; UnitOfWork.Update(account); UnitOfWork.Commit(); Authorization.Provider.Refresh(); }
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(); }
public void Edit_DoesNotEditAccountsPassword() { String expected = context.Set <Account>().SingleOrDefault().Passhash; AccountEditView account = service.GetView <AccountEditView>(accountId); account.Username += "Edition"; service.Edit(account); String actual = context.Set <Account>().SingleOrDefault().Passhash; Assert.AreEqual(expected, actual); }
public ActionResult Edit(AccountEditView model) { if (ModelState.IsValid) { _accountService.Edit(model); if (ModelState.IsValid) { EditSuccessfully(); } } return(View(model)); }
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); }
public void IsSpecified_NullValue_ReturnsFalse() { AccountEditView view = new AccountEditView(); Boolean isSpecified = validator.BaseIsSpecified(view, account => account.RoleId); String message = String.Format(Validations.Required, ResourceProvider.GetPropertyTitle <AccountEditView, Int32?>(account => account.RoleId)); Assert.False(isSpecified); Assert.Empty(validator.Alerts); Assert.Single(validator.ModelState); Assert.Equal(message, validator.ModelState["RoleId"].Errors.Single().ErrorMessage); }
public void IsSpecified_NullValue_ReturnsFalse() { AccountEditView view = new AccountEditView(); Boolean isSpecified = validator.BaseIsSpecified(view, account => account.RoleId); String message = Validation.For("Required", Resource.ForProperty <AccountEditView, Int64?>(account => account.RoleId)); Assert.False(isSpecified); Assert.Empty(validator.Alerts); Assert.Single(validator.ModelState); Assert.Equal(message, validator.ModelState[nameof(AccountEditView.RoleId)].Errors.Single().ErrorMessage); }
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); }
public void Edit(AccountEditView view) { Account account = UnitOfWork.Get <Account>(view.Id); account.Email = view.Email.ToLower(); account.Username = view.Username; account.IsLocked = view.IsLocked; account.RoleId = view.RoleId; UnitOfWork.Update(account); UnitOfWork.Commit(); }
public void MapAccounts_MapsAccountToAccountEditView() { Account expected = ObjectFactory.CreateAccount(); AccountEditView actual = Mapper.Map <AccountEditView>(expected); Assert.Equal(expected.CreationDate, actual.CreationDate); Assert.Equal(expected.IsLocked, actual.IsLocked); Assert.Equal(expected.Username, actual.Username); Assert.Equal(expected.RoleId, actual.RoleId); Assert.Equal(expected.Email, actual.Email); Assert.Equal(expected.Id, actual.Id); }
public ActionResult Edit(AccountEditView account) { if (!Validator.CanEdit(account)) { return(View(account)); } Service.Edit(account); Authorization.Refresh(HttpContext.RequestServices); return(RedirectToAction(nameof(Index))); }
public AccountsControllerTests() { validator = Substitute.For <IAccountValidator>(); service = Substitute.For <IAccountService>(); accountCreate = new AccountCreateView(); accountEdit = new AccountEditView(); account = new AccountView(); controller = Substitute.ForPartsOf <AccountsController>(validator, service); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.RouteData = new RouteData(); }
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(); }
public ActionResult Edit(AccountEditView account) { if (!Validator.CanEdit(account)) { return(View(account)); } Service.Edit(account); Authorization?.Refresh(); return(RedirectToAction("Index")); }
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); }