public bool Update(AdminUserModelDAL adminUser) { try { using (var DBConnection = new DB(false)) { var adminUserFound = DBConnection.AdminUsers.Find(adminUser.Username); if (adminUserFound == null) { Loggings.GeneralLog("Could not find Admin User: "******"Updated credentials for Admin User: "******"Exception", Created_By = "System", LogMessage = ex.ToString(), Created_date = DateTime.Now }; Loggings.LogToBoth(logg); return(false); } }
public void GetAll_WhenTwoExistingUsers_ExpectedResultAreEqual() { //Arrange var DALStub = new AdminUserDALStub(); var defaultAdminUser = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234") }; var newAdminUser = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("newadmin") }; bool successfullCreate = DALStub.Create(newAdminUser); var expectedResult = new List <AdminUserModelDAL>(); expectedResult.Add(defaultAdminUser); expectedResult.Add(newAdminUser); //Act var result = DALStub.GetAll(); //Assert Assert.IsTrue(expectedResult.Count == result.Count); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(expectedResult[i].Username, result[i].Username); } }
public void Delete_WhenTwoExistingUsers_ExpectedResultCount1() { //Arrange var DALStub = new AdminUserDALStub(); var defaultAdminUser = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234") }; var adminUserToDelete = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("torspassword") }; bool successfullCreate = DALStub.Create(adminUserToDelete); var expectedResult = new List <AdminUserModelDAL>(); expectedResult.Add(defaultAdminUser); //Act bool successfullDelete = DALStub.Delete("tor"); var result = DALStub.GetAll(); //Assert Assert.IsTrue(successfullCreate); // Here to make sure the test doesnt pass from it's target not existing Assert.IsTrue(successfullDelete); // Test to se if Delete() is executed Assert.IsTrue(result.Count == 1); // Test to se if Count is back to one for (int i = 0; i < result.Count; i++) // Test to se if correct user has been deleted by comparing to expectations { Assert.AreEqual(expectedResult[i].Username, result[i].Username); } }
public bool Create(AdminUserModelDAL adminuser) { try { using (var DBConnection = new DB()) { DBConnection.AdminUsers.Add(adminuser); DBConnection.SaveChanges(); Loggings.GeneralLog("Created Admin User: "******"Exception", Created_By = "System", LogMessage = ex.ToString(), Created_date = DateTime.Now }; Loggings.LogToBoth(logg); return(false); } }
public bool CheckLoginCredentials(AdminUserModelDAL userInput) { using (var db = new DB(false)) { var allAdminUsers = db.AdminUsers.ToList(); var foundAdminUser = db.AdminUsers.FirstOrDefault(b => b.Username.Equals(userInput.Username)); if (foundAdminUser == null) { Loggings.GeneralLog("No Admin User was found using the Username: "******"Admin User: "******" Used the correct login credecials"); return(true); } else { Loggings.GeneralLog("Admin User: "******" Used the incorrect login credecials"); return(false); } } }
public static AdminUserModelBLL MapFromAdminUsersDALToAdminUsersBLL(AdminUserModelDAL adminUserModelDAL) { var adminUserModelBLL = new AdminUserModelBLL() { UserName = adminUserModelDAL.Username }; return(adminUserModelBLL); }
public bool Create(AdminUserModelDAL adminuser) { if (adminuser.Username == "" || !adminuser.HashedPassword.Any()) { return(false); } _AdminUserDB.Add(adminuser); return(true); }
public bool CheckLoginCredentials(AdminUserModelBLL userInput) { var adminUserModelDAL = new AdminUserModelDAL() { Username = userInput.UserName, HashedPassword = PasswordHelperTool.PasswordSHA256Hasher(userInput.Password) }; return(_adminUserDAL.CheckLoginCredentials(adminUserModelDAL)); }
public bool RegisterAdminUser(AdminUserModelBLL userInput) { var adminUserModelDAL = new AdminUserModelDAL() { Username = userInput.UserName, HashedPassword = PasswordHelperTool.PasswordSHA256Hasher(userInput.Password) }; return(_adminUserDAL.Create(adminUserModelDAL)); }
//Summary: Update a customer public bool Update(AdminUserModelBLL adminModelBLL) { var adminModelDAL = new AdminUserModelDAL() { Username = adminModelBLL.UserName, HashedPassword = PasswordHelperTool.PasswordSHA256Hasher(adminModelBLL.Password) }; var result = _adminUserDAL.Update(adminModelDAL); return(result); }
public bool Update(AdminUserModelDAL adminUser) { var adminUserFound = _AdminUserDB.FirstOrDefault(b => b.Username.Equals(adminUser.Username)); if (adminUserFound == null) { return(false); } _AdminUserDB.Remove(adminUserFound); _AdminUserDB.Add(adminUser); return(true); }
public AdminUserDALStub() { _AdminUserDB = new List <AdminUserModelDAL>(); //Seed an admin user in "artificial" database var seed = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234") }; _AdminUserDB.Add(seed); }
public void CheckLoginCredentials_WhenWrongPassword_ExpectedResultFalse() { //Arrange var DALStub = new AdminUserDALStub(); var input = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("admin") }; //Act bool test = DALStub.CheckLoginCredentials(input); //Assert Assert.IsFalse(test); }
public void CheckLoginCredentials_WhenCorrectCombination_ExpectedResultTrue() { //Arrange var DALStub = new AdminUserDALStub(); var input = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234") }; //Act bool test = DALStub.CheckLoginCredentials(input); //Assert Assert.IsTrue(test); }
public void Update_WhenUserNotExists_ExpectedResultFalse() { //Arrange var DALStub = new AdminUserDALStub(); var input = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("newpassword") }; //Act bool test = DALStub.Update(input); //Assert Assert.IsFalse(test); }
public void Get_WhenOnExistingUser_ExpectedResultAreEqual() { //Arrange var DALStub = new AdminUserDALStub(); var initial = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234") }; //Act var result = DALStub.Get("admin"); //Assert Assert.AreEqual(initial.Username, result.Username); }
public void Create_WhenEmptyUsername_ExpectedResultFalse() { //Arrange var DALStub = new AdminUserDALStub(); var input = new AdminUserModelDAL { Username = "", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("password") }; //Act bool test = DALStub.Create(input); //Assert Assert.IsFalse(test); }
public bool CheckLoginCredentials(AdminUserModelDAL userInput) { var foundAdminUser = _AdminUserDB.Find(b => b.Username.Equals(userInput.Username)); if (foundAdminUser == null) { return(false); } if (foundAdminUser.HashedPassword.SequenceEqual(userInput.HashedPassword)) { return(true); } else { return(false); } }
public void Create_WhenAllOK_ExpectedResultTrueAreEqual() { //Arrange var DALStub = new AdminUserDALStub(); var input = new AdminUserModelDAL { Username = "******", HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("password") }; //Act bool test = DALStub.Create(input); var result = DALStub.Get("newadmin"); //Assert Assert.IsTrue(test); Assert.AreEqual(input, result); }