public Server CreateServer(ResourceGroup resourceGroup, string location) { SqlManagementClient sqlClient = GetClient <SqlManagementClient>(); string version12 = "12.0"; string serverName = SqlManagementTestUtilities.GenerateName(); Dictionary <string, string> tags = new Dictionary <string, string>(); var v12Server = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName, new Server() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Version = version12, Tags = tags, Location = location, }); SqlManagementTestUtilities.ValidateServer(v12Server, serverName, SqlManagementTestUtilities.DefaultLogin, version12, tags, location); return(v12Server); }
public async Task TestCreateUpdateGetDropServer() { var resourceGroup = context.CreateResourceGroup(); var sqlClient = context.GetClient<SqlManagementClient>(); string serverNameV12 = SqlManagementTestUtilities.GenerateName(); string login = "******"; string password = "******"; string version12 = "12.0"; Dictionary<string, string> tags = new Dictionary<string, string>() { { "tagKey1", "TagValue1" } }; // Create server var server1 = await (await sqlClient.Servers.StartCreateOrUpdateAsync(resourceGroup.Name, serverNameV12, new Server() { AdministratorLogin = login, AdministratorLoginPassword = password, Version = version12, Tags = { { "tagKey1", "TagValue1" } }, Location = TestEnvironmentUtilities.DefaultLocationId, })).WaitForCompletionAsync(); SqlManagementTestUtilities.ValidateServer(server1, serverNameV12, login, version12, tags, TestEnvironmentUtilities.DefaultLocationId); // Create second server string server2 = SqlManagementTestUtilities.GenerateName(); var v2Server = await (await sqlClient.Servers.StartCreateOrUpdateAsync(resourceGroup.Name, server2, new Server() { AdministratorLogin = login, AdministratorLoginPassword = password, Tags = tags, Location = TestEnvironmentUtilities.DefaultLocationId, })).WaitForCompletionAsync(); SqlManagementTestUtilities.ValidateServer(v2Server, server2, login, version12, tags, TestEnvironmentUtilities.DefaultLocationId); // Get first server var getServer1 = sqlClient.Servers.Get(resourceGroup.Name, serverNameV12); SqlManagementTestUtilities.ValidateServer(getServer1, serverNameV12, login, version12, tags, TestEnvironmentUtilities.DefaultLocationId); // Get second server var getServer2 = sqlClient.Servers.Get(resourceGroup.Name, server2); SqlManagementTestUtilities.ValidateServer(getServer2, server2, login, version12, tags, TestEnvironmentUtilities.DefaultLocationId); var listServers = sqlClient.Servers.ListByResourceGroup(resourceGroup.Name); Assert.AreEqual(2, listServers.Count()); // Update first server Dictionary<string, string> newTags = new Dictionary<string, string>() { { "asdf", "zxcv" } }; var updateServer1 = sqlClient.Servers.Update(resourceGroup.Name, serverNameV12, new ServerUpdate { Tags = newTags }); SqlManagementTestUtilities.ValidateServer(updateServer1, serverNameV12, login, version12, newTags, TestEnvironmentUtilities.DefaultLocationId); // Drop server, update count await sqlClient.Servers.StartDeleteAsync(resourceGroup.Name, serverNameV12); var listServers2 = sqlClient.Servers.ListByResourceGroup(resourceGroup.Name); Assert.AreEqual(1, listServers2.Count()); }
public void TestServerOutboundFirewallRules() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { const string OBFRNotFoundMessage = "Operation returned an invalid status code 'NotFound'"; ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string location = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId; string enabled = "Enabled"; string disabled = "Disabled"; string serverName = SqlManagementTestUtilities.GenerateName(); //string serverName2 = SqlManagementTestUtilities.GenerateName(); string login = "******"; string password = "******"; string version12 = "12.0"; Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; // Create server with PublicNetworkAccess disabled and verify its been disabled Server server = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName, new Server() { AdministratorLogin = login, AdministratorLoginPassword = password, Version = version12, Tags = tags, Location = location, RestrictOutboundNetworkAccess = disabled }); SqlManagementTestUtilities.ValidateServer(server, serverName, login, version12, tags, location, null, null, disabled); // Get server and verify that server is disabled server = sqlClient.Servers.Get(resourceGroup.Name, serverName); SqlManagementTestUtilities.ValidateServer(server, serverName, login, version12, tags, location, null, null, disabled); // Create server with PublicNetworkAccess enabled and verify its been enabled server = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName, new Server() { Location = location, RestrictOutboundNetworkAccess = enabled }); SqlManagementTestUtilities.ValidateServer(server, serverName, login, version12, tags, location, null, null, enabled); const string sampleOBFRFQDN = "TestOutboundFirewallRule"; try { //Try getting a OBFR which does not exist. Should error with "Not Found" OutboundFirewallRule obfrGetFail = sqlClient.OutboundFirewallRules.Get(resourceGroup.Name, server.Name, sampleOBFRFQDN); } catch (Microsoft.Rest.Azure.CloudException ex) { Assert.Equal(ex.Message, OBFRNotFoundMessage); } //Create a new OBFR. OutboundFirewallRule obfrSet = sqlClient.OutboundFirewallRules.CreateOrUpdate(resourceGroup.Name, server.Name, sampleOBFRFQDN); Assert.Equal(obfrSet.Name, sampleOBFRFQDN); Server existingServerAfterSet = sqlClient.Servers.Get(resourceGroup.Name, serverName); SqlManagementTestUtilities.ValidateServer(existingServerAfterSet, serverName, login, version12, tags, location, null, null, enabled); //Get the previously created OBFR OutboundFirewallRule obfrGet = sqlClient.OutboundFirewallRules.Get(resourceGroup.Name, server.Name, sampleOBFRFQDN); Assert.Equal(obfrGet.Name, sampleOBFRFQDN); Server existingServerAfterGet = sqlClient.Servers.Get(resourceGroup.Name, serverName); SqlManagementTestUtilities.ValidateServer(existingServerAfterSet, serverName, login, version12, tags, location, null, null, enabled); sqlClient.OutboundFirewallRules.Delete(resourceGroup.Name, server.Name, sampleOBFRFQDN); Server existingServerAfterDelete = sqlClient.Servers.Get(resourceGroup.Name, serverName); SqlManagementTestUtilities.ValidateServer(existingServerAfterSet, serverName, login, version12, tags, location, null, null, enabled); try { //Try getting a OBFR got deleted. Should error with "Not Found" OutboundFirewallRule obfrGetFail = sqlClient.OutboundFirewallRules.Get(resourceGroup.Name, server.Name, sampleOBFRFQDN); } catch (Microsoft.Rest.Azure.CloudException ex) { Assert.Equal(ex.Message, OBFRNotFoundMessage); } server = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName, new Server() { Location = location, RestrictOutboundNetworkAccess = disabled }); SqlManagementTestUtilities.ValidateServer(server, serverName, login, version12, tags, location, null, null, disabled); // Drop servers sqlClient.Servers.Delete(resourceGroup.Name, serverName); } }
public void TestServerPublicNetworkAccess() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string location = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId; string enabled = "Enabled"; string disabled = "Disabled"; string serverName1 = SqlManagementTestUtilities.GenerateName(); string serverName2 = SqlManagementTestUtilities.GenerateName(); string login = "******"; string password = "******"; string version12 = "12.0"; Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; // Create server with PublicNetworkAccess disabled and verify its been disabled var server1 = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName1, new Server() { AdministratorLogin = login, AdministratorLoginPassword = password, Version = version12, Tags = tags, Location = location, PublicNetworkAccess = disabled }); SqlManagementTestUtilities.ValidateServer(server1, serverName1, login, version12, tags, location, disabled); // Get server and verify that server is disabled server1 = sqlClient.Servers.Get(resourceGroup.Name, serverName1); SqlManagementTestUtilities.ValidateServer(server1, serverName1, login, version12, tags, location, disabled); // Create server with PublicNetworkAccess enabled and verify its been enabled server1 = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName1, new Server() { Location = location, PublicNetworkAccess = enabled }); SqlManagementTestUtilities.ValidateServer(server1, serverName1, login, version12, tags, location, enabled); // Create second server with no PublicNetworkAccess verify it defaults to enabled var server2 = sqlClient.Servers.CreateOrUpdate(resourceGroup.Name, serverName2, new Server() { AdministratorLogin = login, AdministratorLoginPassword = password, Version = version12, Tags = tags, Location = location, }); SqlManagementTestUtilities.ValidateServer(server2, serverName2, login, version12, tags, location, enabled); // Get servers and verify all are enabled var serverList = sqlClient.Servers.List(); foreach (var server in serverList) { if (server.Name.Equals(serverName1) || server.Name.Equals(serverName2)) { Assert.Equal(enabled, server.PublicNetworkAccess); } } // Drop servers sqlClient.Servers.Delete(resourceGroup.Name, serverName1); sqlClient.Servers.Delete(resourceGroup.Name, serverName2); } }