Пример #1
0
        public bool Equals(OeCacheContext x, OeCacheContext y)
        {
            var comparer = new OeCacheComparer(x.ConstantToParameterMapper);

            if (comparer.Compare(x, y))
            {
                y.ParameterValues = comparer.ParameterValues;
                return(true);
            }

            return(false);
        }
        public bool Equals(OeCacheContext x, OeCacheContext y)
        {
            var comparer = new OeCacheComparer(x.ConstantToParameterMapper, x.NavigationNextLink);

            if (comparer.Compare(x, y))
            {
                y.ParameterValues = comparer.ParameterValues;
                return(true);
            }

            y.ParameterValues = null;
            return(false);
        }
        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);
                }
            }
        }
        //[Fact]
        public void CacheCode()
        {
            var hashes = new Dictionary <int, List <String> >();

            SelectTestDefinition[] requestMethodNames = SelectTestDefinition.GetSelectTestDefinitions();

            var fixture = new RDBNull_DbFixtureInitDb();

            for (int i = 0; i < requestMethodNames.Length; i++)
            {
                var queryContext = new OeQueryContext(fixture.OeEdmModel, fixture.ParseUri(requestMethodNames[i].Request));
                int hash         = OeCacheComparer.GetCacheCode(queryContext.CreateCacheContext());
                if (!hashes.TryGetValue(hash, out List <String> value))
                {
                    value = new List <String>();
                    hashes.Add(hash, value);
                }
                value.Add(requestMethodNames[i].MethodName);
            }

            var duplicate = hashes.Where(p => p.Value.Count > 1).Select(p => p.Value).ToArray();
        }
        public bool Equals([AllowNull] OeCacheContext x, [AllowNull] OeCacheContext y)
        {
            if (Object.ReferenceEquals(x, y))
            {
                return(true);
            }

            if (x == null || y == null)
            {
                return(false);
            }

            var comparer = new OeCacheComparer(x.ConstantToParameterMapper);

            if (comparer.Compare(x, y))
            {
                y.ParameterValues = comparer.ParameterValues;
                return(true);
            }

            return(false);
        }
        //[Fact]
        public void CacheCode()
        {
            var hashes = new Dictionary <int, List <String> >();

            SelectTestDefinition[] requestMethodNames = SelectTestDefinition.GetSelectTestDefinitions();

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

            for (int i = 0; i < requestMethodNames.Length; i++)
            {
                OeQueryContext queryContext = parser.CreateQueryContext(fixture.ParseUri(requestMethodNames[i].Request), 0, false, OeMetadataLevel.Minimal);
                int            hash         = OeCacheComparer.GetCacheCode(queryContext.CreateCacheContext());
                if (!hashes.TryGetValue(hash, out List <String> value))
                {
                    value = new List <String>();
                    hashes.Add(hash, value);
                }
                value.Add(requestMethodNames[i].MethodName);
            }

            var duplicate = hashes.Where(p => p.Value.Count > 1).Select(p => p.Value).ToArray();
        }
Пример #7
0
 public int GetHashCode(OeCacheContext obj)
 {
     return(OeCacheComparer.GetCacheCode(obj));
 }