Exemplo n.º 1
0
        public void TestAllScenariosPrivateEndpointConnection()
        {
            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                sqlClient     = context.GetClient <SqlManagementClient>();
                networkClient = context.GetClient <NetworkManagementClient>();

                var            location                = TestEnvironmentUtilities.DefaultEuapPrimaryLocationId;
                ResourceGroup  resourceGroup           = context.CreateResourceGroup(location);
                Server         server                  = context.CreateServer(resourceGroup, location);
                VirtualNetwork vnet                    = CreateVirtualNetwork(resourceGroup, location);
                IList <PrivateEndpointConnection> pecs = CreatePrivateEndpoints(resourceGroup, location, server, vnet, n: 2);

                PrivateEndpointConnection pec1 = pecs[0];
                pec1.PrivateLinkServiceConnectionState.Status = "Approved";
                sqlClient.PrivateEndpointConnections.CreateOrUpdate(resourceGroup.Name, server.Name, pec1.Name, pec1);
                PrivateEndpointConnection pec1r = sqlClient.PrivateEndpointConnections.Get(resourceGroup.Name, server.Name, pec1.Name);
                SqlManagementTestUtilities.ValidatePrivateEndpointConnection(pec1, pec1r);

                PrivateEndpointConnection pec2 = pecs[1];
                pec2.PrivateLinkServiceConnectionState.Status = "Rejected";
                sqlClient.PrivateEndpointConnections.CreateOrUpdate(resourceGroup.Name, server.Name, pec2.Name, pec2);
                PrivateEndpointConnection pec2r = sqlClient.PrivateEndpointConnections.Get(resourceGroup.Name, server.Name, pec2.Name);
                SqlManagementTestUtilities.ValidatePrivateEndpointConnection(pec2, pec2r);

                sqlClient.PrivateEndpointConnections.Delete(resourceGroup.Name, server.Name, pec1.Name);
                Assert.Throws <Microsoft.Rest.Azure.CloudException>(() => sqlClient.PrivateEndpointConnections.Get(resourceGroup.Name, server.Name, pec1.Name));

                sqlClient.PrivateEndpointConnections.Delete(resourceGroup.Name, server.Name, pec2.Name);
                Assert.Throws <Microsoft.Rest.Azure.CloudException>(() => sqlClient.PrivateEndpointConnections.Get(resourceGroup.Name, server.Name, pec2.Name));
            }
        }