コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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>()));
        }