public void Should_CalculateCorrectTotalPriceWithoutDiscounts_When_ItemsScannedIncrementally() { // Arrange var priceSystemMock = new Mock <IDiscountCalculator>(); priceSystemMock.Setup(x => x.CalculateTotalDiscount(It.IsAny <IEnumerable <ProductItem> >())); var checkout = new Checkout(priceSystemMock.Object); var item1 = new ProductItem { Id = 0, Price = 10 }; var item2 = new ProductItem { Id = 1, Price = 20 }; // Act // Assert var runningTotalPrice = 0; checkout.Scan(item1); runningTotalPrice = checkout.CalculateTotalPrice(); Assert.AreEqual(10, runningTotalPrice); checkout.Scan(item2); runningTotalPrice = checkout.CalculateTotalPrice(); Assert.AreEqual(30, runningTotalPrice); checkout.Scan(item1); runningTotalPrice = checkout.CalculateTotalPrice(); Assert.AreEqual(40, runningTotalPrice); checkout.Scan(item1); runningTotalPrice = checkout.CalculateTotalPrice(); Assert.AreEqual(50, runningTotalPrice); }
public void Should_CorrectlyCalculatePrice_When_ThereIsOneOfEachItem() { // Arrange var priceSystemMock = new Mock <IDiscountCalculator>(); priceSystemMock.Setup(x => x.CalculateTotalDiscount( It.IsAny <int>(), It.IsAny <int>() )).Returns(0); var checkout = new Checkout(priceSystemMock.Object); var item1 = new ProductItem { Id = 0, Price = 10 }; var item2 = new ProductItem { Id = 1, Price = 20 }; var item3 = new ProductItem { Id = 2, Price = 5 }; var items = new List <ProductItem> { item1, item2, item3 }; checkout.ScanBasket(items); // Act var result = checkout.CalculateTotalPrice(); // Assert Assert.AreEqual(35, result); }
public void Should_ApplyDiscount_When_DiscountApplicable() { // Arrange var priceSystemMock = new Mock <IDiscountCalculator>(); priceSystemMock.Setup(x => x.CalculateTotalDiscount(It.IsAny <IEnumerable <ProductItem> >())); var checkout = new Checkout(priceSystemMock.Object); var item = new ProductItem { Id = 0, Price = 3 }; checkout.Scan(item); checkout.Scan(item); checkout.Scan(item); // Act checkout.CalculateTotalPrice(); // Assert priceSystemMock.Verify(x => x.CalculateTotalDiscount( It.Is <IEnumerable <ProductItem> >(items => items.All(checkout.BasketItems.Contains))), Times.Once); }
public void Should_CorrectlyCalculatePrice_When_DiscountIsApplied() { // Arrange var priceSystemMock = new Mock <IDiscountCalculator>(); priceSystemMock.Setup(x => x.CalculateTotalDiscount( It.IsAny <IEnumerable <ProductItem> >() )).Returns(20); var checkout = new Checkout(priceSystemMock.Object); var item = new ProductItem { Id = 0, Price = 10 }; checkout.Scan(item); checkout.Scan(item); checkout.Scan(item); // Act var result = checkout.CalculateTotalPrice(); // Assert Assert.AreEqual(10, result); }
public void GivenListOfItems_WhenListHasNoItem_ReturnsZeroTotalCost() { //arrange List <item> listWithNoItems = new List <item>(); //act var sut = new Checkout(); //Assert Assert.Equal(0, sut.CalculateTotalPrice(listWithNoItems)); }
public void GivenListOfItems_WhenListIsNull_ThrowsArgumentException() { //arrange List <item> listWithNoItems = null; //act var sut = new Checkout(); //Assert Assert.Throws <ArgumentException>(() => { sut.CalculateTotalPrice(listWithNoItems); }); }
public void GivenListOfItems_WhenItemssAreValid_ReturnsTotalCost() { //arrange var listOfItems = TestVariables.GetFakeListOfItems(); Decimal totalApplePriceInList = listOfItems.Where(x => x.ItemName.ToLower() == "apple").Sum(y => y.ItemPrice); Decimal totalOrangePriceInList = listOfItems.Where(x => x.ItemName.ToLower() == "orange").Sum(y => y.ItemPrice); var totalPriceInLIst = listOfItems.Sum(x => x.ItemPrice); var sut = new Checkout(); //add //act var result = sut.CalculateTotalPrice(listOfItems); //Assert Assert.Equal((Decimal)totalPriceInLIst, (Decimal)result); }
public void Should_ReturnPriceOf0_When_BasketIsEmpty() { // Arrange var priceSystemMock = new Mock <IDiscountCalculator>(); priceSystemMock.Setup(x => x.CalculateTotalDiscount( It.IsAny <int>(), It.IsAny <int>() )).Returns(0); var checkout = new Checkout(priceSystemMock.Object); checkout.ScanBasket(new List <ProductItem>()); // Act var result = checkout.CalculateTotalPrice(); // Assert Assert.AreEqual(0, result); }