AccidentalFish.ApplicationSupport.Azure.Tests.Unit.Configuration.AsyncKeyVaultConfigurationTests.ExpiresItemsInCache C# (CSharp) Method

ExpiresItemsInCache() private method

private ExpiresItemsInCache ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
        public async Task ExpiresItemsInCache()
        {
            Mock<IKeyVault> keyVault = new Mock<IKeyVault>();
            Mock<IKeyVaultConfigurationKeyEncoder> keyVaultEncoder = new Mock<IKeyVaultConfigurationKeyEncoder>();
            Mock<IAsyncConfiguration> asyncConfiguration = new Mock<IAsyncConfiguration>();

            keyVaultEncoder.Setup(x => x.Encode("mykey")).Returns("mykey");
            asyncConfiguration.Setup(x => x.GetAsync("mykey")).ReturnsAsync("incache");

            AsyncKeyVaultConfiguration asyncKeyVaultConfiguration = new AsyncKeyVaultConfiguration(
                keyVault.Object,
                keyVaultEncoder.Object,
                new KeyVaultConfigurationCachePolicy
                {
                    CachingEnabled = true,
                    ExpiresAfter = TimeSpan.FromMilliseconds(500)
                },
                asyncConfiguration.Object);

            await asyncKeyVaultConfiguration.GetAsync("mykey");
            await Task.Delay(TimeSpan.FromMilliseconds(600));
            string result = await asyncKeyVaultConfiguration.GetAsync("mykey");
            Assert.AreEqual("incache", result);
            asyncConfiguration.Verify(x => x.GetAsync("mykey"), Times.Exactly(2));
        }
    }