Exemple #1
0
        public void AnalyseBonusText_bonusTextFromFor()
        {
            var fromPrice        = 0;
            var forPrice         = 800;
            var amountOfProducts = 1;

            BonusTextAnalyser.AnalyseBonusText("2 VOOR 4.99", ref fromPrice, ref forPrice, ref amountOfProducts);

            fromPrice.ShouldBe(800);
            forPrice.ShouldBe(249);
            amountOfProducts.ShouldBe(2);
        }
Exemple #2
0
        public void AnalyseBonusText_bonusTextSecondGratis()
        {
            var fromPrice        = 0;
            var forPrice         = 300;
            var amountOfProducts = 1;

            BonusTextAnalyser.AnalyseBonusText("1 + 1 GRATIS", ref fromPrice, ref forPrice, ref amountOfProducts);

            fromPrice.ShouldBe(300);
            forPrice.ShouldBe(150);
            amountOfProducts.ShouldBe(2);
        }
Exemple #3
0
        public void AnalyseBonusText_bonusTextPercentDeducted()
        {
            var fromPrice        = 0;
            var forPrice         = 1000;
            var amountOfProducts = 1;

            BonusTextAnalyser.AnalyseBonusText("10% korting", ref fromPrice, ref forPrice, ref amountOfProducts);

            fromPrice.ShouldBe(1000);
            forPrice.ShouldBe(900);
            amountOfProducts.ShouldBe(1);
        }
Exemple #4
0
        public void AnalyseBonusText_bonusTextSecondHalvePrice()
        {
            var fromPrice        = 0;
            var forPrice         = 800;
            var amountOfProducts = 1;

            BonusTextAnalyser.AnalyseBonusText("2e halve prijs", ref fromPrice, ref forPrice, ref amountOfProducts);

            fromPrice.ShouldBe(800);
            forPrice.ShouldBe(600);
            amountOfProducts.ShouldBe(2);
        }
Exemple #5
0
        public void AnalyseBonusText_bonusTextMoneyDeducted()
        {
            var fromPrice        = 0;
            var forPrice         = 800;
            var amountOfProducts = 1;

            BonusTextAnalyser.AnalyseBonusText("3 EURO KORTING", ref fromPrice, ref forPrice, ref amountOfProducts);

            fromPrice.ShouldBe(800);
            forPrice.ShouldBe(500);
            amountOfProducts.ShouldBe(1);
        }
Exemple #6
0
        public void AnalyseBonusText_bonusTextFromForParts()
        {
            var fromPrice        = 0;
            var forPrice         = 800;
            var amountOfProducts = 1;

            BonusTextAnalyser.AnalyseBonusText("3 STUKS 9.00", ref fromPrice, ref forPrice, ref amountOfProducts);

            fromPrice.ShouldBe(800);
            forPrice.ShouldBe(300);
            amountOfProducts.ShouldBe(3);
        }
Exemple #7
0
        public void AnalyseBonusText_bonusText2Plus2Free()
        {
            var fromPrice        = 0;
            var forPrice         = 400;
            var amountOfProducts = 1;

            BonusTextAnalyser.AnalyseBonusText("2 + 2 gratis", ref fromPrice, ref forPrice, ref amountOfProducts);

            fromPrice.ShouldBe(400);
            forPrice.ShouldBe(100);
            amountOfProducts.ShouldBe(4);
        }
Exemple #8
0
        public BonusProductEvent(JObject bonusItem)
        {
            if (bonusItem.ContainsKey("id"))
            {
                var shield = bonusItem["shield"] as JObject;
                var card   = bonusItem["card"] as JObject;

                var control = bonusItem["control"] as JObject;

                this.Year  = DateTime.Now.Year;
                this.Week  = ISOWeek.GetWeekOfYear(DateTime.Now);
                this.Title = TryAndGetField <string>(bonusItem, "title");
                if (card == null)
                {
                    this.Id   = TryAndGetField <long>(bonusItem, "id");
                    this.Link = TryAndGetField <string>(bonusItem, "link");
                }
                else
                {
                    var productOfCard = card["products"] as JArray;
                    this.Id   = TryAndGetField <long>(card, "id");
                    this.Link = TryAndGetField <string>(productOfCard[0] as JObject, "link");
                }
                this.Brand = TryAndGetField <string>(bonusItem, "brand");
                if (bonusItem.ContainsKey("discount"))
                {
                    var discount = bonusItem["discount"] as JObject;
                    var price    = bonusItem["price"] as JObject;


                    if (discount.ContainsKey("fromPrice"))
                    {
                        this.FromPriceInCents = discount["fromPrice"].Value <int>();
                    }
                    else if (price != null && price.ContainsKey("was"))
                    {
                        this.FromPriceInCents = ParseDecimalPrice(price["was"].Value <string>());
                    }

                    if (discount.ContainsKey("forPrice"))
                    {
                        this.ForPriceInCents = discount["forPrice"].Value <int>();
                    }
                    else if (price != null && price.ContainsKey("now"))
                    {
                        this.ForPriceInCents = ParseDecimalPrice(price["now"].Value <string>());
                    }

                    this.StartDate = TryAndGetField <DateTime>(discount, "startDate");
                    this.EndDate   = TryAndGetField <DateTime>(discount, "endDate");

                    if (discount.ContainsKey("text"))
                    {
                        this.DiscountText = discount["text"].Value <string>();
                    }
                    else if (shield != null && shield.ContainsKey("text"))
                    {
                        this.DiscountText = shield["text"].Value <string>();
                    }

                    this.Store = TryAndGetField <string>(control, "theme");
                    if (this.Store == null)
                    {
                        this.Store = TryAndGetField <string>(control, "bonusType");
                    }
                    if (this.Store == null || this.Store.Equals("bonus"))
                    {
                        this.Store = "ah";
                    }
                }

                this.UnitSize = TryAndGetField <string>(bonusItem, "unitSize");
                this.Category = TryAndGetField <string>(bonusItem, "category");

                this.NumberOfProducts = TryAndGetField <int>(bonusItem, "numberOfProducts");
                var fromPrice        = this.FromPriceInCents;
                var forPrice         = this.ForPriceInCents;
                var amountOfProducts = 1;
                BonusTextAnalyser.AnalyseBonusText(this.DiscountText, ref fromPrice, ref forPrice, ref amountOfProducts);
                this.FromPriceInCents         = fromPrice;
                this.ForPriceInCents          = forPrice;
                this.ActiveAtNumberOfProducts = amountOfProducts;
            }
            else
            {
                this.Id = long.MinValue;
            }
        }