public void AddItem_AddTwoValidProductsToCart_TotalEqualsItemsPrice() { IProductRepository products = A.Fake<IProductRepository>(); ShoppingCart shoppingCart = new ShoppingCart(products); A.CallTo(() => products.GetProductById("item-1")).Returns(new Product("item-1", "Banana", 14.5)); A.CallTo(() => products.GetProductById("item-2")).Returns(new Product("item-2", "Orange", 2.5)); shoppingCart.AddItem("item-1"); shoppingCart.AddItem("item-2"); Assert.That(shoppingCart.Total, Is.EqualTo(17)); }
public void Clear_AddInvalidItemToCartThenClear_ThrowUnknownProductException() { IProductRepository products = A.Fake<IProductRepository>(); A.CallTo(() => products.GetProductById(A<string>.Ignored)).Throws(new UnknownProductException("UnknownProductException was thrown.")); ShoppingCart shoppingCart = new ShoppingCart(products); Assert.Throws<UnknownProductException>(() => shoppingCart.AddItem("item-999")); }
public void Clear_AddValidItemToCartThenClear_TotalEquals0() { IProductRepository products = A.Fake<IProductRepository>(); ShoppingCart shoppingCart = new ShoppingCart(products); A.CallTo(() => products.GetProductById("item-1")).Returns(new Product("item-1", "Banana", 14.5)); shoppingCart.AddItem("item-1"); shoppingCart.Clear(); Assert.That(shoppingCart.Total, Is.EqualTo(0)); }
public void AddItem_AddValidProductToCart_TotalEqualsItemPrice() { // Arrange IProductRepository products = A.Fake<IProductRepository>(); ShoppingCart shoppingCart = new ShoppingCart(products); A.CallTo(() => products.GetProductById("item-1")).Returns(new Product("item-1", "Banana", 14.5)); // Act shoppingCart.AddItem("item-1"); // Assert Assert.AreEqual(shoppingCart.Total, 14.5); }