Exemplo n.º 1
0
        public void TestSqlConnectionQueryCacheViaDynamics()
        {
            // Setup
            var cache               = new MemoryCache();
            var entity              = GetIdentityTable();
            var cacheKey            = "SimpleTables";
            var cacheItemExpiration = 60;

            using (var repository = new SimpleTableRepository(cache, cacheItemExpiration))
            {
                // Act
                entity.Id = Convert.ToInt32(repository.Insert(entity));

                // Act
                var result = repository.Query((object)null,                   /* whereOrPrimaryKey */
                                              (IEnumerable <OrderField>)null, /* orderBy */
                                              (int?)null,                     /* top */
                                              (string)null,                   /* hints */
                                              cacheKey,                       /* cacheKey */
                                              (IDbTransaction)null);

                var item = cache.Get(cacheKey);

                // Assert
                Assert.AreEqual(1, result.Count());
                Assert.IsNotNull(item);
                Assert.AreEqual(cacheItemExpiration, (item.Expiration - item.CreatedDate).TotalMinutes);
            }
        }
Exemplo n.º 2
0
        public void TestSqlConnectionQueryCacheViaQueryGroup()
        {
            // Setup
            var cache               = new MemoryCache();
            var entity              = GetIdentityTable();
            var cacheKey            = "SimpleTables";
            var cacheItemExpiration = 60;

            using (var repository = new SimpleTableRepository(cache, cacheItemExpiration))
            {
                // Act
                entity.Id = Convert.ToInt32(repository.Insert(entity));

                // Act
                var result = repository.Query(where : (QueryGroup)null,
                                              orderBy: null,
                                              top: 0,
                                              hints: null,
                                              cacheKey: cacheKey,
                                              transaction: null);
                var item = cache.Get(cacheKey);

                // Assert
                Assert.AreEqual(1, result.Count());
                Assert.IsNotNull(item);
                Assert.AreEqual(cacheItemExpiration, (item.Expiration - item.CreatedDate).TotalMinutes);
            }
        }