static void Main(string[] args)
        {
            var basket = new Basket();

            basket.Add(new Product {
                Name = "Chocolate", Price = 40m
            });
            basket.Add(new Product {
                Name = "Water", Price = 2.4m
            });
            basket.Add(new Product {
                Name = "Newspaper", Price = 10m
            });
            basket.Add(new Product {
                Name = "Water", Price = 2.4m
            });

            IPriceCalculator calculator =
                new CompositePriceCalculator(
                    new BasketContentsPriceCalculator(),
                    new VatCalculator(.25m)); // Whopping Danish VAT!!

            var price = calculator.CalculatePrice(basket);

            Console.WriteLine($"Price: {price}");
        }
        public void GiftVouchersCanOnlyBeRedeemedAgainstNonGiftVoucherProducts()
        {
            //Arrange
            var expectedTotal = 30.00m;

            var basket = new Basket();

            basket.Add(ProductService.Get(ProductService.ProductCode.Hat));
            basket.Add(ProductService.Get(ProductService.ProductCode.GiftVoucher));

            var giftVoucher1 = VoucherService.Get("XXX-XXX");
            var giftVoucher2 = VoucherService.Get("XXX-XXX");
            var giftVoucher3 = VoucherService.Get("XXX-XXX");
            var giftVoucher4 = VoucherService.Get("XXX-XXX");
            var giftVoucher5 = VoucherService.Get("XXX-XXX");
            var giftVoucher6 = VoucherService.Get("XXX-XXX");

            //Act
            basket.ApplyVoucher(giftVoucher1);
            basket.ApplyVoucher(giftVoucher2);
            basket.ApplyVoucher(giftVoucher3);
            basket.ApplyVoucher(giftVoucher4);
            basket.ApplyVoucher(giftVoucher5);
            basket.ApplyVoucher(giftVoucher6); //Edge case: sixth voucher should not be applied

            //Assert
            Assert.Equal(expectedTotal, basket.DiscountedTotal);
        }
        public void Setup()
        {
            basket = new Basket();

            basket.Add("imported box of chocolates", 1);
            basket.Add("imported bottle of perfume", 1);
        }
        public void Setup()
        {
            basket = new Basket();

            basket.Add("book", 1);
            basket.Add("music CD", 1);
            basket.Add("chocolate bar", 1);
        }
        public void Setup()
        {
            basket = new Basket();

            basket.Add("imported bottle of perfume 2", 1);
            basket.Add("bottle of perfume", 1);
            basket.Add("packet of headache pills", 1);
            basket.Add("imported box of chocolates 2", 1);
        }
Пример #6
0
        public void Basket2()
        {
            Basket basket = new Basket();

            basket.Add(new BasketElement(1, new Product("Box of chocolates", 10.00m, ProductCategory.Food, true)));
            basket.Add(new BasketElement(1, new Product("Bottle of perfume", 47.50m, ProductCategory.Other, true)));

            Assert.IsTrue(basket.GetSalesTaxes() == 7.65m, "Wrong sales taxes");
            Assert.IsTrue(basket.GetTotal() == 65.15m, "Wrong total");
        }
            public void CanAddMultipleOfSameProduct(
                Basket sut)
            {
                IProduct product = new ProductFaker().Generate();

                sut.Add(product);
                sut.Add(product);

                sut.Products.Should().BeEquivalentTo(product, product);
            }
Пример #8
0
        public void Discount9BooksWith1setsOf4IdenticalsAnd1SetOf2Identicals()
        {
            Basket basket = new Basket();
            Book   book1  = new Book("Harry Potter à l'école des sorciers");
            Book   book2  = new Book("Harry Potter et la chambre des secrets");
            Book   book3  = new Book("Harry Potter et le prisonnier d'Azkaban");
            Book   book4  = new Book("Harry Potter et le prisonnier d'Azkaban");
            Book   book5  = new Book("Harry Potter et la coupe de feu");
            Book   book6  = new Book("Harry Potter et la coupe de feu");
            Book   book7  = new Book("Harry Potter et la coupe de feu");
            Book   book8  = new Book("Harry Potter et la coupe de feu");
            Book   book9  = new Book("Harry Potter et l\'ordre du Phoenix");

            basket.Add(book1);
            basket.Add(book2);
            basket.Add(book3);
            basket.Add(book4);
            basket.Add(book5);
            basket.Add(book6);
            basket.Add(book7);
            basket.Add(book8);
            basket.Add(book9);

            Price basketPrice       = basket.GetBestBasketPrice();
            Price priceWithDiscount = new Price(61.2);

            basketPrice.Equals(priceWithDiscount).Should().BeTrue();
        }
