Ejemplo n.º 1
0
        public async Task AddSubnetToExistingVnetTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var vnetName               = Environment.GetEnvironmentVariable("AZURE_VNET_NAME");
            var vnetAddressSpace       = Environment.GetEnvironmentVariable("AZURE_VNET_ADDRESSES");
            var newSubnetName          = "test-dotnet-newsubnet";
            var newSubnetAddress       = "10.0.16.0/24";
            var credentials            = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLERS
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var networkController  = new NetworkController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // RESOURCE GROUP CREATION VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE VNET
            var vnetAddressSpaces = vnetAddressSpace.Split(';');
            var vnet = await networkController.CreateVirtualNetwork(vnetName, vnetAddressSpaces, resourceGroupName, location);

            // VNET CREATION VALIDATION
            Assert.Equal("OK", vnet.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vnet.Body);

            // ADD NEW SUBNET
            var subnet = await networkController.AddSubnet(newSubnetName, vnetName, newSubnetAddress, resourceGroupName);

            // SUBNET CREATION VALIDATION
            Assert.Equal("OK", subnet.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(subnet.Body);
            Assert.Equal("Succeeded", subnet.Body.ProvisioningState, ignoreCase: true);
            Assert.Equal(newSubnetName, subnet.Body.Name);
            Assert.NotEmpty(subnet.Body.Id);
        }