Exemple #1
0
        public async Task ShouldCacheWithKey()
        {
            // Arrange
            string key      = "key";
            string value    = "value";
            string newKey   = "newKey";
            string newValue = "newValue";
            var    cacheQueryHandlerDecorator = new InMemoryCacheQueryHandlerDecorator <FooQuery, string>(new FooQueryHandler(), cache, queryInfoProvider, new NullLoggerFactory());
            var    fooQuery = new FooQuery {
                ValueToCache = value, CacheKey = key
            };

            // Act
            var result = await cacheQueryHandlerDecorator
                         .Handle(fooQuery, Util.Context);

            // Assert
            Assert.Equal(result.Result, value);

            // Arrange
            // result should be old value for same key
            fooQuery.ValueToCache = newValue;

            // Act
            result = await cacheQueryHandlerDecorator
                     .Handle(fooQuery, Util.Context);

            // Assert
            Assert.Equal(result.Result, value);

            // result should be new value for new key

            // Arrange
            fooQuery.ValueToCache = newValue;
            fooQuery.CacheKey     = newKey;

            // Act
            result = await cacheQueryHandlerDecorator
                     .Handle(fooQuery, Util.Context);

            // Assert
            Assert.Equal(result.Result, newValue);
        }
Exemple #2
0
        public async Task ShouldCacheExpireInSecondsDuration()
        {
            // Arrange
            var cacheQueryHandlerDecorator = new InMemoryCacheQueryHandlerDecorator <FooQuery, string>(new FooQueryHandler(), cache, queryInfoProvider, new NullLoggerFactory());

            string oldValue = "foo";
            string newValue = "fooNew";

            var fooQuery = new FooQuery {
                ValueToCache = oldValue, CacheKey = "key"
            };

            var result = await cacheQueryHandlerDecorator
                         .Handle(fooQuery, Util.Context);

            // Assert
            Assert.Equal(result.Result, oldValue);

            // Arrange
            fooQuery.ValueToCache = newValue;

            // Act
            result = await cacheQueryHandlerDecorator
                     .Handle(fooQuery, Util.Context);

            // Assert
            Assert.Equal(result.Result, oldValue);

            // Arrange
            Thread.Sleep(new TimeSpan(0, 0, 3));

            // Act
            result = await cacheQueryHandlerDecorator
                     .Handle(fooQuery, Util.Context);

            // Assert
            Assert.Equal(result.Result, newValue);
        }
Exemple #3
0
 public FooCacheKeyProvider(FooQuery query, RequestContext context)
 {
     this.query = query;
 }