예제 #1
0
        public void Calculate_coupon_and_product_campaign_tests()
        {
            ICartWithCouponPriceAggregate cartWithCouponPriceAggregate = Resolve <ICartWithCouponPriceAggregate>();

            var cart = EmptyCardData();

            cart.Coupons = new List <Coupon>
            {
                new Coupon
                {
                    Amount   = 2,
                    Discount = 0.9M,
                }
            };

            cart.ProductTransactions[0].Product.Campaigns = new List <Campaign>
            {
                new Campaign
                {
                    Discount = 0.9M,
                    Type     = CampaignType.Rate,
                }
            };

            var actualPrice = cartWithCouponPriceAggregate.Calculate(cart);

            Assert.Equal(219.9888M, actualPrice);
        }
예제 #2
0
        public void Calculate_no_campaign_no_coupon_tests()
        {
            ICartWithCouponPriceAggregate cartWithCouponPriceAggregate = Resolve <ICartWithCouponPriceAggregate>();

            var actualPrice = cartWithCouponPriceAggregate.Calculate(EmptyCardData());

            Assert.Equal(250.43M, actualPrice);
        }
예제 #3
0
        public void Calculate_coupon_amount_tests()
        {
            ICartWithCouponPriceAggregate cartWithCouponPriceAggregate = Resolve <ICartWithCouponPriceAggregate>();

            var cart = EmptyCardData();

            cart.Coupons = new List <Coupon>
            {
                new Coupon
                {
                    Amount   = 2,
                    Discount = 0.9M,
                }
            };

            var actualPrice = cartWithCouponPriceAggregate.Calculate(cart);

            Assert.Equal(225.387M, actualPrice);
        }
예제 #4
0
        static void Main(string[] args)
        {
            ContainerHelper.Install();

            Category category = new Category
            {
                Title = "food",
            };

            Product apple = new Product
            {
                Title     = "Apple",
                Price     = 100.0M,
                Category  = category,
                Campaigns = new List <Campaign>
                {
                    new Campaign
                    {
                        Type     = CampaignType.Price,
                        Discount = 2 // 2 tl indirim
                    }
                }
            };

            Product almond = new Product
            {
                Title    = "Almonds",
                Price    = 150.0M,
                Category = category
            };

            Cart shoppingCard = new Cart
            {
                ProductTransactions = new List <ProductTransaction>
                {
                    new ProductTransaction
                    {
                        Product  = apple,
                        Quantity = 5,
                    },
                    new ProductTransaction
                    {
                        Product  = almond,
                        Quantity = 4,
                    },
                },
                Coupons = new List <Coupon>
                {
                    new Coupon
                    {
                        Amount   = 1,
                        Discount = 0.9M
                    }
                }
            };

            ICartWithCouponPriceAggregate cartWithCouponPriceAggregate = ContainerHelper.Resolve <ICartWithCouponPriceAggregate>();
            IDeliveryCostAggregate        deliveryCostAggregate        = ContainerHelper.Resolve <IDeliveryCostAggregate>();

            Console.WriteLine(string.Format("sepetteki ürünlerin toplam fiyatı: {0} tl", cartWithCouponPriceAggregate.Calculate(shoppingCard)));
            Console.WriteLine(string.Format("sepetteki ürünlerin teslimat ücreti: {0} tl", deliveryCostAggregate.Calculate(shoppingCard)));
        }