コード例 #1
0
        public void TestAllOffersHaveAssociatedGoodsItems()
        {
            var config = new PriceCalculatorConfiguration();
            var goods  = config.AvailableGoodsItems;
            var offers = config.AvailableOffers;

            foreach (var offer in offers)
            {
                var goodsItem = goods.SingleOrDefault(c => c.Name == offer.GoodsItemName);
                Assert.NotNull(goodsItem, $"Offer is for goods item {offer.GoodsItemName} which does not exist");
            }
        }
コード例 #2
0
        public void TestScenarioForWhenDiscountAmountIsOver1Pound()
        {
            var priceConfiguration = new PriceCalculatorConfiguration()
            {
                AvailableGoodsItems = new List <GoodsItem>()
                {
                    new GoodsItem("TestApples", 99.00m)
                },
                AvailableOffers = new List <Offer>()
                {
                    new Offer("TestApples", new PercentageDiscount(99))
                }
            };

            var calculator = new global::PriceCalculator.PriceCalculator(priceConfiguration);
            var basket     = calculator.GetCompletedBasket(new string[] { "TestApples" });

            Assert.AreEqual(99m, basket.SubTotal, "Incorrect value for subtotal");
            Assert.AreEqual(0.99m, basket.Total, "Incorrect value for total");
            Assert.AreEqual(1, basket.Messages.Count, "Incorrect count for messages");
            Assert.AreEqual("TestApples 99% off: -�.01", basket.Messages[0]);
        }
コード例 #3
0
        public void TestOffersHaveImplementedCorrectMethod()
        {
            var config = new PriceCalculatorConfiguration();
            var goods  = config.AvailableGoodsItems;
            var offers = config.AvailableOffers;

            foreach (var offer in offers)
            {
                if (offer.Discount.DiscountType == DiscountType.SingleItem)
                {
                    offer.Discount.GetDiscount(new BasketItem(goods[0], offer.Discount));
                    Assert.Throws <NotImplementedException>(() =>
                                                            offer.Discount.GetGroupDiscount(new BasketItem(goods[0], offer.Discount),
                                                                                            new List <BasketItem>()), $"Exception was not thrown when expected for offer {offer.Discount.GetType().Name} for goods item {offer.GoodsItemName}");
                }
                else if (offer.Discount.DiscountType == DiscountType.GroupItem)
                {
                    Assert.Throws <NotImplementedException>(() => offer.Discount.GetDiscount(new BasketItem(goods[0], offer.Discount))
                                                            , $"Exception was not thrown when expected for offer {offer.Discount.GetType().Name} for goods item {offer.GoodsItemName}");
                    offer.Discount.GetGroupDiscount(new BasketItem(goods[0], offer.Discount), new List <BasketItem>());
                }
            }
        }
コード例 #4
0
        public void TestThereAreNoDuplicateGoods()
        {
            var config = new PriceCalculatorConfiguration();

            Assert.AreEqual(config.AvailableGoodsItems.Count, config.AvailableGoodsItems.Select(c => c.Name).Distinct().Count(), "There are non distinct available goods items");
        }
コード例 #5
0
        public void TestThereAreAvailableGoodsItems()
        {
            var config = new PriceCalculatorConfiguration();

            Assert.Greater(config.AvailableGoodsItems.Count, 0, "There are no goods available");
        }