public async Task GetTenantSpecificClientAsync_ShouldReturnClient()
        {
            var tenant = "demo";
            var config = new Mock <IConfigurationProvider>();

            config.Setup(x => x.GetTenantConfigurationAsNameValueCollectionAsync(tenant,
                                                                                 It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(GetNamevalueCollection("us-east-1"));

            var clientFactory = new KmsClientFactory(config.Object);

            var clientA = await clientFactory.GetTenantSpecificClientAsync(tenant);

            Assert.NotNull(clientA);

            //Should return same client .i.e returns client from cache
            var clientB = await clientFactory.GetTenantSpecificClientAsync(tenant);

            Assert.NotNull(clientB);
            Assert.Equal(clientA, clientB);
        }
        public async Task Process_ApplicationEvent_ShouldRemoveUnusedClients()
        {
            var tenant = "demo_tenant";
            var config = new Mock <IConfigurationProvider>();

            config.Setup(x => x.GetTenantConfigurationAsNameValueCollectionAsync(tenant,
                                                                                 It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(GetNamevalueCollection("us-west-1"));

            //Get client first time, should create new client and return
            var clientFactory = new KmsClientFactory(config.Object);
            var clientA       = await clientFactory.GetTenantSpecificClientAsync(tenant);

            Assert.NotNull(clientA);

            //Get the client second time, should return client from cache
            var clientB = await clientFactory.GetTenantSpecificClientAsync(tenant);

            Assert.NotNull(clientB);
            Assert.Equal(clientA, clientB);

            //Update consul settings
            config.Setup(x => x.GetTenantConfigurationAsNameValueCollectionAsync(tenant,
                                                                                 It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(GetNamevalueCollection("us-west-2"));

            var eventData = new ApplicationEvent
            {
                Id        = Guid.NewGuid().ToString(),
                Name      = "in-memory-consul-cache-refresh",
                TimeStamp = DateTime.Now
            };

            //Process is invoked on consule event and clears unused clients
            clientFactory.Process(eventData);
            Thread.Sleep(5000);

            // Get the client third time, this should return different client instance for same tenant as settings in consul is updated
            var updatedClient = await clientFactory.GetTenantSpecificClientAsync(tenant);

            Assert.NotNull(updatedClient);
            Assert.NotEqual(updatedClient, clientA);
        }