public void TestGetAndListDatabase() { string testPrefix = "sqlcrudtest-"; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Create some small databases to run the get/List tests on. Database[] databases = SqlManagementTestUtilities.CreateDatabasesAsync( sqlClient, resourceGroup.Name, server, testPrefix, 4).Result; // Organize into a dictionary for better lookup later IDictionary <string, Database> inputs = databases.ToDictionary( keySelector: d => d.Name, elementSelector: d => d); // Get each database and compare to the results of create database // foreach (var db in inputs) { var response = sqlClient.Databases.Get(resourceGroup.Name, server.Name, db.Key); SqlManagementTestUtilities.ValidateDatabaseEx(db.Value, response); } // List all databases // IEnumerable <Database> listResponse = sqlClient.Databases.ListByServer(resourceGroup.Name, server.Name); // Remove master database from the list listResponse = listResponse.Where(db => db.Name != "master"); Assert.Equal(inputs.Count(), listResponse.Count()); foreach (var db in listResponse) { SqlManagementTestUtilities.ValidateDatabase(inputs[db.Name], db, db.Name); } } }