Example #1
0
        public void RequestQueryParserOperatorsPrimitives()
        {
            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension("Operator", OperatorData.Values),
                new Dimension("LeftType", TypeData.Values),
                new Dimension("RightType", TypeData.Values));

            TypedCustomDataContext <AllTypes> .ClearValues();

            TypedCustomDataContext <AllTypes> .ClearHandlers();

            try
            {
                TypedCustomDataContext <AllTypes> .ValuesRequested += (x, y) =>
                {
                    ((TypedCustomDataContext <AllTypes>)x).SetValues(new object[] { new AllTypes() });
                };
                using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                {
                    request.DataServiceType = typeof(TypedCustomDataContext <AllTypes>);
                    TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
                    {
                        TypeData left  = (TypeData)values["LeftType"];
                        TypeData right = (TypeData)values["RightType"];

                        if (!left.IsTypeSupported || !right.IsTypeSupported)
                        {
                            return;
                        }

                        // Big matrix. Let's cut it down by assuming that left and right ordering does not matter.
                        if (Array.IndexOf(TypeData.Values, left) > Array.IndexOf(TypeData.Values, right))
                        {
                            return;
                        }

                        string leftName          = AllTypes.PropertyNameForType(left.ClrType);
                        string rightName         = AllTypes.PropertyNameForType(right.ClrType);
                        OperatorData o           = (OperatorData)values["Operator"];
                        string requestText       = "/Values?$filter=" + leftName + "%20" + o.Token + "%20" + rightName;
                        request.RequestUriString = requestText;
                        Exception exception      = TestUtil.RunCatching(request.SendRequest);
                        TestUtil.AssertExceptionExpected(exception,
                                                         o.IsEqualityComparison && !left.IsEqualityComparableTo(right),
                                                         o.IsOrderingComparison && !left.IsOrderComparableTo(right));
                    });
                }
            }
            finally
            {
                TypedCustomDataContext <AllTypes> .ClearValues();

                TypedCustomDataContext <AllTypes> .ClearHandlers();
            }
        }