public void TestAddPositive() { var item = new Item(); var discount = new Discount(); discountCollection.Add(item, discount); Assert.AreEqual(discount, discountCollection.GetOrDefault(item, null)); }
public void TestPayItemsWithDiscountPositive() { var apple = new Item { Name = "Apple", Price = 30 }; var banana = new Item { Name = "Banana", Price = 50 }; var peach = new Item { Name = "Peach", Price = 60 }; checkout.AddItem(2, apple); checkout.AddItem(7, banana); checkout.AddItem(4, peach); var discountApple = new Discount { Name = "2 for 45", Quantity = 2, Price = 45 }; var discountBanana = new Discount { Name = "3 for 130", Quantity = 3, Price = 130 }; var discountPeach = new Discount { Name = "5 for 40", Quantity = 5, Price = 40 }; discountCollection.Add(apple, discountApple); discountCollection.Add(banana, discountBanana); discountCollection.Add(peach, discountPeach); var checkoutBill = checkout.PayItems(); var paidApple = new CheckoutItem(apple, discountApple) { Amount = 2, Price = 45, AppliedDiscounts = 1 }; var paidBanana = new CheckoutItem(banana, discountBanana) { Amount = 7, Price = 310, AppliedDiscounts = 2 }; var paidPeach = new CheckoutItem(peach, discountPeach) { Amount = 4, Price = 240, AppliedDiscounts = 0 }; Assert.True(checkoutBill.Items.Contains(paidApple)); Assert.True(checkoutBill.Items.Contains(paidBanana)); Assert.True(checkoutBill.Items.Contains(paidPeach)); Assert.AreEqual(595, checkoutBill.Total); }
public void TestPayItemsWithDiscountNegative() { var apple = new Item { Name = "Apple", Price = 30 }; var banana = new Item { Name = "Banana", Price = 50 }; var peach = new Item { Name = "Peach", Price = 60 }; checkout.AddItem(2, apple); checkout.AddItem(7, banana); checkout.AddItem(4, peach); var invalidDiscountCollection = new SupermarketCheckout.DiscountCollection { ValidityRange = new SupermarketCheckout.Utils.DateTimeRange(new DateTime(DateTime.Now.Year - 1, 6, 10), new DateTime(DateTime.Now.Year - 1, 6, 16)) }; var discountApple = new Discount { Name = "2 for 45", Quantity = 2, Price = 45 }; var discountBanana = new Discount { Name = "3 for 130", Quantity = 3, Price = 130 }; var discountPeach = new Discount { Name = "5 for 40", Quantity = 5, Price = 40 }; invalidDiscountCollection.Add(apple, discountApple); invalidDiscountCollection.Add(banana, discountBanana); invalidDiscountCollection.Add(peach, discountPeach); checkout.DiscountCollection = invalidDiscountCollection; var checkoutBill = checkout.PayItems(); var paidApple = new CheckoutItem(apple, SupermarketCheckout.Checkout.NoDiscount) { Amount = 2, Price = 60, AppliedDiscounts = 0 }; var paidBanana = new CheckoutItem(banana, SupermarketCheckout.Checkout.NoDiscount) { Amount = 7, Price = 350, AppliedDiscounts = 0 }; var paidPeach = new CheckoutItem(peach, SupermarketCheckout.Checkout.NoDiscount) { Amount = 4, Price = 240, AppliedDiscounts = 0 }; Assert.True(checkoutBill.Items.Contains(paidApple)); Assert.True(checkoutBill.Items.Contains(paidBanana)); Assert.True(checkoutBill.Items.Contains(paidPeach)); Assert.AreEqual(650, checkoutBill.Total); }