public void LoadFromUnderlyingStoreIfNotCached() { var aggregate = new FakeAggregate(); var decoratedAggregateStore = new Mock<IStoreAggregates>(); var memoryCache = new MemoryCache(Guid.NewGuid().ToString()); var cachedAggregateStore = new CachedAggregateStore(decoratedAggregateStore.Object, TimeSpan.FromMinutes(1), memoryCache); decoratedAggregateStore.Setup(mock => mock.Get(typeof(FakeAggregate), aggregate.Id)).Returns(aggregate); cachedAggregateStore.Get(typeof(FakeAggregate), aggregate.Id); decoratedAggregateStore.Verify(mock => mock.Get(typeof(FakeAggregate), aggregate.Id), Times.Once()); }
public void LoadFromUnderlyingStoreIfNotCached() { var aggregate = new FakeAggregate(); var decoratedAggregateStore = new Mock <IStoreAggregates>(); var memoryCache = new MemoryCache(Guid.NewGuid().ToString()); var cachedAggregateStore = new CachedAggregateStore(decoratedAggregateStore.Object, TimeSpan.FromMinutes(1), memoryCache); decoratedAggregateStore.Setup(mock => mock.Get(typeof(FakeAggregate), aggregate.Id)).Returns(aggregate); cachedAggregateStore.Get(typeof(FakeAggregate), aggregate.Id); decoratedAggregateStore.Verify(mock => mock.Get(typeof(FakeAggregate), aggregate.Id), Times.Once()); }
public void UseCachedAggregateIfAvailable() { var aggregate = new FakeAggregate(); var decoratedAggregateStore = new Mock<IStoreAggregates>(); var memoryCache = new MemoryCache(Guid.NewGuid().ToString()); var cachedAggregateStore = new CachedAggregateStore(decoratedAggregateStore.Object, TimeSpan.FromMinutes(1), memoryCache); memoryCache.Add(aggregate.CacheKey, aggregate, new CacheItemPolicy()); Assert.Same(aggregate, cachedAggregateStore.Get(typeof(FakeAggregate), aggregate.Id)); decoratedAggregateStore.Verify(mock => mock.Get(typeof(FakeAggregate), aggregate.Id), Times.Never()); }
public void UseCachedAggregateIfAvailable() { var aggregate = new FakeAggregate(); var decoratedAggregateStore = new Mock <IStoreAggregates>(); var memoryCache = new MemoryCache(Guid.NewGuid().ToString()); var cachedAggregateStore = new CachedAggregateStore(decoratedAggregateStore.Object, TimeSpan.FromMinutes(1), memoryCache); memoryCache.Add(aggregate.CacheKey, aggregate, new CacheItemPolicy()); Assert.Same(aggregate, cachedAggregateStore.Get(typeof(FakeAggregate), aggregate.Id)); decoratedAggregateStore.Verify(mock => mock.Get(typeof(FakeAggregate), aggregate.Id), Times.Never()); }