GetAsync() public method

public GetAsync ( string key ) : Task
key string
return Task
        public async Task GetsFromCache()
        {
            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, KeyVaultConfigurationCachePolicy.Default, asyncConfiguration.Object);

            await asyncKeyVaultConfiguration.GetAsync("mykey");
            string result = await asyncKeyVaultConfiguration.GetAsync("mykey");
            Assert.AreEqual("incache", result);
            asyncConfiguration.Verify(x => x.GetAsync("mykey"), Times.AtMostOnce);
        }
        public async Task GetsFromKeyVaultWhenMissingLocally()
        {
            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(null);
            keyVault.Setup(x => x.GetSecretAsync("mykey")).ReturnsAsync("keyvaultvalue");

            AsyncKeyVaultConfiguration asyncKeyVaultConfiguration = new AsyncKeyVaultConfiguration(keyVault.Object, keyVaultEncoder.Object, KeyVaultConfigurationCachePolicy.Default, asyncConfiguration.Object);

            string result = await asyncKeyVaultConfiguration.GetAsync("mykey");
            Assert.AreEqual("keyvaultvalue", result);
        }
        public async Task HandlesKeyVaultExceptionAsNullWhenMissingInKeyVault()
        {
            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(null);
            keyVault.Setup(x => x.GetSecretAsync("mykey")).Throws(new AggregateException(new KeyVaultClientException(HttpStatusCode.NotFound, new Uri("http://localhost"))));

            AsyncKeyVaultConfiguration asyncKeyVaultConfiguration = new AsyncKeyVaultConfiguration(keyVault.Object, keyVaultEncoder.Object, KeyVaultConfigurationCachePolicy.Default, asyncConfiguration.Object);

            string result = await asyncKeyVaultConfiguration.GetAsync("mykey");
            Assert.IsNull(result);
        }
        public async Task IgnoresCacheBasedOnPolicy()
        {
            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 = false
                },
                asyncConfiguration.Object);

            await asyncKeyVaultConfiguration.GetAsync("mykey");
            string result = await asyncKeyVaultConfiguration.GetAsync("mykey");
            Assert.AreEqual("incache", result);
            asyncConfiguration.Verify(x => x.GetAsync("mykey"), Times.Exactly(2));
        }
        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));
        }