public void Test()
        {
            SelectTestDefinition[] requestMethodNames = SelectTestDefinition.GetSelectTestDefinitions();
            requestMethodNames = requestMethodNames.Where(t => t.MethodName == "FilterEnum" || t.MethodName == "FilterEnumNull").ToArray();

            var fixture = new DbFixtureInitDb();
            var parser  = new OeGetParser(fixture.OeDataAdapter, fixture.EdmModel);

            for (int i = 0; i < requestMethodNames.Length; i++)
            {
                OeQueryContext queryContext1 = parser.CreateQueryContext(fixture.ParseUri(requestMethodNames[i].Request), 0, false, OeMetadataLevel.Minimal);
                OeQueryContext queryContext2 = parser.CreateQueryContext(fixture.ParseUri(requestMethodNames[i].Request), 0, false, OeMetadataLevel.Minimal);

                var constantToParameterMapper = new FakeReadOnlyDictionary <ConstantNode, Db.OeQueryCacheDbParameterDefinition>();
                if (queryContext1.ODataUri.Skip != null)
                {
                    var constantNode = OeCacheComparerParameterValues.CreateSkipConstantNode((int)queryContext1.ODataUri.Skip.Value, queryContext1.ODataUri.Path);
                    constantToParameterMapper.Add(constantNode, new Db.OeQueryCacheDbParameterDefinition("p_0", typeof(int)));
                }
                if (queryContext1.ODataUri.Top != null)
                {
                    var constantNode = OeCacheComparerParameterValues.CreateTopConstantNode((int)queryContext1.ODataUri.Top.Value, queryContext1.ODataUri.Path);
                    constantToParameterMapper.Add(constantNode, new Db.OeQueryCacheDbParameterDefinition($"p_{constantToParameterMapper.Count}", typeof(int)));
                }

                OeCacheContext cacheContext1 = queryContext1.CreateCacheContext();
                OeCacheContext cacheContext2 = queryContext2.CreateCacheContext();
                bool           result        = new OeCacheComparer(constantToParameterMapper, false).Compare(cacheContext1, cacheContext2);
                Assert.True(result);

                for (int j = i + 1; j < requestMethodNames.Length; j++)
                {
                    queryContext2 = parser.CreateQueryContext(fixture.ParseUri(requestMethodNames[j].Request), 0, false, OeMetadataLevel.Minimal);

                    constantToParameterMapper = new FakeReadOnlyDictionary <ConstantNode, Db.OeQueryCacheDbParameterDefinition>();
                    result = new OeCacheComparer(constantToParameterMapper, false).Compare(cacheContext1, cacheContext2);
                    Assert.False(result);
                }
            }
        }
Ejemplo n.º 2
0
        public void Test()
        {
            SelectTestDefinition[] requestMethodNames = TestHelper.GetSelectTestDefinitions();
            requestMethodNames = requestMethodNames.Where(t => t.MethodName == "FilterEnum" || t.MethodName == "FilterEnumNull").ToArray();

            var fixture = new DbFixtureInitDb();
            var baseUri = new Uri("http://dummy/");
            var parser  = new OeGetParser(baseUri, fixture.OeDataAdapter, fixture.EdmModel);

            for (int i = 0; i < requestMethodNames.Length; i++)
            {
                OeParseUriContext parseUriContext1 = parser.ParseUri(fixture.ParseUri(requestMethodNames[i].Request));
                OeParseUriContext parseUriContext2 = parser.ParseUri(fixture.ParseUri(requestMethodNames[i].Request));

                var constantToParameterMapper = new FakeReadOnlyDictionary <ConstantNode, Db.OeQueryCacheDbParameterDefinition>();
                if (parseUriContext1.ODataUri.Skip != null)
                {
                    var constantNode = OeODataUriComparerParameterValues.CreateSkipConstantNode((int)parseUriContext1.ODataUri.Skip.Value, parseUriContext1.ODataUri.Path);
                    constantToParameterMapper.Add(constantNode, new Db.OeQueryCacheDbParameterDefinition("p_0", typeof(int)));
                }
                if (parseUriContext1.ODataUri.Top != null)
                {
                    var constantNode = OeODataUriComparerParameterValues.CreateTopConstantNode((int)parseUriContext1.ODataUri.Top.Value, parseUriContext1.ODataUri.Path);
                    constantToParameterMapper.Add(constantNode, new Db.OeQueryCacheDbParameterDefinition($"p_{constantToParameterMapper.Count}", typeof(int)));
                }

                bool result = new OeODataUriComparer(constantToParameterMapper).Compare(parseUriContext1, parseUriContext2);
                Assert.True(result);

                for (int j = i + 1; j < requestMethodNames.Length; j++)
                {
                    parseUriContext2 = parser.ParseUri(fixture.ParseUri(requestMethodNames[j].Request));

                    constantToParameterMapper = new FakeReadOnlyDictionary <ConstantNode, Db.OeQueryCacheDbParameterDefinition>();
                    result = new OeODataUriComparer(constantToParameterMapper).Compare(parseUriContext1, parseUriContext2);
                    Assert.False(result);
                }
            }
        }