コード例 #1
0
        public void TestBaseRepositoryQueryCachingWithoutExpression()
        {
            // Prepare
            var cache               = new Mock <ICache>();
            var cacheKey            = "MemoryCacheKey";
            var cacheItemExpiration = 60;
            var repository          = new CacheEntityRepository(cache.Object, cacheItemExpiration);

            // Act
            repository.Query(where : (QueryGroup)null,
                             orderBy: null,
                             top: 0,
                             hints: null,
                             cacheKey: cacheKey,
                             transaction: null);

            // Assert
            cache.Verify(c => c.Get(It.Is <string>(s => s == cacheKey),
                                    It.IsAny <bool>()), Times.Once);
            cache.Verify(c => c.Add(It.Is <string>(s => s == cacheKey),
                                    It.IsAny <object>(),
                                    It.Is <int>(i => i == cacheItemExpiration),
                                    It.IsAny <bool>()), Times.Once);
        }
コード例 #2
0
        public void TestBaseRepositoryQueryCachingViaDynamics()
        {
            // Prepare
            var cache               = new Mock <ICache>();
            var cacheKey            = "MemoryCacheKey";
            var cacheItemExpiration = 60;
            var repository          = new CacheEntityRepository(cache.Object, cacheItemExpiration);

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

            // Assert
            cache.Verify(c => c.Get(It.Is <string>(s => s == cacheKey),
                                    It.IsAny <bool>()), Times.Once);
            cache.Verify(c => c.Add(It.Is <string>(s => s == cacheKey),
                                    It.IsAny <object>(),
                                    It.Is <int>(i => i == cacheItemExpiration),
                                    It.IsAny <bool>()), Times.Once);
        }
コード例 #3
0
        public void TestBaseRepositoryQueryAsyncCachingViaQueryFields()
        {
            // Prepare
            var cache               = new Mock <ICache>();
            var cacheKey            = "MemoryCacheKey";
            var cacheItemExpiration = 60;
            var repository          = new CacheEntityRepository(cache.Object, cacheItemExpiration);

            // Act
            var result = repository.QueryAsync(where : (IEnumerable <QueryField>)null,
                                               orderBy: null,
                                               top: 0,
                                               hints: null,
                                               cacheKey: cacheKey,
                                               transaction: null).Result;

            // Assert
            cache.Verify(c => c.Get(It.Is <string>(s => s == cacheKey),
                                    It.IsAny <bool>()), Times.Once);
            cache.Verify(c => c.Add(It.Is <string>(s => s == cacheKey),
                                    It.IsAny <object>(),
                                    It.Is <int>(i => i == cacheItemExpiration),
                                    It.IsAny <bool>()), Times.Once);
        }