public void ChangePasswordWithBlankDataTest() { this.tests = UserManagementTests.Update(); var model = new ChangePasswordModel { OldPassword = string.Empty, ConfirmPassword = "******", NewPassword = "******" }; var temp = new User { Username = "******", Email = "*****@*****.**", Password = "******" }; this.tests.ChangeCurrentUser("panza"); this.tests.Storage.CreateUser(temp); this.tests.ChangeCurrentUser("name"); try { this.tests.Storage.ChangePassword(model); } catch (Exception e) { this.tests.Storage.DeleteUser(u => u.Username == "name"); if (e.Message == "Old password can't be empty.") { Assert.Pass(); } Assert.Fail(); } this.tests.Storage.DeleteUser(u => u.Username == "name"); Assert.Fail(); }
public void ChangePasswordSuccess() { var model = new ChangePasswordModel {OldPassword = "******", ConfirmPassword = "******", NewPassword = "******"}; User temp = new User { Username = "******", Email = "*****@*****.**", Password = "******" }; _Tests.MockStorage.Setup(s => s.GetCurrentUser()).Returns(_Tests.Storage.GetUser(u => u.Username == "panza")); _Tests.Storage.CreateUser(temp); _Tests.MockStorage.Setup(s => s.GetCurrentUser()).Returns(_Tests.Storage.GetUser(u => u.Username == "ipepp")); _Tests.Storage.ChangePassword(model); Assert.AreEqual(_Tests.Storage.GetUser(u => u.Username == "ipepp").Password, _Tests.Storage.EncryptPassword("321")); }
public void ChangePasswordIncorrect() { var model = new ChangePasswordModel { OldPassword = "******", ConfirmPassword = "******", NewPassword = "******" }; User temp = new User { Username = "******", Email = "*****@*****.**", Password = "******" }; _Tests.MockStorage.Setup(s => s.GetCurrentUser()).Returns(_Tests.Storage.GetUser(u => u.Username == "panza")); _Tests.Storage.CreateUser(temp); _Tests.MockStorage.Setup(s => s.GetCurrentUser()).Returns(_Tests.Storage.GetUser(u => u.Username == "name")); _Tests.Storage.ChangePassword(model); Assert.AreEqual(_Tests.Storage.GetUser(u => u.Username == "name").Password, _Tests.Storage.EncryptPassword("321")); _Tests.Storage.DeleteUser(u => u.Username == "name"); }
public void ChangePasswordCorrect() { tests = UserManagementTests.Update(); var model = new ChangePasswordModel { OldPassword = "******", ConfirmPassword = "******", NewPassword = "******" }; var temp = new User { Username = "******", Email = "*****@*****.**", Password = "******" }; this.tests.ChangeCurrentUser("panza"); this.tests.Storage.CreateUser(temp); this.tests.ChangeCurrentUser("name"); this.tests.Storage.ChangePassword(model); Assert.AreEqual( this.tests.Storage.GetUser("name").Password, this.tests.Storage.EncryptPassword("321")); this.tests.Storage.DeleteUser(u => u.Username == "name"); }
public void ChangePasswordWithBlankDataTest() { this.tests = UserManagementTests.Update(); var model = new ChangePasswordModel { OldPassword = string.Empty, ConfirmPassword = "******", NewPassword = "******" }; var temp = new User { Username = "******", Email = "*****@*****.**", Password = "******" }; // Creating new user. this.tests.ChangeCurrentUser("panza"); this.tests.Storage.CreateUser(temp); this.tests.ChangeCurrentUser("name"); // Trying to change password with blank old passwird entered. this.tests.Storage.ChangePassword(model); // Deleting created user. this.tests.Storage.DeleteUser(u => u.Username == "name"); }
public ActionResult ChangePassword(ChangePasswordModel changePasswordModel) { if (changePasswordModel.OldPassword != _Storage.GetCurrentUser().Password) { ModelState.AddModelError("OldPassword", "Pasword is not correct"); } else if (changePasswordModel.NewPassword != changePasswordModel.ConfirmPassword) { ModelState.AddModelError("ConfirmPassword", "Paswords don't match"); } if (!ModelState.IsValid) { return View(); } _Storage.ChangePassword(changePasswordModel); return RedirectToAction("Index"); }
public void ChangePasswordWithBlankNewPassword() { this.tests = UserManagementTests.Update(); var model = new ChangePasswordModel { OldPassword = "******", ConfirmPassword = "******", NewPassword = string.Empty }; var temp = new User { Username = "******", Email = "*****@*****.**", Password = "******" }; this.tests.ChangeCurrentUser("panza"); this.tests.Storage.CreateUser(temp); this.tests.ChangeCurrentUser("name"); this.tests.Storage.ChangePassword(model); this.tests.Storage.DeleteUser(u => u.Username == "name"); }
public ActionResult ChangePassword(ChangePasswordModel changePasswordModel) { var oldPassword = this.storage.EncryptPassword(changePasswordModel.OldPassword); if (oldPassword != this.storage.GetCurrentUser().Password) { this.ModelState.AddModelError("OldPassword", "Pasword is not correct"); } else if (changePasswordModel.NewPassword != changePasswordModel.ConfirmPassword) { this.ModelState.AddModelError("ConfirmPassword", "Paswords don't match"); } if (!this.ModelState.IsValid) { return this.View(); } this.storage.ChangePassword(changePasswordModel); return this.RedirectToAction("Index"); }