Exemple #1
0
        [Ignore] // test case issue, request uri and service root in this case is null.
        public void RequestQueryParserTestBasicTests()
        {
            using (OpenWebDataServiceHelper.AcceptReplaceFunctionInQuery.Restore())
            {
                OpenWebDataServiceHelper.AcceptReplaceFunctionInQuery.Value = true;
                TestUtil.ClearConfiguration();

                // Repro Protocol: Filter - replace not implemented?
                // Repro Protocol: Can't cast simple primitive value in filter expression
                CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                    new Dimension("ServiceModelData", ServiceModelData.Values));

                TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
                {
                    ServiceModelData modelData = (ServiceModelData)values["ServiceModelData"];
                    object service             = Activator.CreateInstance(typeof(OpenWebDataService <>).MakeGenericType(modelData.ServiceModelType));
                    service.GetType().GetMethod("AttachHost", BindingFlags.Public | BindingFlags.Instance).Invoke(service, new object[] { new TestServiceHost2() });
                    object context  = ServiceModelData.InitializeAndGetContext(service);
                    object provider = ServiceModelData.CreateProvider(context, service);

                    if (!modelData.ContainerNames.Contains("Customers"))
                    {
                        return;
                    }

                    string customerNameProperty = modelData.IsUnitTestProvider ? "Name" : "CompanyName";
                    string integerProperty      = modelData.IsUnitTestProvider ? "ID" : "1";

                    string[] predicates = new string[]
                    {
                        "1 eq 1",
                        "1 add 1 eq 2",
                        "2 eq 1 add 1",
                        "3.5 eq 3 add 0.5",
                        "3.5 eq 3 add 0.5",
                        "1 add 2 mul 2 eq 5",
                        "(1 add 2) mul 2 eq 6",
                        "2 sub 1 eq 1",
                        "2 sub 1 add 1 ne 1",
                        "1 add 1 lt 5",
                        "1 add 1 le 2",
                        "1 add 1 ge 2",
                        "1 add 1 gt 1",
                        "1 lt " + Int64.MaxValue + "L",
                        "1 gt " + Int64.MinValue + "L",
                        ///TODO: these 2 should succeed, (double, double, single) shouldn't get -1 from
                        ///private static int CompareConversions(Type source, Type targetA, Type targetB) , this method needs some fixing.
                        ///"1 lt " + decimal.MaxValue + "00",
                        ///"1 gt " + decimal.MinValue + "00",
                        "not (1 add 1 eq 1)",
                        "1 eq 1 or 2 eq 1",
                        "1 eq 1 and 2 eq 1 add 1",
                        "1 eq 1 and not not (2 eq 1 add 1)",
                        "1 eq 0 sub -1",
                        "1 eq 0 sub - 1",
                        "0 sub 3 eq -(3)",
                        "'a' eq 'a'",
                        "'abc' eq 'abc'",
                        "'''' eq ''''",
                        "-" + integerProperty + " eq 1 sub 2",
                        customerNameProperty + " eq 'John' or 1 eq 1",
                        "10 div 2 eq 5",
                        "3 mod 2 eq 1",
                        "1 gt " + XmlConvert.ToString(10.1E-9),
                        "1 lt " + XmlConvert.ToString(10.1E+3),
                        "binary'12AABBff' eq Binary'12aabbFF'",
                        "binary'000102030405060708090A0B0C0D0E0F' eq BINARY'000102030405060708090a0b0c0d0e0f'",
                        "binary'12AABBff' ne binary'22aabbFF'",

                        // String functions.
                        "endswith('abc', 'bc')",
                        "startswith('abc', 'ab')",
                        "not startswith('abc', 'aab')",
                        "contains('abc','b')",
                        "indexof('abc', 'b') ge 1",
                        "replace('foo','o','g') eq 'fgg'",
                        "substring('123', 1) eq '23'",
                        "substring('123', 1, 1) eq '2'",
                        "tolower('ABC') eq 'abc'",
                        "toupper('AbC') eq 'ABC'",
                        "length(toupper('aBc')) eq length(tolower('aBc'))",
                        "concat('a', 'b') eq 'ab'",
                        "'a' lt 'b'",
                        "'a' le 'a'",
                        "'a' ge 'a'",
                        "'b' ge 'a'",
                        // "'a' add 'b' eq 'ab'",
                        // Repro Protocol: can't call date function in filter expressions on LinqToSql
                        "startswith(" + customerNameProperty + ", 'C')",
                        "endswith(concat(" + customerNameProperty + ", 'b'), 'b')",
                        "contains(" + customerNameProperty + ",'C')",
                        "trim(" + customerNameProperty + ") eq substring(" + customerNameProperty + ", 0)",

                        // DateTime functions.
                        "year(2007-08-08) eq 2007",
                        "month(2007-08-10) eq 08",
                        "day(2007-08-10) eq 10",
                        "hour(2007-08-10T14:11:12Z) eq 14",
                        "minute(2007-08-10T14:11:12Z) eq 11",
                        "second(2007-08-10T14:11:12Z) eq 12",

                        // Math functions.
                        "round(1.1) eq 1",
                        "round(42) eq 42",
                        "floor(1.1M) eq 1",
                        "ceiling(1.1f) eq 2",
                    };

                    if (modelData.IsUnitTestProvider)
                    {
                        // Refer to some specific types.
                        string[] customDataContextPredicates = new string[]
                        {
                            //   "(BestFriend ne null and BestFriend/Name eq 'John') or 1 eq 1",
                            "GuidValue ne 5dc82c04-570a-41f5-b48f-c8a4e436f716",
                            "GuidValue ne 5dc82c04-570a-41f5-b48f-c8a4e436f716",
                            "GuidValue ne 5dc82c04-570a-41f5-b48f-c8a4e436f716 and GuidValue ne 5dc82c04-570a-41f5-b48f-c8a4e436f716",
                            // Type functions.
                            "ID eq cast(1, 'Edm.Int32')",
                            String.Format("not isof(1, '{0}')", UnitTestsUtil.ConvertTypeNames("AstoriaUnitTests.Stubs.Customer", context)),
                            String.Format("isof('{0}')", UnitTestsUtil.ConvertTypeNames("AstoriaUnitTests.Stubs.Customer", context)),
                            String.Format("isof('{0}') and cast('{0}')/Birthday gt 1960-01-01", UnitTestsUtil.ConvertTypeNames("AstoriaUnitTests.Stubs.CustomerWithBirthday", context))
                        };

                        if (!(context is CustomRowBasedOpenTypesContext))
                        {
                            predicates = predicates.Concat(new string[] {
                                "ID eq cast(1, 'Edm.Int64')",
                                "ID eq 1L"
                            }).ToArray();
                        }

                        predicates = predicates.Concat(customDataContextPredicates).ToArray();
                    }
                    else if (context is NorthwindModel.NorthwindContext)
                    {
                        string[] northwindPredicates = new string[]
                        {
                            // Repro 602210 - Exception when filter expression contains null
                            "((((CustomerID) eq ('ALFKI')) and ((CustomerID) eq ('ANATR')))) or ((Region) ne (null))"
                        };
                        predicates = predicates.Concat(northwindPredicates).ToArray();
                    }
                    else if (context is AstoriaUnitTests.Stubs.Sql.SqlNorthwindDataContext)
                    {
                        string[] sqlNorthwindPredicates = new string[]
                        {
                            // Repro Protocol: Can't compare properties to null in LinqToSql filter expression
                            "Categories|CategoryName eq null or 1 add 1 eq 2",
                            "Categories|null eq CategoryName or 1 add 1 eq 2",

                            // Repro Protocol: error trying to use Link property in filter expression (LinqToSql)
                            //"Categories|contains('Beer',CategoryName)",
                            //"Products|contains('Beer',Categories/CategoryName)",

                            // Repro Protocol: can't call date function in filter expressions on LinqToSql
                            //"Employees|month(HireDate) eq 5",
                        };
                        predicates = sqlNorthwindPredicates;
                        // predicates = predicates.Concat(sqlNorthwindPredicates).ToArray();
                    }

                    VerifyResultsExistForWhere(service, context, "Customers", predicates);
                });
            }
        }