public void GivenTwoItemsHaveBeenScanned_WhenGetTotalPrice_ThenTheSumOfItemPriceIsReturned() { ICheckout checkout = Mocker.CreateInstance <Checkout>(); Mocker.GetMock <IItemLookup>().Setup(scanner => scanner.Lookup('A')).Returns(new CheckoutItem('A', 50)); Mocker.GetMock <IItemLookup>().Setup(scanner => scanner.Lookup('B')).Returns(new CheckoutItem('B', 30)); checkout.AppendItem('A'); checkout.AppendItem('B'); var totalPrice = checkout.GetTotalPrice(); totalPrice.Should().Be(80); }
public void WhenAnInvalidItemCodeIsScanned_ThenItIsNotAddedToTheCheckout() { ICheckout checkout = Mocker.CreateInstance <Checkout>(); Mocker.GetMock <IItemLookup>().Setup(scanner => scanner.Lookup('E')).Returns((CheckoutItem)null); checkout.AppendItem('E'); var totalPrice = checkout.GetTotalPrice(); totalPrice.Should().Be(0); }
public void WhenScanSingleItem_ThenItemShouldBeInstantiated(char itemCode, decimal itemPrice) { ICheckout checkout = Mocker.CreateInstance <Checkout>(); ICheckoutItem expectedCheckoutItem = new CheckoutItem(itemCode, itemPrice); Mocker.GetMock <IItemLookup>() .Setup(scanner => scanner.Lookup(itemCode)) .Returns(expectedCheckoutItem); var item = checkout.AppendItem(itemCode); item.ItemCode.Should().Be(itemCode); item.ItemPrice.Should().Be(itemPrice); }
public void EnterLoop() { _checkoutMessagePrinter.PrintWelcomeMessage(); do { var itemCode = _itemScanner.Scan(); if (itemCode == 'X') { break; } _checkout.AppendItem(itemCode); } while (true); _checkoutMessagePrinter.PrintTotalPrice(_checkout.GetTotalPrice()); }