Пример #9
0
        public void ShouldContainMutlipleItemsWhenAddingManyOfOneProduct()
        {
            var basket = new Basket();

            var product = new Product(42, "Name", Money.Zero(SE));

            basket.Add(product);
            basket.Add(product);

            Assert.Equal(2, basket.Count);
        }
Пример #10
0
        public void Buy2DifferentBooks_YouWIllGetA5percentDiscount()
        {
            var basket = new Basket();

            basket.Add(_books[1]);
            basket.Add(_books[2]);

            var totalCost = basket.CheckOut();

            Assert.IsTrue(totalCost == 15.20M);
        }
Пример #11
0
        public void BuyFiveBooks_2DifferentTitles_10PercentDiscountBut4thWillBe8Euro()
        {
            var basket = new Basket();

            basket.Add(_books[4]);
            basket.Add(_books[1]);
            basket.Add(_books[1]);
            var totalCost = basket.CheckOut();

            Assert.IsTrue(totalCost == 23.2M);
        }
Пример #12
0
        public void Scenario1()
        {
            var basket   = new Basket();
            var checkout = new CheckoutService();

            basket.Add(TestData.Bread);
            basket.Add(TestData.Butter);
            basket.Add(TestData.Milk);

            Assert.Equal(2.95m, checkout.CalculateTotal(basket));
        }
Пример #13
0
        public void Basket1()
        {
            Basket basket = new Basket();

            basket.Add(new BasketElement(1, new Product("Book", 12.49m, ProductCategory.Book, false)));
            basket.Add(new BasketElement(1, new Product("MusicCD", 14.99m, ProductCategory.Other, false)));
            basket.Add(new BasketElement(1, new Product("Chocolate", 0.85m, ProductCategory.Food, false)));

            Assert.IsTrue(basket.GetSalesTaxes() == 1.50m, "Wrong sales taxes");
            Assert.IsTrue(basket.GetTotal() == 29.83m, "Wrong total");
        }
Пример #14
0
        public void TheTotalShouldBe2Pounds95_GivenTheBasketHas1Butter1MilkAnd1Bread()
        {
            var basket = new Basket();

            basket.Add(Butter);
            basket.Add(Milk);
            basket.Add(Bread);

            var total = basket.Total;

            total.ShouldBe(new Gbp(2.95m));
        }
Пример #15
0
        public void ShouldTotalWithVat()
        {
            var basket = new Basket();

            var apple  = new Product(42, "Apple", new Money(13.76, SE));
            var banana = new Product(43, "Banana", new Money(44.55, SE));

            basket.Add(apple);
            basket.Add(banana);

            Assert.Equal(new Money(72.89, SE), basket.TotalWithVat);
        }
Пример #16
0
        public void Basket3()
        {
            Basket basket = new Basket();

            basket.Add(new BasketElement(1, new Product("Bottle of perfume", 27.99m, ProductCategory.Other, true)));
            basket.Add(new BasketElement(1, new Product("Bottle of perfume", 18.99m, ProductCategory.Other, false)));
            basket.Add(new BasketElement(1, new Product("Packet of headache pills", 9.75m, ProductCategory.Medical, false)));
            basket.Add(new BasketElement(1, new Product("Box of chocolates", 11.25m, ProductCategory.Food, true)));

            Assert.IsTrue(basket.GetSalesTaxes() == 6.70m, "Wrong sales taxes");
            Assert.IsTrue(basket.GetTotal() == 74.68m, "Wrong total");
        }
Пример #17
0
        public void Buy5DifferentBooks_YouWIllGetA20percentDiscount()
        {
            var basket = new Basket();

            basket.Add(_books[4]);
            basket.Add(_books[3]);
            basket.Add(_books[1]);
            basket.Add(_books[2]);
            basket.Add(_books[0]);
            var totalCost = basket.CheckOut();

            Assert.IsTrue(totalCost == 30);
        }
