Exemple #1
0
        public void CartPredicateCustomField()
        {
            Expression <Func <Cart, bool> >     expression = c => c.LineItemCount(l => l.Custom.Fields["age"].ToString() == "adult") >= 2 && c.LineItemCount(l => l.Custom.Fields["age"].ToString() == "youth") >= 1;
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("lineItemCount(custom.age = \"adult\") >= 2 and lineItemCount(custom.age = \"youth\") >= 1", result);
        }
Exemple #2
0
        public void CustomLineItemPredicateCustomFieldReferenceType()
        {
            Expression <Func <CustomLineItem, bool> > expression = c => c.Custom.Fields["reference-field"].ToString() == "bac1a3a5-3807-4f5b-9d07-0611984ecae8";
            IDiscountPredicateExpressionVisitor       cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("custom.`reference-field` = \"bac1a3a5-3807-4f5b-9d07-0611984ecae8\"", result);
        }
Exemple #3
0
        public void CartPredicateCustomTypeId()
        {
            Expression <Func <Cart, bool> >     expression = c => c.Custom.Type.Id == "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7";
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("custom.type.id = \"f6a19a23-14e3-40d0-aee2-3e612fcb1bc7\"", result);
        }
Exemple #4
0
        public void CustomLineItemPredicateCustomFieldStartWithNumber()
        {
            Expression <Func <CustomLineItem, bool> > expression = c => c.Custom.Fields["4brand"].ToString() == "adidas";
            IDiscountPredicateExpressionVisitor       cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("custom.`4brand` = \"adidas\"", result);
        }
Exemple #5
0
        public void CustomLineItemPredicateCustomFieldMoneyCentAmount()
        {
            Expression <Func <CustomLineItem, bool> > expression = c => c.Custom.Fields["price"].ToMoney().CentAmount == 18;
            IDiscountPredicateExpressionVisitor       cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("custom.price.centAmount = 18", result);
        }
Exemple #6
0
        public void LineItemPredicateCategoriesIdNotEqual()
        {
            Expression <Func <LineItem, bool> > expression = l => l.CategoriesId().IsNotIn("f6a19a23-14e3-40d0-aee2-3e612fcb1bc7");
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("categories.id != (\"f6a19a23-14e3-40d0-aee2-3e612fcb1bc7\")", result);
        }
Exemple #7
0
        public void CustomLineItemPredicateMoneyAndTaxRate()
        {
            Expression <Func <CustomLineItem, bool> > expression = c => c.Money > Money.FromDecimal("EUR", 10.51M, MidpointRounding.ToEven).moneyString() && c.TaxRate.IncludedInPrice == false;
            IDiscountPredicateExpressionVisitor       cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("money > \"10.51 EUR\" and taxRate.includedInPrice = false", result);
        }
Exemple #8
0
        public void LineItemPredicateMoneyAttributeCast()
        {
            Expression <Func <LineItem, bool> > expression = l => l.Attributes().Any(a => a.Name == "money" && a.ToMoneyAttribute().Value >= Money.FromDecimal("EUR", 18, MidpointRounding.ToEven).moneyString());
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("attributes.money >= \"18 EUR\"", result);
        }
Exemple #9
0
        public void LineItemPredicateTextAttributeCaseSensitive()
        {
            Expression <Func <LineItem, bool> > expression = l => l.Attributes().Any(a => a.Name == "Color" && ((TextAttribute)a).Value == "Green");
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("attributes.Color = \"Green\"", result);
        }
Exemple #10
0
        public void LineItemPredicateVariantId()
        {
            Expression <Func <LineItem, bool> > expression = l => l.VariantId() == 123;
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("variant.id = 123", result);
        }
Exemple #11
0
        public void LineItemPredicateVariantKey()
        {
            Expression <Func <LineItem, bool> > expression = l => l.VariantKey() == "blue_shirt";
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("variant.key = \"blue_shirt\"", result);
        }
Exemple #12
0
        public void CartPredicateCustomerInformation()
        {
            Expression <Func <Cart, bool> >     expression = c => c.Customer().Email == "*****@*****.**" && c.Customer().CustomerGroup.Id == "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7";
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("customer.email = \"[email protected]\" and customer.customerGroup.id = \"f6a19a23-14e3-40d0-aee2-3e612fcb1bc7\"", result);
        }
Exemple #13
0
        public void LineItemCountByProductIdGreaterThanTen()
        {
            Expression <Func <Cart, bool> >     expression = c => c.LineItemCount(l => l.ProductId == "45224437-12bd-4742-830c-3a36b52541d3") > 10;
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("lineItemCount(product.id = \"45224437-12bd-4742-830c-3a36b52541d3\") > 10", result);
        }
Exemple #14
0
        public void CartPredicateTotalGross()
        {
            Expression <Func <Cart, bool> >     expression = c => c.TaxedPrice.TotalGross <= Money.FromDecimal("USD", 10, MidpointRounding.ToEven).moneyString();
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("taxedPrice.gross <= \"10 USD\"", result);
        }
