コード例 #1
0
        public void RemoveCallsGrain()
        {
            var key     = Guid.NewGuid().ToString();
            var factory = Mock.Of <IGrainFactory>(x => x.GetGrain <ICacheGrain>(key, null).RemoveAsync() == Task.CompletedTask);
            var clock   = new NullClock();
            var cache   = new OutkeepDistributedCache(factory, clock);

            cache.Remove(key);

            Mock.Get(factory).VerifyAll();
        }
コード例 #2
0
        public async Task RefreshAsyncCallsGrain()
        {
            var key     = Guid.NewGuid().ToString();
            var factory = Mock.Of <IGrainFactory>(x => x.GetGrain <ICacheGrain>(key, null).RefreshAsync() == Task.CompletedTask);
            var clock   = new NullClock();
            var cache   = new OutkeepDistributedCache(factory, clock);

            await cache.RefreshAsync(key).ConfigureAwait(false);

            Mock.Get(factory).VerifyAll();
        }
コード例 #3
0
        public void GetCallsGrain()
        {
            var key     = Guid.NewGuid().ToString();
            var value   = Guid.NewGuid().ToByteArray();
            var factory = Mock.Of <IGrainFactory>(x => x.GetGrain <ICacheGrain>(key, null).GetAsync() == new ValueTask <CachePulse>(new CachePulse(Guid.NewGuid(), value)));
            var clock   = new NullClock();
            var cache   = new OutkeepDistributedCache(factory, clock);

            var result = cache.Get(key);

            Assert.Same(value, result);
            Mock.Get(factory).VerifyAll();
        }
コード例 #4
0
        public async Task SetAsyncCallsGrainWithNoExpiration()
        {
            var key               = Guid.NewGuid().ToString();
            var value             = Guid.NewGuid().ToByteArray();
            var slidingExpiration = TimeSpan.FromMinutes(1);
            var factory           = Mock.Of <IGrainFactory>(x => x.GetGrain <ICacheGrain>(key, null).SetAsync(new Immutable <byte[]?>(value), null, slidingExpiration) == Task.CompletedTask);
            var clock             = new NullClock();
            var cache             = new OutkeepDistributedCache(factory, clock);

            var options = new DistributedCacheEntryOptions
            {
                SlidingExpiration = slidingExpiration
            };
            await cache.SetAsync(key, value, options).ConfigureAwait(false);

            Mock.VerifyAll();
        }
コード例 #5
0
        public void SetCallsGrain()
        {
            var key   = Guid.NewGuid().ToString();
            var value = Guid.NewGuid().ToByteArray();
            var absoluteExpiration = DateTimeOffset.UtcNow.AddHours(1);
            var slidingExpiration  = TimeSpan.FromMinutes(1);
            var factory            = Mock.Of <IGrainFactory>(x => x.GetGrain <ICacheGrain>(key, null).SetAsync(new Immutable <byte[]?>(value), absoluteExpiration, slidingExpiration) == Task.CompletedTask);
            var clock = new NullClock();
            var cache = new OutkeepDistributedCache(factory, clock);

            var options = new DistributedCacheEntryOptions
            {
                AbsoluteExpiration = absoluteExpiration,
                SlidingExpiration  = slidingExpiration
            };

            cache.Set(key, value, options);

            Mock.VerifyAll();
        }