예제 #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 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);
            }
        }
예제 #3
0
        public void TestSqlConnectionQueryCacheViaExpression()
        {
            // 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 : (Expression <Func <IdentityTable, bool> >)null,
                                              orderBy: null,
                                              top: 0,
                                              hints: null,
                                              cacheKey: cacheKey,
                                              transaction: null);
                var item = cache.Get <IEnumerable <IdentityTable> >(cacheKey);

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