Пример #18
0
        public void TheTotalShouldBe3Pounds10_GivenTheBasketHas2ButterAnd2Bread()
        {
            var basket = new Basket();

            basket.Add(Butter);
            basket.Add(Butter);
            basket.Add(Bread);
            basket.Add(Bread);

            var total = basket.Total;

            total.ShouldBe(new Gbp(3.10m));
        }
Пример #19
0
        public void ProductsShouldNotBeIncludedInMultipleDiscounts(
            [Frozen(Matching.ImplementedInterfaces)] FakeClock fakeClock,
            [Frozen(Matching.ImplementedInterfaces)] DiscountService discountService,
            Basket basket)
        {
            discountService.AddProductDiscount(new PieAndChipsMealDealDiscount(new DiscountPercent(20)));
            discountService.AddProductDiscount(new PieExpiryDiscount(fakeClock, new DiscountPercent(50)));

            basket.Add(new Pie(new Price(3.20m), fakeClock.GetCurrentInstant().InUtc().Date));
            basket.Add(new PortionOfChips(new Price(1.80m)));

            basket.TotalCost.Should().Be(3.40m);
        }
        public void Take_WhenMultipleItemsInBasket_ReturnsThemAll()
        {
            const string item1 = "something 1";
            const string item2 = "something 2";

            var sut = new Basket();

            sut.Add(item1);
            sut.Add(item2);

            Assert.That(sut.Take(), Is.EqualTo(item2));
            Assert.That(sut.Take(), Is.EqualTo(item1));
            Assert.That(sut.Take(), Is.Null);
        }
        public void CalculateBasket()
        {
            var basket = new Basket(catalog);

            basket.Add("soup");      // should be $2.50 total (with the 2 soups)
            basket.Add("soup");
            basket.Add("mushrooms"); // should be $2.50 total also (with all 3 mushrooms)
            basket.Add("mushrooms");
            basket.Add("mushrooms");

            var total = basket.CalculateTotal();

            Assert.Equal(5.0m, total);
        }
Пример #22
0
        public void DiscountOf5PercentShouldBeApplyWhenBasketContains2DifferentsBooks()
        {
            Basket basket = new Basket();
            Book   book1  = new Book("Harry Potter à l'école des sorciers");
            Book   book2  = new Book("Harry Potter et la chambre des secrets");

            basket.Add(book1);
            basket.Add(book2);

            Price  basketPrice = basket.GetBestBasketPrice();
            double total       = 2 * 8 - (2 * 8 * 0.05);
            Price  priceOf2booksWithDiscount = new Price(total);

            basketPrice.Equals(priceOf2booksWithDiscount).Should().BeTrue();
        }
Пример #23
0
        public void PieDiscountShouldOnlyAllyToExpiringPies(
            [Frozen(Matching.ImplementedInterfaces)] FakeClock fakeClock,
            [Frozen(Matching.ImplementedInterfaces)] DiscountService discountService,
            Basket basket)
        {
            discountService.AddProductDiscount(new PieExpiryDiscount(fakeClock, new DiscountPercent(50)));

            Pie pie1 = new Pie(new Price(3.20m), fakeClock.GetCurrentInstant().InUtc().Date);
            Pie pie2 = new Pie(new Price(3.20m), fakeClock.GetCurrentInstant().InUtc().Date.PlusDays(1));

            basket.Add(pie1);
            basket.Add(pie2);

            basket.TotalCost.Should().Be(4.80m);
        }
Пример #24
0
        public void Add_ProductIsAddedThenShouldContainProduct()
        {
            var product = new Product(9.99m);

            _valueCalculator.Setup(o => o.CalculateValue(It.IsAny <IEnumerable <Product> >(), It.IsAny <IEnumerable <Voucher> >())).Returns(9.99m);
            _voucherValidator.Setup(o => o.Validate(It.IsAny <IEnumerable <Product> >(), It.IsAny <IEnumerable <Voucher> >())).Returns((Enumerable.Empty <Voucher>(), Enumerable.Empty <Voucher>()));

            _basket.Add(product);

            _basket.Products.Count.Should().Be(1);
            _basket.Products.Should().Contain(product);
        }
