public void TestMethod2() { var basketService = new BasketService(); // Could've added these a lists but didnt feel it necessary for the scale of these tests var butter1 = new Product() { Name = "Butter", Type = ProductType.Butter, Price = 0.80 }; var butter2 = new Product() { Name = "Butter", Type = ProductType.Butter, Price = 0.80 }; var bread1 = new Product() { Name = "Bread", Type = ProductType.Bread, Price = 1.00 }; var bread2 = new Product() { Name = "Bread", Type = ProductType.Bread, Price = 1.00 }; var expected = 3.10; basketService.AddProduct(butter1); basketService.AddProduct(butter2); basketService.AddProduct(bread1); basketService.AddProduct(bread2); double actual = basketService.GetTotal(); Assert.AreEqual(expected, actual, 0.001, "TestMethod2 Failed"); }
public void TestMethod3() { var basketService = new BasketService(); // Could've added these a lists but didnt feel it necessary for the scale of these tests var milk1 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk2 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk3 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk4 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var expected = 3.45; basketService.AddProduct(milk1); basketService.AddProduct(milk2); basketService.AddProduct(milk3); basketService.AddProduct(milk4); double actual = basketService.GetTotal(); Assert.AreEqual(expected, actual, 0.001, "TestMethod3 Failed"); }
public void TestMethod1() { var basketService = new BasketService(); // Could've added these a lists but didnt feel it necessary for the scale of these tests var butter = new Product() { Name = "Butter", Type = ProductType.Butter, Price = 0.80 }; var milk = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var bread = new Product() { Name = "Bread", Type = ProductType.Bread, Price = 1.00 }; var expected = 2.95; basketService.AddProduct(butter); basketService.AddProduct(milk); basketService.AddProduct(bread); double actual = basketService.GetTotal(); Assert.AreEqual(expected, actual, 0.001, "TestMethod1 Failed"); }
public void BasketService_WhenTwoOfSameItemAddedToBasket_TotalPriceIsTwiceTheItemPrice() { var basket = new BasketService(mockProductRepository.Object); // mock concept of scanning an item twice basket.AddProduct(apple.Barcode); basket.AddProduct(apple.Barcode); var distinctCountOfProductsInBasket = basket.GetDistinctProductCount(); var expectedResult = apple.Price * 2; Assert.Equal(expectedResult, basket.GetTotal()); Assert.Equal(1, distinctCountOfProductsInBasket); }
public void BasketService_WhenSingleItemAddedToBasket_TotalPriceMatchesItemPrice() { var basket = new BasketService(mockProductRepository.Object); basket.AddProduct(apple.Barcode); Assert.Equal(apple.Price, basket.GetTotal()); }
public void BasketService_WhenOfferOnMultipleItemsIsAppliedButNumberOfItemsDoesNotMeetOfferCount_TotalPriceMatchesItemPrice() { var basket = new BasketService(mockProductRepository.Object); basket.AddProduct(orange.Barcode, 2); Assert.Equal(orange.Price * 2, basket.GetTotal()); }
public void BasketService_WhenOfferOnMultipleItemsIsAppliedAndNumberOfItemsMeetsOfferCount_TotalPriceMatchesOfferPrice() { var basket = new BasketService(mockProductRepository.Object); basket.AddProduct(orange.Barcode, 3); Assert.Equal(orangeOffer.Price, basket.GetTotal()); }
public void should_add_product_after_remove() { var basketService = new BasketService(CreateMockHttpContextAccessor()); basketService.AddProduct(new Product { Name = "玩具" }); basketService.RemoveFromBasket("0"); basketService.AddProduct(new Product { Name = "玩具2" }); var itemsInBasket = basketService.GetProducts().ToList(); Assert.Single(itemsInBasket); Assert.Equal("玩具2", itemsInBasket.Single().Name); }
public void BasketService_WhenCountOfItemsExceedsOfferCountWithARemainder_TotalPriceIsCombinationOfOfferPlusItemPrice() { var basket = new BasketService(mockProductRepository.Object); basket.AddProduct(orange.Barcode, 5); var expectedResult = orangeOffer.Price + (2 * orange.Price); Assert.Equal(expectedResult, basket.GetTotal()); }
static void Main(string[] args) { var repository = new MockProductRepository(); var basket = new BasketService(repository); Console.WriteLine("Scanning Products"); Console.WriteLine("Adding 3 apples to basket..."); basket.AddProduct(appleBarcode, 3); Console.WriteLine("Adding 5 oranges to basket..."); basket.AddProduct(orangeBarcode, 5); Console.WriteLine("Adding 2lbs of bananas to basket..."); basket.AddWeightedProduct(bananaBarcode, 2); Console.WriteLine($"Basket Total: £{basket.GetTotal()}"); Console.WriteLine("Press any key to exit"); Console.Read(); }
public void BasketService_WhenMultipleItemsAddedToBasket_TotalPriceIsCalculatedCorrectly() { var basket = new BasketService(mockProductRepository.Object); basket.AddProduct(apple.Barcode, 3); basket.AddProduct(orange.Barcode, 5); basket.AddWeightedProduct(banana.Barcode, 2); /* * 3 apples = £1.50, * 5 oranges * --> 1 offer £1.00 * --> 2 orange £0.90 * 6 bananas £4.00 (2 X £2 per lb) * expected total £7.40 */ var expectedResult = (decimal)7.40; Assert.Equal(expectedResult, basket.GetTotal()); }
public void should_remove_product() { var basketService = new BasketService(CreateMockHttpContextAccessor()); basketService.AddProduct(new Product { Name = "玩具" }); basketService.RemoveFromBasket("0"); var itemsInBasket = basketService.GetProducts().ToList(); Assert.Empty(itemsInBasket); }
public void TestMethod4() { var basketService = new BasketService(); // Could've added these a lists but didnt feel it necessary for the scale of these tests var milk1 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk2 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk3 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk4 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk5 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk6 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk7 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var milk8 = new Product() { Name = "Milk", Type = ProductType.Milk, Price = 1.15 }; var butter1 = new Product() { Name = "Butter", Type = ProductType.Butter, Price = 0.80 }; var butter2 = new Product() { Name = "Butter", Type = ProductType.Butter, Price = 0.80 }; var bread1 = new Product() { Name = "Bread", Type = ProductType.Bread, Price = 1.00 }; basketService.AddProduct(milk1); var expected = 9.00; basketService.AddProduct(butter1); basketService.AddProduct(butter2); basketService.AddProduct(bread1); basketService.AddProduct(milk2); basketService.AddProduct(milk3); basketService.AddProduct(milk4); basketService.AddProduct(milk5); basketService.AddProduct(milk6); basketService.AddProduct(milk7); basketService.AddProduct(milk8); double actual = basketService.GetTotal(); Assert.AreEqual(expected, actual, 0.001, "TestMethod4 Failed"); }