public async Task Given_WhenCacheMiss_ExecutesFunction() { // Arrange CacheAdapter.Setup(x => x.GetStringAsync(It.IsAny <string>())) .ReturnsAsync(string.Empty); // Act var result = await CacheManager.GetOrCreate(_key, async() => await DefaultMethod()); // Assert Assert.True(_methodCalled); Assert.IsAssignableFrom <CommunityFeatured>(result); }
public async Task Given_WhenCacheHit_CacheValueReturned() { // Arrange CacheAdapter.Setup(x => x.GetStringAsync(It.IsAny <string>())) .ReturnsAsync(JsonSerializer.Serialize(_results)); // Act var result = await CacheManager.GetOrCreate(_key, async() => await DefaultMethod()); // Assert Assert.False(_methodCalled); Assert.IsAssignableFrom <CommunityFeatured>(result); }
public async Task Given_WhenCacheMiss_SetsCache() { // Arrange CacheAdapter.Setup(x => x.GetStringAsync(It.IsAny <string>())) .ReturnsAsync(string.Empty); // Act await CacheManager.GetOrCreate(_key, async() => await DefaultMethod()); // Assert var value = JsonSerializer.Serialize(_results !); CacheAdapter.Verify(x => x.SetStringAsync(_key, value, It.IsAny <DistributedCacheEntryOptions>())); }