Пример #25
0
        public void BasketsController_RemoveBasketItem()
        {
            //prepare dataset: a product, a basket and a basket item
            var product = new PhotoProduct {
                Name = "Alpha", Id = "42"
            };
            var basket = new Basket {
                Id = "Aruba", Created = DateTime.Now, Modified = DateTime.Now
            };
            var basketItem = basket.Add(product, 1337);

            //prepare the ceremonies: the repo's, services and the controller
            var productRepo = new PhotoProductMemoryRepository();

            productRepo.Add(product);
            var productService = new PhotoProductService(productRepo);

            var repo = new BasketMemoryRepository();

            repo.Add(basket);

            var service = new BasketService(repo, productService);

            var controller = new BasketsController(service, productService);

            //actual test
            var result = controller.RemoveBasketItem("Aruba", basket.Contents[0].Id);

            Assert.IsNotNull(result, "There should be a result.");
            Assert.IsInstanceOfType(result, typeof(OkResult));

            //check result in original basket
            Assert.AreEqual(0, basket.Contents.Count, "There should be no basket items anymore.");
        }
 public void GivenIHaveAddedTheFollowingToMyBasket(IEnumerable <LineItem> lines)
 {
     foreach (var line in lines)
     {
         _target.Add(line);
     }
 }
        public void Checkout_ChecksOut()
        {
            // Arrange
            var userId = 1;

            this.userService.Get("TestUser").Returns(new User {
                Id = userId
            });

            var basket = new Basket();

            basket.Add(new BasketItem {
                ItemId = 2
            });

            this.basketService.GetByUserId(userId).Returns(basket);
            this.itemService.Get(2).Returns(new Item {
                Id = 2, Stock = 4
            });

            // Act
            controller.Checkout("TestUser");

            // Assert
            this.basketService.Received(1).Checkout(basket);
        }
        public void Checkout_ReturnsInvoiceOk()
        {
            // Arrange
            var userId = 1;

            this.userService.Get("TestUser").Returns(new User {
                Id = userId
            });

            var basket = new Basket();

            basket.Add(new BasketItem {
                ItemId = 2
            });

            this.basketService.GetByUserId(userId).Returns(basket);
            this.itemService.Get(2).Returns(new Item {
                Id = 2, Stock = 4
            });

            // Act
            var actionResult = controller.Checkout("TestUser");

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <Invoice>));
        }
Пример #29
0
        private void OnAddToBasket(int?productID)
        {
            // Lookup the product based on the ID
            var product = Products.First(p => p.ID == productID);

            // Check whether the product is already in the basket
            var basketItem = Basket.FirstOrDefault(p => p.ProductID == productID);

            if (basketItem != null)
            {
                // Product already in the basket -> add amount and total price
                basketItem.Amount++;
                basketItem.TotalPrice += product.UnitPrice;
            }
            else
            {
                // New product -> add item to basket
                Basket.Add(new ReceiptLineViewModel
                {
                    ProductID   = product.ID,
                    Amount      = 1,
                    ProductName = product.ProductName,
                    TotalPrice  = product.UnitPrice
                });
            }
        }
Пример #30
0
        public void BasketPriceShouldBeEqualOf24WhenAddingThreeBook()
        {
            Basket basket = new Basket();
            Book   book1  = new Book("Harry Potter à l'école des sorciers");
            Book   book2  = new Book("Harry Potter et la chambre des secrets");
            Book   book3  = new Book("Harry Potter et le prisonnier d'Azkaban");

            basket.Add(book1);
            basket.Add(book2);
            basket.Add(book3);

            Price basketPrice   = basket.GetPrice();
            Price priceOf3Books = new Price(24);

            basketPrice.Equals(priceOf3Books).Should().BeTrue();
        }
        private void AddProductsToBasket(IList<int> productsToAdd, Basket basket)
        {
            Product product;

            if (productsToAdd.Count() > 0)
                foreach (int productId in productsToAdd)
                {
                    product = _productRepository.FindBy(productId);
                    basket.Add(product);
                }
        }
        public void GivenIHaveAProductsInMyBasket()
        {
            _basket = new Basket();

            _basket.Add(GetHatProduct());
        }