Ejemplo n.º 1
0
        public void Test_can_map_binary_andexpression_to_one_criteria_collections()
        {
            // Arrange
            CmsqlQueryBinaryExpression orExpression = new CmsqlQueryBinaryExpression
            {
                Operator       = ConditionalOperator.And,
                LeftExpression = new CmsqlQueryCondition
                {
                    Identifier = "PageName",
                    Operator   = EqualityOperator.GreaterThan,
                    Value      = "5"
                },
                RightExpression = new CmsqlQueryCondition
                {
                    Identifier = "PageName",
                    Operator   = EqualityOperator.Equals,
                    Value      = "10"
                }
            };

            CmsqlExpressionVisitorContext context = new CmsqlExpressionVisitorContext(new ContentType());

            CmsqlExpressionVisitor cmsqlExpressionVisitor =
                new CmsqlExpressionVisitor(
                    new QueryConditionToPropertyCriteriaMapper(
                        new PropertyDataTypeResolver(new ContentType())), context);

            // Act
            cmsqlExpressionVisitor.VisitQueryExpression(orExpression);

            IEnumerable <PropertyCriteriaCollection> propertyCriteriaCollection = context.GetCriteria();

            // Assert
            propertyCriteriaCollection.Should().HaveCount(1);
        }
Ejemplo n.º 2
0
        public void Test_can_map_nested_expressions()
        {
            // Arrange
            CmsqlQueryBinaryExpression expressions = new CmsqlQueryBinaryExpression
            {
                Operator       = ConditionalOperator.Or,
                LeftExpression = new CmsqlQueryBinaryExpression
                {
                    Operator       = ConditionalOperator.Or,
                    LeftExpression = new CmsqlQueryBinaryExpression
                    {
                        Operator       = ConditionalOperator.Or,
                        LeftExpression = new CmsqlQueryCondition
                        {
                            Identifier = "PageName",
                            Operator   = EqualityOperator.Equals,
                            Value      = "1"
                        },
                        RightExpression = new CmsqlQueryBinaryExpression
                        {
                            Operator       = ConditionalOperator.Or,
                            LeftExpression = new CmsqlQueryCondition
                            {
                                Identifier = "PageName",
                                Operator   = EqualityOperator.Equals,
                                Value      = "2"
                            },
                            RightExpression = new CmsqlQueryCondition
                            {
                                Identifier = "PageName",
                                Operator   = EqualityOperator.Equals,
                                Value      = "3"
                            }
                        }
                    },
                    RightExpression = new CmsqlQueryBinaryExpression
                    {
                        Operator       = ConditionalOperator.Or,
                        LeftExpression = new CmsqlQueryCondition
                        {
                            Identifier = "PageName",
                            Operator   = EqualityOperator.Equals,
                            Value      = "4"
                        },
                        RightExpression = new CmsqlQueryCondition
                        {
                            Identifier = "PageName",
                            Operator   = EqualityOperator.Equals,
                            Value      = "5"
                        }
                    }
                },
                RightExpression = new CmsqlQueryBinaryExpression
                {
                    Operator        = ConditionalOperator.And,
                    RightExpression = new CmsqlQueryCondition
                    {
                        Identifier = "PageName",
                        Operator   = EqualityOperator.Equals,
                        Value      = "6"
                    },
                    LeftExpression = new CmsqlQueryCondition
                    {
                        Identifier = "PageName",
                        Operator   = EqualityOperator.Equals,
                        Value      = "7"
                    }
                }
            };

            CmsqlExpressionVisitorContext context = new CmsqlExpressionVisitorContext(new ContentType());

            CmsqlExpressionVisitor cmsqlExpressionVisitor =
                new CmsqlExpressionVisitor(
                    new QueryConditionToPropertyCriteriaMapper(
                        new PropertyDataTypeResolver(new ContentType())), context);

            // Act
            cmsqlExpressionVisitor.VisitQueryExpression(expressions);

            IEnumerable <PropertyCriteriaCollection> propertyCriteriaCollection = context.GetCriteria();

            // Assert
            propertyCriteriaCollection.Should().HaveCount(6);
        }