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_WhenOneUserExists_ExpectedResultCount0() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1 }; var DALStub = new CustomerDALStub(initialCustomers); //Act bool test1 = DALStub.Delete(user1.Email); var result = DALStub.GetAll(); //Assert Assert.IsTrue(test1); Assert.IsTrue(result.Count == 0); }
public void GetAll_WhenOneExistingUser_ExpectedResultAreEqual() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1 }; var expectedResult = new List <CustomerModelDAL> { user1 }; var DALStub = new CustomerDALStub(initialCustomers); //Act var result = DALStub.GetAll(); //Assert Assert.IsTrue(expectedResult.Count == result.Count); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(expectedResult[i].Email, result[i].Email); } }
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 void AuthenticateCustomerTest() { //Arrange var seedDB = new List <CustomerModelDAL>(); var seed = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("password"), FirstName = "First", LastName = "Last" }; seedDB.Add(seed); var controller = new CustomerUsersLogic(new CustomerDALStub(seedDB)); var rightInput1 = "*****@*****.**"; var rightInput2 = "password"; var wrongInput1 = ""; var wrongInput2 = ""; //Act var result1 = controller.AuthenticateCustomer(rightInput1, rightInput2); var result2 = controller.AuthenticateCustomer(wrongInput1, wrongInput2); //Assert Assert.IsTrue(result1 && !result2); }
public void Update_WhenUserNotExists_ExpectedResultFalse() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1 }; var DALStub = new CustomerDALStub(initialCustomers); var input = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newandbetterpassword"), FirstName = "Someones-Fistname", LastName = "New-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; //Act bool test = DALStub.Update(input); //Assert Assert.IsFalse(test); }
public void Create_WhenOtherUsersExisits_ExpectedResultTrueAreEqual() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword1"), FirstName = "number-one", LastName = "one", MovieRentals = new List <MovieOrderModelDAL>() }; var user2 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword2"), FirstName = "number-two", LastName = "two", MovieRentals = new List <MovieOrderModelDAL>() }; var user3 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword3"), FirstName = "number-three", LastName = "three", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1, user2, user3 }; var DALStub = new CustomerDALStub(initialCustomers); var input = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; var expectedResult = new List <CustomerModelDAL> { user1, user2, user3, input }; //Act bool test1 = DALStub.Create(input); var result = DALStub.GetAll(); //Assert Assert.IsTrue(test1); Assert.IsTrue(expectedResult.Count == result.Count); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(expectedResult[i].Email, result[i].Email); } }
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 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 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 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 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 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 GetAll_WhenMultipleExistingUsers_ExpectedResultAreEqual() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword1"), FirstName = "number-one", LastName = "one", MovieRentals = new List <MovieOrderModelDAL>() }; var user2 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword2"), FirstName = "number-two", LastName = "two", MovieRentals = new List <MovieOrderModelDAL>() }; var user3 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword3"), FirstName = "number-three", LastName = "three", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1, user2, user3 }; var expectedResult = new List <CustomerModelDAL> { user1, user2, user3 }; var DALStub = new CustomerDALStub(initialCustomers); //Act var result = DALStub.GetAll(); //Assert Assert.IsTrue(expectedResult.Count == result.Count); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(expectedResult[i].Email, result[i].Email); } }
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); }
public void Create_WhenEmptyEmail_ExpectedResultFalse() { //Arrange var DALStub = new CustomerDALStub(); var input = new CustomerModelDAL { Email = "", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; //Act bool test = DALStub.Create(input); //Assert Assert.IsFalse(test); }
//Summary: Create a customer public bool Create(CustomerModelBLL customerModelBLL) { var customerModelDAL = new CustomerModelDAL() { Email = customerModelBLL.Email, Password = PasswordHelperTool.PasswordSHA256Hasher(customerModelBLL.Password), FirstName = customerModelBLL.FirstName, LastName = customerModelBLL.LastName }; if (customerModelBLL.MovieRentals != null) { customerModelDAL.MovieRentals = ModelMapper.MapFromMovieOrderModelBLLToMovieOrderModelDAL(customerModelBLL.MovieRentals); } var result = CustomerDAL.Create(customerModelDAL); return(result); }
public void Update_WhenUpdatingMovieOrders_ExpectedResultTrueAreEqual() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1 }; var DALStub = new CustomerDALStub(initialCustomers); var newMovieOrder = new MovieOrderModelDAL { RentedMovieId = 1, RentalStartTimeStamp = DateTime.Now.ToString(), Email = user1.Email }; var newMovieRenatlList = new List <MovieOrderModelDAL> { newMovieOrder }; var input = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = newMovieRenatlList }; //Act bool test1 = DALStub.Update(input); var result = DALStub.Get(user1.Email); //Assert Assert.IsTrue(test1); Assert.AreEqual(input, result); }
public void Create_WhenNoExistingUsers_ExpectedResultTrueAreEqual() { //Arrange var DALStub = new CustomerDALStub(); var input = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; //Act bool test1 = DALStub.Create(input); var result = DALStub.Get(input.Email); //Assert Assert.IsTrue(test1); Assert.AreEqual(input, result); }
public static CustomerModelDAL MapFromCustomerModelBLLToCustomerModelDAL(CustomerModelBLL customerModelBLL) { var customerModelDAL = new CustomerModelDAL() { Email = customerModelBLL.Email, FirstName = customerModelBLL.FirstName, LastName = customerModelBLL.LastName }; if (customerModelBLL.Password != null) { customerModelDAL.Password = PasswordHelperTool.PasswordSHA256Hasher(customerModelBLL.Password); } if (customerModelDAL.MovieRentals != null) { customerModelDAL.MovieRentals = MapFromMovieOrderModelBLLToMovieOrderModelDAL(customerModelBLL.MovieRentals); } return(customerModelDAL); }
public void GetAllTest() { //Arrange var seedDB = new List <CustomerModelDAL>(); var seed = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("password"), FirstName = "First", LastName = "Last" }; seedDB.Add(seed); var controller = new CustomerUsersLogic(new CustomerDALStub(seedDB)); //Act var result = controller.GetAll(); //Assert Assert.IsNotNull(result); //Double check }
public void Get_WhenMultipleUsersExist_ExpectedResultAreEqual() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword1"), FirstName = "number-one", LastName = "one", MovieRentals = new List <MovieOrderModelDAL>() }; var user2 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword2"), FirstName = "number-two", LastName = "two", MovieRentals = new List <MovieOrderModelDAL>() }; var user3 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword3"), FirstName = "number-three", LastName = "three", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1, user2, user3 }; var expectedResult = user2; var DALStub = new CustomerDALStub(initialCustomers); //Act var result = DALStub.Get(user2.Email); //Assert Assert.AreEqual(expectedResult, result); }
public void UpdateTest() { var seedDB = new List <CustomerModelDAL>(); var seed = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("password"), FirstName = "First", LastName = "Last" }; seedDB.Add(seed); //Arrange var controller = new CustomerUsersLogic(new CustomerDALStub(seedDB)); var rightInput = new CustomerModelBLL { Email = "*****@*****.**", Password = "******", FirstName = "First", LastName = "Last", MovieRentals = null }; var wrongInput = new CustomerModelBLL { Email = "", Password = "", FirstName = "", LastName = "", MovieRentals = null }; //Act var result1 = controller.Create(rightInput); var result2 = controller.Create(wrongInput); //Assert Assert.IsTrue(result1 && !result2); }
public void Get_WhenTargetNotExists_ExpectedResultNull() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1 }; var DALStub = new CustomerDALStub(initialCustomers); //Arrange var result = DALStub.Get("*****@*****.**"); //Assert Assert.IsNull(result); }
public void Get_WhenOneUserExists_ExpectedResultAreEqual() { //Arrange var user1 = new CustomerModelDAL { Email = "*****@*****.**", Password = PasswordHelperTool.PasswordSHA256Hasher("newbypassword"), FirstName = "Someones-Fistname", LastName = "Someones-Lastname", MovieRentals = new List <MovieOrderModelDAL>() }; var initialCustomers = new List <CustomerModelDAL> { user1 }; var expectedResult = user1; var DALStub = new CustomerDALStub(initialCustomers); //Arrange var result = DALStub.Get(user1.Email); //Assert Assert.AreEqual(expectedResult, result); }
public bool AuthenticateCustomer(string userName, string password) { return(CustomerDAL.FindCustomerMatchingCredentials(userName, PasswordHelperTool.PasswordSHA256Hasher(password))); }