Esempio n. 1
0
        public async Task <IEnumerable <TEntity> > Query(QueryRequest queryRequest)
        {
            var entities = QueryCache.GetEntities(queryRequest);

            if (entities != null)
            {
                return(entities);
            }
            entities = (await QueryRepository.Query(queryRequest)).ToList();
            QueryCache.Add(queryRequest, entities);
            return(entities);
        }
        public void ConverterQueryCacheTests()
        {
            IQueryCache cache = InstantiateCache();
            IConverter  cDown = new ConvertDown();
            IConverter  cUp   = new ConvertUp();

            IQueryCache convCache = ConverterCollections.GetQueryCache(cache, cUp, cDown, cUp, cDown);

            Assert.IsNotNull(convCache);
            for (int i = 0; i < 5; i++)
            {
                convCache.Add(i, i + 1);
            }
            Assert.AreEqual(convCache.Count, 5);

            IFilter filter = new EqualsFilter(IdentityExtractor.Instance, cDown.Convert("4"));

            object[] keys = convCache.GetKeys(filter);
            Assert.IsNotNull(keys);
            Assert.AreEqual(keys.Length, 1);
            Assert.AreEqual(keys[0], "3");

            filter = new GreaterEqualsFilter(IdentityExtractor.Instance, "2");
            object[] values = convCache.GetValues(filter);
            Assert.IsNotNull(values);
            Assert.AreEqual(values.Length, 4);
            values = convCache.GetValues(filter, Comparer.DefaultInvariant);
            Assert.IsNotNull(values);
            Assert.AreEqual(values.Length, 4);
            Assert.AreEqual(values[0], "2");

            object[] entries = convCache.GetEntries(filter);
            Assert.IsNotNull(entries);
            Assert.AreEqual(entries.Length, 4);
            entries = convCache.GetEntries(filter, new KeyExtractor(IdentityExtractor.Instance));
            Assert.IsNotNull(entries);
            Assert.AreEqual(entries.Length, 4);
            Assert.IsInstanceOf(typeof(ICacheEntry), entries[0]);
            ICacheEntry e = entries[0] as ICacheEntry;

            Assert.IsNotNull(e);
            Assert.AreEqual(e.Key, "1");
            Assert.AreEqual(e.Value, "2");

            Assert.IsInstanceOf(typeof(ConverterCollections.ConverterQueryCache), convCache);
            ConverterCollections.ConverterQueryCache cqc = convCache as ConverterCollections.ConverterQueryCache;
            Assert.IsNotNull(cqc);
            Assert.AreEqual(cqc.QueryCache, cache);
        }