public async Task GetShouldReturnDatabasesFromCacheIfGetCalledTwice()
        {
            Dictionary <string, List <string> > subscriptionToDatabaseMap = CreateSubscriptonMap(2);

            AddDatabases(subscriptionToDatabaseMap, 3);

            AzureDatabaseDiscoveryProvider         databaseDiscoveryProvider = FakeDataFactory.CreateAzureDatabaseDiscoveryProvider(subscriptionToDatabaseMap);
            ServiceResponse <DatabaseInstanceInfo> response = await databaseDiscoveryProvider.GetDatabaseInstancesAsync(serverName : null, cancellationToken : new CancellationToken());

            List <DatabaseInstanceInfo> list = response.Data.ToList();

            ValidateResult(subscriptionToDatabaseMap, list);

            Dictionary <string, List <string> > subscriptionToDatabaseMap2 = CopySubscriptonMap(subscriptionToDatabaseMap);

            AddDatabases(subscriptionToDatabaseMap2, 5);
            AzureTestContext testContext = new AzureTestContext(subscriptionToDatabaseMap2);

            databaseDiscoveryProvider.AccountManager       = testContext.AzureAccountManager;
            databaseDiscoveryProvider.AzureResourceManager = testContext.AzureResourceManager;
            response = await databaseDiscoveryProvider.GetDatabaseInstancesAsync(serverName : null, cancellationToken : new CancellationToken());

            list = response.Data.ToList();
            //the provider should get the databases from cache for the list should match the first created data
            ValidateResult(subscriptionToDatabaseMap, list);
        }
        public async Task GetShouldReturnDatabasesEvenIfFailsForOneServer()
        {
            string        databaseName1            = "server1/db1";
            string        databaseName2            = "server1/db2";
            string        databaseName3            = "error/db3";
            string        databaseName4            = "server2/db4";
            List <string> databasesForSubscription = new List <string>()
            {
                databaseName1,
                databaseName2
            };

            Dictionary <string, List <string> > subscriptionToDatabaseMap = new Dictionary <string, List <string> >();

            subscriptionToDatabaseMap.Add(Guid.NewGuid().ToString(), databasesForSubscription);
            subscriptionToDatabaseMap.Add(Guid.NewGuid().ToString(), new List <string>()
            {
                databaseName3,
                databaseName4,
            });

            AzureDatabaseDiscoveryProvider         databaseDiscoveryProvider = FakeDataFactory.CreateAzureDatabaseDiscoveryProvider(subscriptionToDatabaseMap);
            ServiceResponse <DatabaseInstanceInfo> response = await databaseDiscoveryProvider.GetDatabaseInstancesAsync(serverName : null, cancellationToken : new CancellationToken());

            List <DatabaseInstanceInfo> list = response.Data.ToList();

            Assert.NotNull(list);
            Assert.True(list.Any(x => x.Name == "db1" && x.ServerInstanceInfo.Name == "server1"));
            Assert.True(list.Any(x => x.Name == "db2" && x.ServerInstanceInfo.Name == "server1"));
            Assert.True(list.Any(x => x.Name == "db4" && x.ServerInstanceInfo.Name == "server2"));
            Assert.False(list.Any(x => x.Name == "db3" && x.ServerInstanceInfo.Name == "error"));
            Assert.True(list.Count() == 3);
            Assert.NotNull(response.Errors);
            Assert.True(response.Errors.Count() == 1);
        }
        public async Task GetShouldReturnEmptyGivenNotSubscriptionFound()
        {
            Dictionary <string, List <string> > subscriptionToDatabaseMap = new Dictionary <string, List <string> >();

            AzureDatabaseDiscoveryProvider databaseDiscoveryProvider =
                FakeDataFactory.CreateAzureDatabaseDiscoveryProvider(subscriptionToDatabaseMap);
            ServiceResponse <DatabaseInstanceInfo> response =
                await databaseDiscoveryProvider.GetDatabaseInstancesAsync(serverName : null, cancellationToken : new CancellationToken());

            Assert.NotNull(response);
            Assert.NotNull(response.Data);
            Assert.False(response.Data.Any());
        }