public void GivenAddableProductItem_WhenAddCalledWithNullProductItem_ThenThrowsArgumentNullException()
        {
            // Arrange
            IAddableProductItem addableProductItem = new AddableProductItem(Mock.Of <IProductItem>());

            // Act, Assert
            Assert.Throws <ArgumentNullException>(() => addableProductItem.Add(null));
        }
        public void GivenNoObject_WhenAddableProductItemCreated_ThenReturnsAnInstanceOfIAddableProductItem()
        {
            // Arrange, Act
            var addableProductItem = new AddableProductItem(Mock.Of <IProductItem>());

            // Assert
            Assert.That(addableProductItem, Is.InstanceOf(typeof(IAddableProductItem)));
        }
        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));
        }
        public void GivenConsolidateProductItemsShoppingCart_WhenAddTwoProductItemsWithSameName_ThenContainsSingleProductItemWithCombinedQuantity()
        {
            // Arrange
            var shoppingCart = new ConsolidateProductItemsShoppingCart();

            var firstProductItem = new Mock <IProductItem>();

            firstProductItem.Setup(pi => pi.Name).Returns("product name");
            firstProductItem.Setup(pi => pi.Quantity).Returns(10);
            IAddableProductItem addableProductItem = new AddableProductItem(firstProductItem.Object);

            var secondProductItem = new Mock <IProductItem>();

            secondProductItem.Setup(pi => pi.Name).Returns("product name");
            secondProductItem.Setup(pi => pi.Quantity).Returns(7);

            // Act
            shoppingCart.AddProductItem(firstProductItem.Object);
            shoppingCart.AddProductItem(secondProductItem.Object);


            // Assert
            Assert.That(shoppingCart.ProductItems.First().Quantity, Is.EqualTo(17));
        }