コード例 #1
0
        public void TestSqlConnectionQueryAllAsyncCache()
        {
            // 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.QueryAllAsync(orderBy: null,
                                                      cacheKey: cacheKey,
                                                      transaction: null).Result;
                var item = cache.Get(cacheKey);

                // Assert
                Assert.AreEqual(1, result.Count());
                Assert.IsNotNull(item);
                Assert.AreEqual(cacheItemExpiration, (item.Expiration - item.CreatedDate).TotalMinutes);
            }
        }
コード例 #2
0
        public void TestSqlConnectionQueryAsyncCacheViaDynamics()
        {
            // 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.QueryAsync((object)null,                   /* whereOrPrimaryKey */
                                                   (IEnumerable <OrderField>)null, /* orderBy */
                                                   (int?)null,                     /* top */
                                                   (string)null,                   /* hints */
                                                   cacheKey,                       /* cacheKey */
                                                   (IDbTransaction)null).Result;

                var item = cache.Get(cacheKey);

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