예제 #1
0
        public void RelationalOperatorTypePromotion()
        {
            IEdmModel model = QueryTestMetadata.BuildTestMetadata(this.PrimitiveTypeResolver, this.StronglyTypedDataServiceProviderFactory);

            BinaryOperatorKind[] relationalOperatorKinds = new BinaryOperatorKind[]
            {
                BinaryOperatorKind.Equal,
                BinaryOperatorKind.NotEqual,
                BinaryOperatorKind.GreaterThan,
                BinaryOperatorKind.GreaterThanOrEqual,
                BinaryOperatorKind.LessThan,
                BinaryOperatorKind.LessThanOrEqual
            };

            var testCases = ComputeRelationalTestCases().Concat(ComputeRelationalErrorTestCases());

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                relationalOperatorKinds,
                (testCase, relationalOperatorKind) =>
            {
                string filter = testCase.Arguments[0] + " " + QueryTestUtils.ToOperatorName(relationalOperatorKind) + " " + testCase.Arguments[1];

                string errorMessage = null;
                if (testCase.ExpectedErrorMessage != null)
                {
                    errorMessage = string.Format(CultureInfo.InvariantCulture, testCase.ExpectedErrorMessage, relationalOperatorKind);
                }

                var actualFilter = this.BindFilter(model, filter, errorMessage);

                if (errorMessage == null)
                {
                    this.Assert.IsNotNull(actualFilter, "Filter must not be null.");

                    BinaryOperatorNode binaryOperatorNode = null;
                    if (actualFilter.Expression.InternalKind == InternalQueryNodeKind.Convert)
                    {
                        binaryOperatorNode = ((ConvertNode)actualFilter.Expression).Source as BinaryOperatorNode;
                    }
                    else
                    {
                        binaryOperatorNode = actualFilter.Expression as BinaryOperatorNode;
                    }
                    this.Assert.IsNotNull(binaryOperatorNode, "Expected a binary operator at the top of the filter.");

                    QueryTestUtils.VerifyTypesAreEqual(
                        testCase.ExpectedResultType,
                        binaryOperatorNode.Left.TypeReference,
                        this.Assert);

                    QueryTestUtils.VerifyTypesAreEqual(
                        testCase.ExpectedResultType,
                        binaryOperatorNode.Right.TypeReference,
                        this.Assert);
                }
            });
        }
예제 #2
0
        public void ArithmeticOperatorTypePromotion()
        {
            var metadata = QueryTestMetadata.BuildTestMetadata(this.PrimitiveTypeResolver, this.StronglyTypedDataServiceProviderFactory);

            BinaryOperatorKind[] arithmeticOperatorKinds = new BinaryOperatorKind[]
            {
                BinaryOperatorKind.Add,
                BinaryOperatorKind.Subtract,
                BinaryOperatorKind.Multiply,
                BinaryOperatorKind.Divide,
                BinaryOperatorKind.Modulo,
            };

            var testCases = ComputeArithmeticTestCases().Concat(ComputeArithmeticErrorTestCases());

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                arithmeticOperatorKinds,
                (testCase, arithmeticOperatorKind) =>
            {
                string filter = testCase.Arguments[0] + " " + QueryTestUtils.ToOperatorName(arithmeticOperatorKind) + " " + testCase.Arguments[1] + " le 0";

                string errorMessage = null;
                if (testCase.ExpectedErrorMessage != null)
                {
                    errorMessage = string.Format(CultureInfo.InvariantCulture, testCase.ExpectedErrorMessage, arithmeticOperatorKind);
                }

                var actualFilter = this.BindFilter(metadata, filter, errorMessage);

                if (errorMessage == null)
                {
                    this.Assert.IsNotNull(actualFilter, "Filter must not be null.");

                    BinaryOperatorNode binaryOperatorNode = null;
                    if (actualFilter.Expression.InternalKind == InternalQueryNodeKind.Convert)
                    {
                        binaryOperatorNode = ((ConvertNode)actualFilter.Expression).Source as BinaryOperatorNode;
                    }
                    else
                    {
                        binaryOperatorNode = actualFilter.Expression as BinaryOperatorNode;
                    }
                    this.Assert.IsNotNull(binaryOperatorNode, "Expected a binary operator at the top of the filter.");

                    if (binaryOperatorNode.Left.InternalKind == InternalQueryNodeKind.Convert)
                    {
                        binaryOperatorNode = ((ConvertNode)binaryOperatorNode.Left).Source as BinaryOperatorNode;
                    }
                    else
                    {
                        binaryOperatorNode = binaryOperatorNode.Left as BinaryOperatorNode;
                    }
                    this.Assert.IsNotNull(binaryOperatorNode, "Expected a binary operator as the left argument of the top-level binary operator.");

                    QueryTestUtils.VerifyTypesAreEqual(
                        testCase.ExpectedResultType,
                        binaryOperatorNode.Left.TypeReference,
                        this.Assert);

                    QueryTestUtils.VerifyTypesAreEqual(
                        testCase.ExpectedResultType,
                        binaryOperatorNode.Right.TypeReference,
                        this.Assert);
                }
            });
        }