diff --git a/FitFusion/FitFusionTest/MockDAO/MockOrderDAO.cs b/FitFusion/FitFusionTest/MockDAO/MockOrderDAO.cs index 173e56e..8a3097b 100644 --- a/FitFusion/FitFusionTest/MockDAO/MockOrderDAO.cs +++ b/FitFusion/FitFusionTest/MockDAO/MockOrderDAO.cs @@ -20,9 +20,9 @@ public MockOrderDAO() { var users = new List { - new Customer { Id = 1, FirstName = "Alice", LastName = "Johnson", Address="Sofia", NutriPoints = 60 }, - new Customer { Id = 2, FirstName = "Bob", LastName = "Smith", NutriPoints = 15 }, - new Customer { Id = 3, FirstName = "John", LastName = "Doe", NutriPoints = 100 } + new Customer ( id: 1, firstName: "Alice", lastName: "Johnson", email: "alicejohnson@email.com", passwordHash: "hash", passwordSalt: "salt", address: "Sofia", nutriPoints: 60), + new Customer ( id: 2, firstName: "Bob", lastName: "Smith", email: "bobsmith@email.com", passwordHash: "hash", passwordSalt: "salt", address: "USA", nutriPoints: 15), + new Customer ( id: 3, firstName: "John", lastName: "Doe", email: "johndoe@email.com", passwordHash: "hash", passwordSalt: "salt", address: "England", nutriPoints: 100) }; var products = new List @@ -71,13 +71,16 @@ public MockOrderDAO() } - public bool CreateOrder(Order order) - { - orders.Add(order); - order.Customer.NutriPoints += order.Cart.NutriPointsReward; - order.Customer.NutriPoints -= order.Cart.NutriPointsNeeded; - return true; - } + //public bool CreateOrder(Order order) + //{ + // orders.Add(order); + // order.Customer = new Customer(); + + // order.Customer.NutriPoints += order.Cart.NutriPointsReward; + // order.Customer.NutriPoints -= order.Cart.NutriPointsNeeded; + + // return order; + //} public ShoppingCart GetShoppingCart(int id) { @@ -118,6 +121,20 @@ public Dictionary> GetRecommendations(int cus { throw new NotImplementedException(); } - + + public bool CreateOrder(Order order) + { + throw new NotImplementedException(); + } + + public ProductModel GetMerchantRecommendation(int customerId) + { + throw new NotImplementedException(); + } + + public bool CreateMerchantRecommendation(int customerId, ProductModel newProduct) + { + throw new NotImplementedException(); + } } } diff --git a/FitFusion/FitFusionTest/MockDAO/MockUserDAO.cs b/FitFusion/FitFusionTest/MockDAO/MockUserDAO.cs index 929188a..fed2771 100644 --- a/FitFusion/FitFusionTest/MockDAO/MockUserDAO.cs +++ b/FitFusion/FitFusionTest/MockDAO/MockUserDAO.cs @@ -94,33 +94,19 @@ public bool UpdateUser(User user) { if (DoesEmailExists(user.Email)) { - User existingUser = users.FirstOrDefault(u => u.Email == user.Email)!; - - existingUser.FirstName = user.FirstName; - existingUser.LastName = user.LastName; - existingUser.Email = user.Email; - existingUser.PasswordHash = user.PasswordHash; - existingUser.PasswordSalt = user.PasswordSalt; - - if (user is Staff) - { - ((Staff)existingUser).Phone = ((Staff)user).Phone; - } - else if (user is Owner) - { - ((Owner)existingUser).Phone = ((Owner)user).Phone; - } - else if (user is Customer) - { - ((Customer)existingUser).NutriPoints = ((Customer)user).NutriPoints; - } + User existingUser = users.FirstOrDefault(u => u.Id == user.Id)!; + + users.Remove(existingUser); + users.Add(user); + + return true; } else { throw new NullReferenceException("User doesn't exist."); } - return true; + //TODO check } public bool DeleteUser(User user) diff --git a/FitFusion/FitFusionTest/ProductManagerTest.cs b/FitFusion/FitFusionTest/ProductManagerTest.cs index 2d6460e..9f3d302 100644 --- a/FitFusion/FitFusionTest/ProductManagerTest.cs +++ b/FitFusion/FitFusionTest/ProductManagerTest.cs @@ -109,7 +109,7 @@ public void DeleteProduct_ExistingProduct_ShouldRemoveProduct() public void FilterByCategory_ShouldReturnFilteredProducts() { List products = _manager.GetProducts(); - List firstSort = _manager.Sort(products, param: "titleAsc"); + List firstSort = _manager.Sort(products, new TitleAscSortStrategy()); List products2 = _manager.GetProducts(); } diff --git a/FitFusion/FitFusionTest/UserManagerTest.cs b/FitFusion/FitFusionTest/UserManagerTest.cs index 6caf160..3e0bb4a 100644 --- a/FitFusion/FitFusionTest/UserManagerTest.cs +++ b/FitFusion/FitFusionTest/UserManagerTest.cs @@ -3,6 +3,7 @@ using Models.User.Enums; using NUnit.Framework; using Services; +using Services.Sort; using System.Data; namespace FitFusionTest @@ -23,28 +24,30 @@ public void SetUp() public void CreateUser_DuplicateEmail_ShouldThrowDuplicateNameException() { var existingUser = new Owner - { - FirstName = "Peter", - LastName = "Parker", - Email = "peterparker@email.com", - PasswordHash = "peterparker@email.com", - PasswordSalt = "salt", - Address = "USA", - Phone = "1234567890", - }; + ( + id: 24, + firstName: "Peter", + lastName: "Parker", + email: "peterparker@email.com", + passwordHash: "peterparker@email.com", + passwordSalt: "salt", + address: "USA", + phone: "1234567890" + ); _dao.CreateUser(existingUser); var newUser = new Customer - { - FirstName = "Peter", - LastName = "Parker", - Email = "peterparker@email.com", - PasswordHash = "peterparker@email.com", - PasswordSalt = "salt", - Address = "USA", - NutriPoints = 0 - }; + ( + id: 24, + firstName: "Peter", + lastName: "Parker", + email: "peterparker@email.com", + passwordHash: "peterparker@email.com", + passwordSalt: "salt", + address: "USA", + nutriPoints: 0 + ); Assert.Throws(() => _manager.CreateUser(newUser)); } @@ -53,30 +56,30 @@ public void CreateUser_DuplicateEmail_ShouldThrowDuplicateNameException() public void UpdateUser_ExistingUser_ShouldUpdateUser() { var existingUser = new Customer - { - Id = 1, - FirstName = "Ivan", - LastName = "Ivanov", - Email = "ivanivanov@email.com", - PasswordHash = "ivanivanov@email.com", - PasswordSalt = "salt", - Address = "USA", - NutriPoints = 0 - }; + ( + id: 23, + firstName: "Ivan", + lastName: "Ivanov", + email: "ivanivanov@email.com", + passwordHash: "ivanivanov@email.com", + passwordSalt: "salt", + address: "USA", + nutriPoints: 0 + ); _dao.CreateUser(existingUser); var updatedUser = new Customer - { - Id = 1, - FirstName = "Ivan", - LastName = "Parker", - Email = "ivanivanov@email.com", - PasswordHash = "ivanivanov@email.com", - PasswordSalt = "salt", - Address = "Bulgaria", - NutriPoints = 0 - }; + ( + id: 23, + firstName: "Ivan", + lastName: "Parker", + email: "ivanivanov@email.com", + passwordHash: "ivanivanov@email.com", + passwordSalt: "salt", + address: "Bulgaria", + nutriPoints: 0 + ); _manager.UpdateUser(updatedUser); @@ -93,16 +96,16 @@ public void UpdateUser_ExistingUser_ShouldUpdateUser() public void DeleteUser_ExistingUser_ShouldRemoveUser() { var existingUser = new Customer - { - Id = 1, - FirstName = "Doom", - LastName = "Doctor", - Email = "doctordoom@email.com", - PasswordHash = "doctordoom@email.com", - PasswordSalt = "salt", - Address = "USA", - NutriPoints = 0 - }; + ( + id: 1, + firstName: "Doom", + lastName: "Doctor", + email: "doctordoom@email.com", + passwordHash: "doctordoom@email.com", + passwordSalt: "salt", + address: "USA", + nutriPoints: 0 + ); _dao.CreateUser(existingUser); @@ -151,7 +154,7 @@ public void Sort_ShouldSortUsersByLastNameInDescendingOrder() List users = _manager.GetAllUsers(); List usersToCompare = users.OrderByDescending(x => x.LastName).ToList(); - List usersToCheck = _manager.Sort(users, SortParameter.LastNameDescending); + List usersToCheck = _manager.Sort(users, new LastNameDescending()); Assert.That(usersToCheck, Is.EqualTo(usersToCompare)); }