public void Test9_Orders_Should_Update_LoyaltyPoints_When_Using_LoyaltyPoints() { /* * * 1) Create a new Loyalty Customer with 0 points and Add them * 2) Create a new Order and add the Loyalty Customer, a product and a payment * 3) Process the order * 4) Get the customer * 5) Create a new order * 6) Add a product which costs as much as their points balance * 7) Pay for the new order with points * 8) Get the customer and ensure their balance is now 0 * */ var loyaltyService = new LoyaltyService(new LoyaltyRepository(_testDbConnection)); IOrderService orderService = OrderService; var order = new Order(); var customer = new LoyaltyCustomer() { CustomerId = Guid.NewGuid(), EmailAddress = "*****@*****.**", FirstName = "Test", LastName = "Test", LifetimeLoyaltyPoints = 0, LoyaltyPointsBalance = 0, RewardStatus = RewardStatus.Silver }; loyaltyService.AddLoyaltyCustomer(customer); order.AddLoyaltyCustomerToOrder(customer); const decimal price = 1000m; // Buy a $1000 product in order to get $100 worth of points order.AddItemToOrder(new OrderItem(GetValidProduct(), ProductSize.Medium, price)); order.Payments.AddPayment(PaymentType.Cash, price); orderService.ProcessOrder(order); var updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId); order = new Order(); order.AddLoyaltyCustomerToOrder(updatedCustomer); order.AddItemToOrder(new OrderItem(GetValidProduct(), ProductSize.Medium, price / 10)); order.Payments.AddPayment(PaymentType.LoyaltyPoints, price / 10); orderService.ProcessOrder(order); updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId); Assert.Equal(0, updatedCustomer.LoyaltyPointsBalance); }
protected static LoyaltyCustomer GetValidLoyaltyCustomer() { var loyaltyCustomer = new LoyaltyCustomer() { CustomerId = Guid.NewGuid(), EmailAddress = "*****@*****.**", FirstName = "test", LastName = "test", RewardStatus = RewardStatus.Gold, LoyaltyPointsBalance = 1.0m, LifetimeLoyaltyPoints = 1.0m }; return(loyaltyCustomer); }
public void AddLoyaltyCustomer(LoyaltyCustomer customer) { var sql = "INSERT INTO LoyaltyCustomer (CustomerId, FirstName, LastName, EmailAddress, RewardStatus, LoyaltyPointsBalance, LifetimeLoyaltyPoints)" + " Values (@CustomerId, @FirstName, @LastName, @EmailAddress, @RewardStatus, @LoyaltyPointsBalance, @LifetimeLoyaltyPoints);"; _db.Execute(sql, new { CustomerId = customer.CustomerId, FirstName = customer.FirstName, LastName = customer.LastName, EmailAddress = customer.EmailAddress, RewardStatus = customer.RewardStatus.ToString(), LoyaltyPointsBalance = customer.LoyaltyPointsBalance, LifetimeLoyaltyPoints = customer.LifetimeLoyaltyPoints }); }
public void UpdateLoyaltyCustomer(LoyaltyCustomer customer) { // Todo: Test 2 - Need to update the SQL statement and parameters in order to save first and last names var sql = "UPDATE LoyaltyCustomer Set FirstName = @FirstName, LastName = @LastName, EmailAddress = @EmailAddress, RewardStatus = @RewardStatus," + " LoyaltyPointsBalance = @LoyaltyPointsBalance, LifetimeLoyaltyPoints = @LifetimeLoyaltyPoints" + " WHERE CustomerId = @CustomerId;"; _db.Execute(sql, new { FirstName = customer.FirstName, LastName = customer.LastName, EmailAddress = customer.EmailAddress, RewardStatus = customer.RewardStatus.ToString(), LoyaltyPointsBalance = customer.LoyaltyPointsBalance, LifetimeLoyaltyPoints = customer.LifetimeLoyaltyPoints, CustomerId = customer.CustomerId }); }
public void Test8_Orders_Should_Update_LoyaltyPoints() { /* * * 1) Create a new Loyalty Customer with 0 points and Add them * 2) Create a new Order and add the Loyalty Customer, a product and a payment * 3) Process the order * 4) Get the customer, and verify that their points were updated appropriately * */ var loyaltyService = new LoyaltyService(new LoyaltyRepository(_testDbConnection)); IOrderService orderService = OrderService; var customer = new LoyaltyCustomer() { CustomerId = Guid.NewGuid(), EmailAddress = "*****@*****.**", FirstName = "Test", LastName = "Test", LifetimeLoyaltyPoints = 0, LoyaltyPointsBalance = 0, RewardStatus = RewardStatus.Silver }; loyaltyService.AddLoyaltyCustomer(customer); var order = new Order(); order.AddLoyaltyCustomerToOrder(customer); const decimal price = 1m; // Buy a 1.00 product order.AddItemToOrder(new OrderItem(GetValidProduct(), ProductSize.Medium, price)); order.Payments.AddPayment(PaymentType.Cash, price); orderService.ProcessOrder(order); var updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId); Assert.Equal(price / 10, updatedCustomer.LoyaltyPointsBalance); }
public void Test_2_Should_Update_Customer_Name() { /* * * 1) Create a new Loyalty Customer and Add them * 2) Get the customer * 3) Change the customer's first and last name * 4) Update the customer * 5) Get the customer * 6) Ensure the updated customer has the new information */ var loyaltyService = new LoyaltyService(new LoyaltyRepository(_testDbConnection)); const string firstName = "Test2"; const string lastName = "2Test"; var customer = new LoyaltyCustomer() { CustomerId = Guid.NewGuid(), EmailAddress = "*****@*****.**", FirstName = firstName, LastName = lastName, LifetimeLoyaltyPoints = 0, LoyaltyPointsBalance = 0, RewardStatus = RewardStatus.Silver }; loyaltyService.AddLoyaltyCustomer(customer); var newCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId); Assert.Equal(firstName, newCustomer.FirstName); Assert.Equal(lastName, newCustomer.LastName); newCustomer.FirstName = lastName; newCustomer.LastName = firstName; loyaltyService.UpdateLoyaltyCustomer(newCustomer); var updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId); Assert.Equal(lastName, updatedCustomer.FirstName); Assert.Equal(firstName, updatedCustomer.LastName); }
public void Test10_LoyaltyStatus_Should_Update_When_Reaching_Milestone() { /* * * 1) Create a new Loyalty Customer with 0 points and Add them * 2) Create a new Order and add the Loyalty Customer, a product and a payment * 3) Process the order * 4) Get the customer and ensure their status has changed appropriately * * */ var order = new Order(); var loyaltyService = new LoyaltyService(new LoyaltyRepository(_testDbConnection)); var customer = new LoyaltyCustomer() { CustomerId = Guid.NewGuid(), EmailAddress = "*****@*****.**", FirstName = "Test", LastName = "Test", LifetimeLoyaltyPoints = 0, LoyaltyPointsBalance = 0, RewardStatus = RewardStatus.Silver }; loyaltyService.AddLoyaltyCustomer(customer); order.AddLoyaltyCustomerToOrder(customer); const decimal price = 1001m; // Buy a $1001 product in order to become diamond status order.AddItemToOrder(new OrderItem(GetValidProduct(), ProductSize.Medium, price)); order.Payments.AddPayment(PaymentType.Cash, price); IOrderService orderService = OrderService; orderService.ProcessOrder(order); var updatedCustomer = loyaltyService.GetLoyaltyCustomer(customer.CustomerId); Assert.Equal(RewardStatus.Diamond, updatedCustomer.RewardStatus); }
public static void AddLoyaltyPoints(this LoyaltyCustomer customer, decimal pointsToAdd) { customer.LoyaltyPointsBalance += pointsToAdd; customer.LifetimeLoyaltyPoints += pointsToAdd; }
public static void RemoveLoyaltyPoints(this LoyaltyCustomer customer, decimal pointsToRemove) { customer.LoyaltyPointsBalance -= pointsToRemove; customer.LoyaltyPointsBalance = customer.LoyaltyPointsBalance < 0 ? 0 : customer.LoyaltyPointsBalance; }
public void DeleteLoyaltyCustomer(LoyaltyCustomer customer) { throw new NotImplementedException(); }
public void UpdateLoyaltyCustomer(LoyaltyCustomer customer) { _loyaltyRepository.UpdateLoyaltyCustomer(customer); }
public void AddLoyaltyCustomer(LoyaltyCustomer customer) { _loyaltyRepository.AddLoyaltyCustomer(customer); }
private bool Find(LoyaltyCustomer customer) { return(customer.LastName.StartsWith('D') && customer.FirstName.StartsWith('S')); }