public async Task CacheAsync_CalledWithKeyAndValue_CallsStoreInImplementation() { await Cache.CacheAsync(User.Test); CacheImplementationMock .Verify(i => i.CacheAsync(KEY, User.Test, It.IsAny <CacheOptions>()), Times.Once); }
public async Task RetrieveAsync_CalledWithKey_CallsRetrieveInImplementation() { var result = await Cache.RetrieveAsync <User>(KEY); CacheImplementationMock .Verify(i => i.RetrieveAsync <User>(KEY), Times.Once); }
public async Task RetrieveAsync_MissingConfiguration_ThrowsException() { Func <Task> cacheAsync = async() => await Cache.CacheAsync(Order.Test); await cacheAsync.Should().ThrowAsync <ConfigurationNotFoundException>(); CacheImplementationMock .Verify(i => i.CacheAsync(It.IsAny <string>(), It.IsAny <User>(), It.IsAny <CacheOptions>()), Times.Never); }
public async Task RetrieveAsync_MissingConfiguration_ThrowsException() { Func <Task <Order> > retrieveAsync = async() => await Cache.RetrieveAsync <Order>(new { Id = 1, LastName = "Test" }); await retrieveAsync.Should().ThrowAsync <ConfigurationNotFoundException>(); CacheImplementationMock .Verify(i => i.RetrieveAsync <Order>(It.IsAny <string>()), Times.Never); }
public async Task CacheAsync_GenericImplementation_UsesGenericCache() { var cache = CacheBuilder .For <User>(u => u.UseAsKey(KEY).Complete()) .Build(); await cache.CacheAsync(User.Test); CacheImplementationMock .Verify(i => i.CacheAsync(KEY, User.Test, It.IsAny <CacheOptions>()), Times.Once); }
public async Task CacheAsync_SpecificImplementation_UsesSpecificCache() { var cache = CacheBuilder .For <User>(u => u.UseAsKey(KEY).Complete(_userSpecificImplementationMock.Object)) .Build(); await cache.CacheAsync(User.Test); _userSpecificImplementationMock .Verify(i => i.CacheAsync(KEY, User.Test, It.IsAny <CacheOptions>()), Times.Once); CacheImplementationMock .Verify(i => i.CacheAsync(It.IsAny <string>(), It.IsAny <User>(), It.IsAny <CacheOptions>()), Times.Never); }
public async Task RetrieveOrStoreAsync_ValueIsInCache_ReturnsCachedValue() { await Cache.CacheAsync(User.Test); var entityFetcherMock = new Mock <Func <string, Task <User> > >(); CacheImplementationMock .Setup(i => i.RetrieveAsync <User>(KEY)) .ReturnsAsync(User.Test); var result = await Cache.RetrieveOrStoreAsync(KEY, entityFetcherMock.Object); result.Should().Be(User.Test); entityFetcherMock.Verify(f => f(It.IsAny <string>()), Times.Never); }