public void TestAddItemToCheckout()
        {
            // Arrange
            ICheckout checkout = new Checkout();

            // Act
            checkout.AddItem(new CheckoutItem("A", 50));
            checkout.AddItem(new CheckoutItem("B", 30));

            //Assert
            Assert.AreEqual(2, checkout.Items.Count, "Number of items does not equal 2");
        }
        public void TestCalculateTotalPrice()
        {
            // Arrange
            ICheckout checkout = new Checkout();

            checkout.AddItem(new CheckoutItem("A", 50));
            checkout.AddItem(new CheckoutItem("B", 30));

            // Act
            var total = checkout.CalculateTotal();

            // Assert
            Assert.AreEqual(80, total);
        }
        public void TestSpecialOffersCanBeAdded_NoSpecialOffers()
        {
            // Arrange
            ICheckout checkout = new Checkout();

            checkout.AddItem(new CheckoutItem("B", 30));
            checkout.AddItem(new CheckoutItem("A", 50));
            checkout.AddItem(new CheckoutItem("B", 30));

            // Act

            // Assert
            Assert.AreEqual(0, checkout.SpecialOffers.Count);
        }
        public void TestSpecialOffersAreApplied()
        {
            // Arrange
            ICheckout checkout = new Checkout();

            checkout.AddItem(new CheckoutItem("B", 30));
            checkout.AddItem(new CheckoutItem("A", 50));
            checkout.AddItem(new CheckoutItem("B", 30));

            // Act
            checkout.AddSpecialOffer(new MultiBuySpecialOffer(2, "B", 45));

            // Assert
            Assert.AreEqual(95, checkout.CalculateTotal());
        }
        public void TestSpecialOffersCanBeAdded()
        {
            // Arrange
            ICheckout checkout = new Checkout();

            checkout.AddItem(new CheckoutItem("B", 30));
            checkout.AddItem(new CheckoutItem("A", 50));
            checkout.AddItem(new CheckoutItem("B", 30));

            // Act
            checkout.AddSpecialOffer(new MultiBuySpecialOffer(2, "B", 45));

            // Assert
            Assert.AreEqual(1, checkout.SpecialOffers.Count);
        }
        public void TestSpecialOffersAreApplied_WithAdditionalItemsNotCoveredByOffer()
        {
            // Arrange
            ICheckout checkout = new Checkout();

            checkout.AddItem(new CheckoutItem("B", 30));
            checkout.AddItem(new CheckoutItem("A", 50));
            checkout.AddItem(new CheckoutItem("B", 30));
            checkout.AddItem(new CheckoutItem("B", 30));

            // Act
            checkout.AddSpecialOffer(new MultiBuySpecialOffer(2, "B", 45));

            // Assert
            Assert.AreEqual(125, checkout.CalculateTotal());
        }
Exemplo n.º 7
0
 private void AddItems(int count, Item item)
 {
     for (int i = 0; i < count; i++)
     {
         checkout.AddItem(item);
     }
 }
Exemplo n.º 8
0
        public void AddItem_ThrowsItemCodeNotRecognisedException_WhenItemCodeDoesNotExist()
        {
            //arrange
            var itemCodeToAdd = "THIS CODE DOES NOT EXIST";

            //act + assert
            Assert.Throws <ItemCodeNotRecognisedException>(() => Checkout.AddItem(itemCodeToAdd));
        }
        public void TestAddItemToCheckout_Null()
        {
            // Arrange
            ICheckout checkout = new Checkout();

            // Act
            checkout.AddItem(null);

            //Assert
            Assert.Fail("ArgumentNullException should have been thrown");
        }
Exemplo n.º 10
0
            public void ArrangeWhenPriceApplies()
            {
                _fixture = new Fixture();

                _fixture.Customize(new AutoRhinoMockCustomization());

                _pricingRule = _fixture.Create <ISpecialPricingRule>();

                _product = _fixture.Create <Product>();

                _pricingRule.Stub(r =>
                                  r.IsApplicable(
                                      Arg <ICollection <Product> > .Matches(p => p.First().ProductId == _product.ProductId)))
                .Return(true);

                _pricingRule.Expect(r =>
                                    r.Apply(Arg <ICollection <Product> > .Matches(p => p.First().ProductId == _product.ProductId)));

                _sut = new Checkout(new List <ISpecialPricingRule> {
                    _pricingRule
                });

                _sut.AddItem(_product);
            }
Exemplo n.º 11
0
        public void TestMethodToothpaste()
        {
            // 3 toothpaste
            _checkout.AddItem(1);
            _checkout.AddItem(1);
            _checkout.AddItem(1);

            var Totl = _checkout.Sum();

            Assert.AreEqual(49.88, Totl);
        }