public void GivenAddableProductItem_WhenAddCalledWithNullProductItem_ThenThrowsArgumentNullException() { // Arrange IAddableProductItem addableProductItem = new AddableProductItem(Mock.Of <IProductItem>()); // Act, Assert Assert.Throws <ArgumentNullException>(() => addableProductItem.Add(null)); }
public void GivenAddableProductItem_WhenAddCalledWithInvalidProductItem_ThenThrowsArgumentException() { // Arrange var productItemToAddTo = new Mock <IProductItem>(); productItemToAddTo.Setup(pi => pi.Name).Returns("Some product name"); IAddableProductItem addableProductItem = new AddableProductItem(productItemToAddTo.Object); var productItemToAdd = new Mock <IProductItem>(); productItemToAdd.Setup(pi => pi.Name).Returns("Different product name"); // Act, Assert Assert.Throws <ArgumentException>(() => addableProductItem.Add(productItemToAdd.Object)); }
public void GivenAddableProductItem_WhenAddCalledWithValidProductItem_ThenReturnsCombinedQuantity() { // Arrange var productItemToAddTo = new Mock <IProductItem>(); productItemToAddTo.Setup(pi => pi.Name).Returns("product name"); productItemToAddTo.Setup(pi => pi.Quantity).Returns(10); IAddableProductItem addableProductItem = new AddableProductItem(productItemToAddTo.Object); var productItemToAdd = new Mock <IProductItem>(); productItemToAdd.Setup(pi => pi.Name).Returns("product name"); productItemToAdd.Setup(pi => pi.Quantity).Returns(7); // Act, Assert addableProductItem.Add(productItemToAdd.Object); // Assert Assert.That(addableProductItem.Quantity, Is.EqualTo(17)); }