Exemple #15
0
        public void LineItemPredicateGrouping()
        {
            Expression <Func <LineItem, bool> > expression = l => l.ProductType.Id == "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7" && l.Attributes().Any(a => a.Name == "rating" && ((NumberAttribute)a).Value > 3) && (l.ProductId == "abcd9a23-14e3-40d0-aee2-3e612fcbefgh" || l.ProductId == "ba3e4ee7-30fa-400b-8155-46ebf423d793");
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("productType.id = \"f6a19a23-14e3-40d0-aee2-3e612fcb1bc7\" and attributes.rating > 3 and (product.id = \"abcd9a23-14e3-40d0-aee2-3e612fcbefgh\" or product.id = \"ba3e4ee7-30fa-400b-8155-46ebf423d793\")", result);
        }
Exemple #16
0
        public void CartPredicateCountryIsDefined()
        {
            Expression <Func <Cart, bool> >     expression = c => c.Country.IsDefined();
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("country is defined", result);
        }
Exemple #17
0
        public void LineItemPredicateCustomField()
        {
            Expression <Func <LineItem, bool> > expression = l => l.Custom.Fields["gender"].ToString() == "alien";
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("custom.gender = \"alien\"", result);
        }
Exemple #18
0
        public void LineItemCountTrueGreaterThanTen()
        {
            Expression <Func <Cart, bool> >     expression = c => c.LineItemCount(true) > 10;
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("lineItemCount(true) > 10", result);
        }
Exemple #19
0
        public void LineItemCountWithPredicate()
        {
            Expression <Func <Cart, bool> >     expression = c => c.LineItemCount(l => l.Attributes().Any(a => a.Name == "size" && a.ToTextAttribute().Value.In("xxl", "xl"))) == 2;
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("lineItemCount(attributes.size in (\"xxl\", \"xl\")) = 2", result);
        }
Exemple #20
0
        public void LineItemPredicateEnumSetContainsAnyAttribute()
        {
            Expression <Func <LineItem, bool> > expression = l => l.Attributes().Any(a => a.Name == "colors" && ((SetEnumAttribute)a).Value.Select(e => e.Key).ContainsAny("green", "blue"));
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("attributes.colors contains any (\"green\", \"blue\")", result);
        }
Exemple #21
0
        public void CustomLineItemPredicateSlug()
        {
            Expression <Func <CustomLineItem, bool> > expression = c => c.Slug == "adidas-superstar-2";
            IDiscountPredicateExpressionVisitor       cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("slug = \"adidas-superstar-2\"", result);
        }
Exemple #22
0
        public void LineItemPredicatePriceCentAmount()
        {
            Expression <Func <LineItem, bool> > expression = l => l.Price.Value.CentAmount == 1000;
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("price.centAmount = 1000", result);
        }
Exemple #23
0
        public void CustomLineItemPredicateCustomFieldMoney()
        {
            Expression <Func <CustomLineItem, bool> > expression = c => c.Custom.Fields["price"].ToString() == "18.00 EUR";
            IDiscountPredicateExpressionVisitor       cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("custom.price = \"18.00 EUR\"", result);
        }
Exemple #24
0
        public void LineItemPredicatePriceDiscountId()
        {
            Expression <Func <LineItem, bool> > expression = l => l.Price.DiscountId() == "45224437-12bd-4742-830c-3a36b52541d3";
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("price.discount.id = \"45224437-12bd-4742-830c-3a36b52541d3\"", result);
        }
Exemple #25
0
        public void LineItemPredicatePriceNot()
        {
            Expression <Func <LineItem, bool> > expression = l => !(l.Price.Value == Money.FromDecimal("EUR", 10, MidpointRounding.ToEven).moneyString());
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("not(price = \"10 EUR\")", result);
        }
Exemple #26
0
        public void LineItemPredicatePriceCustomerGroupKey()
        {
            Expression <Func <LineItem, bool> > expression = l => l.Price.CustomerGroupKey() == "key123";
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("price.customerGroup.key = \"key123\"", result);
        }
Exemple #27
0
        public void CustomLineItemPredicateCustomFieldReferenceTypeInCollection()
        {
            Expression <Func <CustomLineItem, bool> > expression = c => c.Custom.Fields["reference-field"].ContainsAny("bac1a3a5-3807-4f5b-9d07-0611984ecae8", "f6a19a23-14e3-40d0-aee2-3e612fcb1bc7");
            IDiscountPredicateExpressionVisitor       cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("custom.`reference-field` contains any (\"bac1a3a5-3807-4f5b-9d07-0611984ecae8\", \"f6a19a23-14e3-40d0-aee2-3e612fcb1bc7\")", result);
        }
Exemple #28
0
        public void LineItemPredicateSkuAndTaxRate()
        {
            Expression <Func <LineItem, bool> > expression = l => l.Sku() == "SKU-123" && l.TaxRate.IncludedInPrice == false;
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("sku = \"SKU-123\" and taxRate.includedInPrice = false", result);
        }
Exemple #29
0
        public void CartPredicateCurrency()
        {
            Expression <Func <Cart, bool> >     expression = c => c.Currency() == "EUR";
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("currency = \"EUR\"", result);
        }
Exemple #30
0
        public void CartPredicateCustomTypeKey()
        {
            Expression <Func <Cart, bool> >     expression = c => c.CustomTypeKey() == "my-category";
            IDiscountPredicateExpressionVisitor cartPredicateExpressionVisitor = this.linqFixture.GetService <IDiscountPredicateExpressionVisitor>();
            var result = cartPredicateExpressionVisitor.Render(expression);

            Assert.Equal("custom.type.key = \"my-category\"", result);
        }