public void CanEdit_CanNotEditToAlreadyUsedEmail() { Account takenEmailAccount = ObjectFactory.CreateAccount(2); context.Set <Account>().Add(takenEmailAccount); context.SaveChanges(); ProfileEditView profile = ObjectFactory.CreateProfileEditView(); profile.Email = takenEmailAccount.Email; Assert.IsFalse(validator.CanEdit(profile)); }
public ProfileTests() { service = Substitute.For <IAccountService>(); validator = Substitute.For <IAccountValidator>(); profileEdit = ObjectsFactory.CreateProfileEditView(0); profileDelete = ObjectsFactory.CreateProfileDeleteView(0); controller = Substitute.ForPartsOf <Profile>(validator, service); controller.ControllerContext.HttpContext = new DefaultHttpContext(); controller.Authorization.Returns(Substitute.For <IAuthorization>()); controller.ControllerContext.RouteData = new RouteData(); controller.CurrentAccountId.Returns(1); }
public void MapAccounts_MapsProfileEditViewToAccount() { ProfileEditView expected = ObjectFactory.CreateProfileEditView(); Account actual = Mapper.Map <ProfileEditView, Account>(expected); Assert.AreEqual(expected.EntityDate, actual.EntityDate); Assert.AreEqual(expected.Username, actual.Username); Assert.AreEqual(expected.Email, actual.Email); Assert.AreEqual(expected.Id, actual.Id); Assert.IsNull(actual.Passhash); Assert.IsNull(actual.RoleId); Assert.IsNull(actual.Role); }
public void CanEdit_CanNotEditToAlreadyTakenUsername() { Account takenAccount = ObjectFactory.CreateAccount(2); context.Set <Account>().Add(takenAccount); context.SaveChanges(); ProfileEditView view = ObjectFactory.CreateProfileEditView(); view.Username = takenAccount.Username; Assert.False(validator.CanEdit(view)); }
public void Edit_NullOrEmptyNewPassword_DoesNotEditPassword(String newPassword) { ProfileEditView view = ObjectFactory.CreateProfileEditView(); view.NewPassword = newPassword; service.Edit(view); String actual = context.Set <Account>().AsNoTracking().Single().Passhash; String expected = account.Passhash; Assert.Equal(expected, actual); }
public void CanEdit_Profile_IncorrectPassword_ReturnsFalse() { ProfileEditView view = ObjectsFactory.CreateProfileEditView(account.Id + 1); hasher.VerifyPassword(view.Password, Arg.Any <String>()).Returns(false); Boolean canEdit = validator.CanEdit(view); Assert.False(canEdit); Assert.Empty(validator.Alerts); Assert.Single(validator.ModelState); Assert.Equal(Validation.For <AccountView>("IncorrectPassword"), validator.ModelState[nameof(ProfileEditView.Password)].Errors.Single().ErrorMessage); }
public void CanEdit_CanNotEditToAlreadyUsedEmail() { Account usedEmailAccount = ObjectFactory.CreateAccount(2); context.Set <Account>().Add(usedEmailAccount); context.SaveChanges(); ProfileEditView view = ObjectFactory.CreateProfileEditView(); view.Email = usedEmailAccount.Email; Assert.False(validator.CanEdit(view)); }
public void Edit_OnNotSpecifiedNewPasswordDoesNotEditPassword(String newPassword) { String expected = context.Set <Account>().AsNoTracking().Single().Passhash; ProfileEditView profile = ObjectFactory.CreateProfileEditView(); profile.NewPassword = newPassword; service.Edit(profile); String actual = context.Set <Account>().AsNoTracking().Single().Passhash; Assert.AreEqual(expected, actual); }
public void SetUp() { account = new AccountView(); profileEdit = ObjectFactory.CreateProfileEditView("Edition"); profileDelete = ObjectFactory.CreateProfileDeleteView("Edition"); service = Substitute.For <IAccountService>(); validator = Substitute.For <IAccountValidator>(); controller = Substitute.ForPartsOf <ProfileController>(validator, service); controller.When(sub => { String get = sub.CurrentAccountId; }).DoNotCallBase(); controller.CurrentAccountId.Returns("CurrentAccount"); }
public void CanEdit_AddsErrorMessageThenCanNotEditWithIncorrectPassword() { ProfileEditView view = ObjectFactory.CreateProfileEditView(); hasher.VerifyPassword(view.Password, Arg.Any <String>()).Returns(false); validator.CanEdit(view); String expected = Validations.IncorrectPassword; String actual = validator.ModelState["Password"].Errors[0].ErrorMessage; Assert.Equal(expected, actual); }
public void Edit_LowersEmailValue() { ProfileEditView view = ObjectFactory.CreateProfileEditView(); String expected = view.Email.ToLower(); view.Email = view.Email.ToUpper(); service.Edit(view); Account model = context.Set <Account>().SingleOrDefault(); Assert.AreEqual(expected, model.Email); Assert.AreEqual(expected, view.Email); }
public void MapAccounts_MapsAccountToProfileEditView() { Account account = ObjectFactory.CreateAccount(); ProfileEditView actual = Mapper.Map <Account, ProfileEditView>(account); Account expected = account; Assert.AreEqual(expected.EntityDate, actual.EntityDate); Assert.AreEqual(expected.Username, actual.Username); Assert.AreEqual(expected.Email, actual.Email); Assert.AreEqual(expected.Id, actual.Id); Assert.IsNull(actual.NewPassword); Assert.IsNull(actual.Password); }
public ProfileControllerTests() { validator = Substitute.For <IAccountValidator>(); service = Substitute.For <IAccountService>(); profileDelete = ObjectsFactory.CreateProfileDeleteView(); profileEdit = ObjectsFactory.CreateProfileEditView(); controller = Substitute.ForPartsOf <ProfileController>(validator, service); controller.ControllerContext.HttpContext = Substitute.For <HttpContext>(); controller.TempData = Substitute.For <ITempDataDictionary>(); controller.ControllerContext.RouteData = new RouteData(); controller.Url = Substitute.For <IUrlHelper>(); ReturnCurrentAccountId(controller, 1); }
public ActionResult Edit(ProfileEditView profile) { if (!Service.AccountExists(CurrentAccountId)) { return(LogOut()); } if (Validator.CanEdit(profile)) { Service.Edit(profile); Alerts.Add(AlertTypes.Success, Messages.ProfileUpdated); } return(View(profile)); }
public void CanEdit_AddsErrorMessageThenCanNotEditToAlreadyTakenUsername() { Account takenAccount = ObjectFactory.CreateAccount("2"); context.Set <Account>().Add(takenAccount); context.SaveChanges(); ProfileEditView profile = ObjectFactory.CreateProfileEditView(); profile.Username = takenAccount.Username; validator.CanEdit(profile); String actual = validator.ModelState["Username"].Errors[0].ErrorMessage; String expected = Validations.UsernameIsAlreadyTaken; Assert.AreEqual(expected, actual); }
public void CanEdit_Profile_UsedEmail_ReturnsFalse() { Account usedAccount = ObjectsFactory.CreateAccount(account.Id + 1); context.Add(usedAccount); context.SaveChanges(); ProfileEditView view = ObjectsFactory.CreateProfileEditView(0); view.Email = usedAccount.Email; Boolean canEdit = validator.CanEdit(view); Assert.False(canEdit); Assert.Single(validator.ModelState); Assert.Equal(Validation.For <AccountView>("UniqueEmail"), validator.ModelState[nameof(ProfileEditView.Email)].Errors.Single().ErrorMessage); }
public void CanEdit_Profile_UsedUsername_ReturnsFalse() { Account usedAccount = ObjectsFactory.CreateAccount(2); context.Add(usedAccount); context.SaveChanges(); ProfileEditView view = ObjectsFactory.CreateProfileEditView(); view.Username = usedAccount.Username.ToLower(); Boolean canEdit = validator.CanEdit(view); Assert.False(canEdit); Assert.Single(validator.ModelState); Assert.Equal(Validation.For <AccountView>("UniqueUsername"), validator.ModelState[nameof(ProfileEditView.Username)].Errors.Single().ErrorMessage); }
public void CanEdit_AddsErorrMessageThenCanNotEditToAlreadyUsedEmail() { Account takenEmailAccount = ObjectFactory.CreateAccount(2); context.Set <Account>().Add(takenEmailAccount); context.SaveChanges(); ProfileEditView profile = ObjectFactory.CreateProfileEditView(); profile.Email = takenEmailAccount.Email; validator.CanEdit(profile); String actual = validator.ModelState["Email"].Errors[0].ErrorMessage; String expected = Validations.EmailIsAlreadyUsed; Assert.AreEqual(expected, actual); }
public void CanEdit_UsedUsername_ReturnsFalse() { Account takenAccount = ObjectFactory.CreateAccount(2); context.Set <Account>().Add(takenAccount); context.SaveChanges(); ProfileEditView view = ObjectFactory.CreateProfileEditView(); 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); }
public ActionResult Edit([Bind(Exclude = "Id")] ProfileEditView profile) { if (!Service.IsActive(CurrentAccountId)) { return(RedirectIfAuthorized("Logout", "Auth")); } if (!Validator.CanEdit(profile)) { return(View(profile)); } Service.Edit(profile); Alerts.AddSuccess(Messages.ProfileUpdated, 4000); return(RedirectIfAuthorized("Edit")); }
public ActionResult Edit([BindExcludeId] ProfileEditView profile) { if (!Service.IsActive(CurrentAccountId)) { return(RedirectToAction("Logout", "Auth")); } if (!Validator.CanEdit(profile)) { return(View(profile)); } Service.Edit(profile); Alerts.Add(AlertType.Success, Messages.ProfileUpdated); return(RedirectToAction("Edit")); }
public void Edit_EditsProfile() { ProfileEditView profile = ObjectFactory.CreateProfileEditView(); Account expected = context.Set <Account>().SingleOrDefault(); profile.Email = "*****@*****.**"; profile.Username += "1"; service.Edit(profile); Account actual = context.Set <Account>().SingleOrDefault(); Assert.AreEqual(expected.RecoveryTokenExpirationDate, actual.RecoveryTokenExpirationDate); Assert.AreEqual(hasher.HashPassword(profile.NewPassword), actual.Passhash); Assert.AreEqual(expected.RecoveryToken, actual.RecoveryToken); Assert.AreEqual(expected.EntityDate, actual.EntityDate); Assert.AreEqual(expected.Username, actual.Username); Assert.AreEqual(expected.Email, actual.Email); }
public ActionResult Edit(ProfileEditView profile) { if (!Service.IsActive(CurrentAccountId)) { return(RedirectToAction("Logout", "Auth")); } if (!Validator.CanEdit(profile)) { return(View(profile)); } Service.Edit(User, profile); Alerts.AddSuccess(Message.For <AccountView>("ProfileUpdated"), 4000); return(RedirectToAction("Edit")); }
public ActionResult Edit([Bind(Exclude = "Id")] ProfileEditView profile) { if (!Service.IsActive(CurrentAccountId)) { return(LogOut()); } profile.Id = CurrentAccountId; if (!Validator.CanEdit(profile)) { return(View(profile)); } Service.Edit(profile); Alerts.Add(AlertType.Success, Messages.ProfileUpdated); return(RedirectToAction("Edit")); }
public ActionResult Edit(ProfileEditView profile) { profile.Id = User.Id(); if (!Service.IsActive(profile.Id)) { return(RedirectToAction(nameof(Auth.Logout), nameof(Auth))); } if (!Validator.CanEdit(profile)) { return(View(profile)); } Service.Edit(User, profile); Alerts.AddSuccess(Message.For <AccountView>("ProfileUpdated"), 4000); return(RedirectToAction(nameof(Edit))); }