public async Task ApplicationGatewayApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("csmrg");

            string location = "West US";
            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            string vnetName     = Recording.GenerateAssetName("azsmnet");
            string gwSubnetName = Recording.GenerateAssetName("azsmnet");
            string subnet2Name  = Recording.GenerateAssetName("azsmnet");
            string appGwName    = Recording.GenerateAssetName("azsmnet");

            VirtualNetwork vnet = new VirtualNetwork()
            {
                Location     = location,
                AddressSpace = new AddressSpace()
                {
                    AddressPrefixes = { "10.0.0.0/16", }
                },
                DhcpOptions = new DhcpOptions()
                {
                    DnsServers = { "10.1.1.1", "10.1.2.4" }
                },
                Subnets =
                {
                    new Subnet()
                    {
                        Name = gwSubnetName, AddressPrefix = "10.0.0.0/24"
                    },
                    new Subnet()
                    {
                        Name = subnet2Name, AddressPrefix = "10.0.1.0/24"
                    }
                }
            };

            VirtualNetworksCreateOrUpdateOperation putVnetResponseOperation = await NetworkManagementClient.VirtualNetworks.StartCreateOrUpdateAsync(resourceGroupName, vnetName, vnet);

            await WaitForCompletionAsync(putVnetResponseOperation);

            Response <VirtualNetwork> getVnetResponse = await NetworkManagementClient.VirtualNetworks.GetAsync(resourceGroupName, vnetName);

            Response <Subnet> getSubnetResponse = await NetworkManagementClient.Subnets.GetAsync(resourceGroupName, vnetName, gwSubnetName);

            Console.WriteLine("Virtual Network GatewaySubnet Id: {0}", getSubnetResponse.Value.Id);
            Response <Subnet> gwSubnet = getSubnetResponse;

            ApplicationGateway appGw = CreateApplicationGateway(location, gwSubnet, resourceGroupName, appGwName, TestEnvironment.SubscriptionId);

            // Put AppGw
            Operation <ApplicationGateway> putAppGw = await NetworkManagementClient.ApplicationGateways.StartCreateOrUpdateAsync(resourceGroupName, appGwName, appGw);

            Response <ApplicationGateway> putAppGwResponse = await WaitForCompletionAsync(putAppGw);

            Assert.AreEqual("Succeeded", putAppGwResponse.Value.ProvisioningState.ToString());

            // Get AppGw
            Response <ApplicationGateway> getGateway = await NetworkManagementClient.ApplicationGateways.GetAsync(resourceGroupName, appGwName);

            Assert.AreEqual(appGwName, getGateway.Value.Name);
            CompareApplicationGateway(appGw, getGateway);

            // Get available WAF rule sets (validate first result set/group)
            Response <ApplicationGatewayAvailableWafRuleSetsResult> availableWAFRuleSets = await NetworkManagementClient.ApplicationGateways.ListAvailableWafRuleSetsAsync();

            Assert.NotNull(availableWAFRuleSets);
            Assert.IsNotEmpty(availableWAFRuleSets.Value.Value);
            Assert.NotNull(availableWAFRuleSets.Value.Value[0].Name);
            Assert.NotNull(availableWAFRuleSets.Value.Value[0].RuleSetType);
            Assert.NotNull(availableWAFRuleSets.Value.Value[0].RuleSetVersion);
            Assert.IsNotEmpty(availableWAFRuleSets.Value.Value[0].RuleGroups);
            Assert.NotNull(availableWAFRuleSets.Value.Value[0].RuleGroups[0].RuleGroupName);
            Assert.IsNotEmpty(availableWAFRuleSets.Value.Value[0].RuleGroups[0].Rules);
            // Assert.NotNull(availableWAFRuleSets.Value[0].RuleGroups[0].Rules[0].RuleId);

            // Get availalbe SSL options
            Response <ApplicationGatewayAvailableSslOptions> sslOptions = await NetworkManagementClient.ApplicationGateways.ListAvailableSslOptionsAsync();

            Assert.NotNull(sslOptions.Value.DefaultPolicy);
            Assert.NotNull(sslOptions.Value.AvailableCipherSuites);
            Assert.NotNull(sslOptions.Value.AvailableCipherSuites[20]);

            AsyncPageable <ApplicationGatewaySslPredefinedPolicy>    policies   = NetworkManagementClient.ApplicationGateways.ListAvailableSslPredefinedPoliciesAsync();
            IAsyncEnumerator <ApplicationGatewaySslPredefinedPolicy> enumerator = policies.GetAsyncEnumerator();

            Assert.True(enumerator.MoveNextAsync().Result);
            Assert.NotNull(enumerator.Current.Name);

            Task <Response <ApplicationGatewaySslPredefinedPolicy> > policy = NetworkManagementClient.ApplicationGateways.GetSslPredefinedPolicyAsync(ApplicationGatewaySslPolicyName.AppGwSslPolicy20150501.ToString());

            Assert.NotNull(policy.Result.Value.MinProtocolVersion);
            Assert.NotNull(policy.Result.Value.CipherSuites);
            Assert.NotNull(policy.Result.Value.CipherSuites[20]);

            // Create Nics
            string nic1name = Recording.GenerateAssetName("azsmnet");
            string nic2name = Recording.GenerateAssetName("azsmnet");

            Task <NetworkInterface> nic1 = CreateNetworkInterface(
                nic1name,
                resourceGroupName,
                null,
                getVnetResponse.Value.Subnets[1].Id,
                location,
                "ipconfig",
                NetworkManagementClient);

            Task <NetworkInterface> nic2 = CreateNetworkInterface(
                nic2name,
                resourceGroupName,
                null,
                getVnetResponse.Value.Subnets[1].Id,
                location,
                "ipconfig",
                NetworkManagementClient);

            // Add NIC to application gateway backend address pool.
            nic1.Result.IpConfigurations[0].ApplicationGatewayBackendAddressPools.Add(getGateway.Value.BackendAddressPools[1]);
            nic2.Result.IpConfigurations[0].ApplicationGatewayBackendAddressPools.Add(getGateway.Value.BackendAddressPools[1]);
            // Put Nics
            NetworkInterfacesCreateOrUpdateOperation createOrUpdateOperation1 = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nic1name, nic1.Result);

            await WaitForCompletionAsync(createOrUpdateOperation1);

            NetworkInterfacesCreateOrUpdateOperation createOrUpdateOperation2 = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nic2name, nic2.Result);

            await WaitForCompletionAsync(createOrUpdateOperation2);

            // Get AppGw backend health
            Operation <ApplicationGatewayBackendHealth> backendHealthOperation = await NetworkManagementClient.ApplicationGateways.StartBackendHealthAsync(resourceGroupName, appGwName, "true");

            Response <ApplicationGatewayBackendHealth> backendHealth = await WaitForCompletionAsync(backendHealthOperation);

            Assert.AreEqual(2, backendHealth.Value.BackendAddressPools.Count);
            Assert.AreEqual(1, backendHealth.Value.BackendAddressPools[0].BackendHttpSettingsCollection.Count);
            Assert.AreEqual(1, backendHealth.Value.BackendAddressPools[1].BackendHttpSettingsCollection.Count);
            Assert.True(backendHealth.Value.BackendAddressPools[1].BackendAddressPool.BackendIPConfigurations.Any());

            //Start AppGw
            await NetworkManagementClient.ApplicationGateways.StartStartAsync(resourceGroupName, appGwName);

            // Get AppGw and make sure nics are added to backend
            getGateway = await NetworkManagementClient.ApplicationGateways.GetAsync(resourceGroupName, appGwName);

            Assert.AreEqual(2, getGateway.Value.BackendAddressPools[1].BackendIPConfigurations.Count);

            //Stop AppGw
            await NetworkManagementClient.ApplicationGateways.StartStopAsync(resourceGroupName, appGwName);

            // Delete AppGw
            await NetworkManagementClient.ApplicationGateways.StartDeleteAsync(resourceGroupName, appGwName);
        }
Ejemplo n.º 2
0
        public async Task VirtualNetworkUsageTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("csmrg");

            string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/virtualNetworks");

            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            string vnetName   = Recording.GenerateAssetName("azsmnet");
            string subnetName = Recording.GenerateAssetName("azsmnet");

            VirtualNetwork vnet = new VirtualNetwork()
            {
                Location     = location,
                AddressSpace = new AddressSpace()
                {
                    AddressPrefixes = { "10.0.0.0/16", }
                },
                DhcpOptions = new DhcpOptions()
                {
                    DnsServers = { "10.1.1.1", "10.1.2.4" }
                },
                Subnets = { new Subnet()
                            {
                                Name = subnetName, AddressPrefix = "10.0.1.0/24"
                            } }
            };

            // Put Vnet
            VirtualNetworksCreateOrUpdateOperation putVnetResponseOperation = await NetworkManagementClient.VirtualNetworks.StartCreateOrUpdateAsync(resourceGroupName, vnetName, vnet);

            Response <VirtualNetwork> putVnetResponse = await WaitForCompletionAsync(putVnetResponseOperation);

            Assert.AreEqual("Succeeded", putVnetResponse.Value.ProvisioningState.ToString());

            Response <Subnet> getSubnetResponse = await NetworkManagementClient.Subnets.GetAsync(resourceGroupName, vnetName, subnetName);

            // Get Vnet usage
            AsyncPageable <VirtualNetworkUsage> listUsageResponseAP = NetworkManagementClient.VirtualNetworks.ListUsageAsync(resourceGroupName, vnetName);
            List <VirtualNetworkUsage>          listUsageResponse   = await listUsageResponseAP.ToEnumerableAsync();

            Assert.AreEqual(0.0, listUsageResponse[0].CurrentValue);

            // Create Nic
            string nicName      = Recording.GenerateAssetName("azsmnet");
            string ipConfigName = Recording.GenerateAssetName("azsmnet");

            NetworkInterface nicParameters = new NetworkInterface()
            {
                Location         = location,
                Tags             = { { "key", "value" } },
                IpConfigurations =
                {
                    new NetworkInterfaceIPConfiguration()
                    {
                        Name = ipConfigName,
                        PrivateIPAllocationMethod = IPAllocationMethod.Static,
                        PrivateIPAddress          = "10.0.1.9",
                        Subnet = new Subnet()
                        {
                            Id = getSubnetResponse.Value.Id
                        }
                    }
                }
            };

            NetworkInterfacesCreateOrUpdateOperation putNicResponseOperation = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nicName, nicParameters);

            await WaitForCompletionAsync(putNicResponseOperation);

            // Get Vnet usage again
            listUsageResponseAP = NetworkManagementClient.VirtualNetworks.ListUsageAsync(resourceGroupName, vnetName);
            listUsageResponse   = await listUsageResponseAP.ToEnumerableAsync();

            Assert.AreEqual(1.0, listUsageResponse[0].CurrentValue);

            // Delete Vnet and Nic
            await NetworkManagementClient.NetworkInterfaces.StartDeleteAsync(resourceGroupName, nicName);

            await NetworkManagementClient.VirtualNetworks.StartDeleteAsync(resourceGroupName, vnetName);
        }
Ejemplo n.º 3
0
        public async Task ExpandResourceTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("csmrg");

            string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/loadBalancers");

            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            // Create lbPublicIP
            string lbPublicIpName     = Recording.GenerateAssetName("azsmnet");
            string lbDomaingNameLabel = Recording.GenerateAssetName("azsmnet");

            PublicIPAddress lbPublicIp = await CreateDefaultPublicIpAddress(
                lbPublicIpName,
                resourceGroupName,
                lbDomaingNameLabel,
                location,
                NetworkManagementClient);

            // Create Vnet
            string vnetName   = Recording.GenerateAssetName("azsmnet");
            string subnetName = Recording.GenerateAssetName("azsmnet");

            VirtualNetwork vnet = await CreateVirtualNetwork(vnetName, subnetName, resourceGroupName, location, NetworkManagementClient);

            // Create Nics
            string nic1name = Recording.GenerateAssetName("azsmnet");
            string nic2name = Recording.GenerateAssetName("azsmnet");
            string nic3name = Recording.GenerateAssetName("azsmnet");

            NetworkInterface nic1 = await CreateNetworkInterface(
                nic1name,
                resourceGroupName,
                null,
                vnet.Subnets[0].Id,
                location,
                "ipconfig",
                NetworkManagementClient);

            NetworkInterface nic2 = await CreateNetworkInterface(
                nic2name,
                resourceGroupName,
                null,
                vnet.Subnets[0].Id,
                location,
                "ipconfig",
                NetworkManagementClient);

            NetworkInterface nic3 = await CreateNetworkInterface(
                nic3name,
                resourceGroupName,
                null,
                vnet.Subnets[0].Id,
                location,
                "ipconfig",
                NetworkManagementClient);

            // Create the LoadBalancer
            var lbName = Recording.GenerateAssetName("azsmnet");
            var frontendIpConfigName   = Recording.GenerateAssetName("azsmnet");
            var backEndAddressPoolName = Recording.GenerateAssetName("azsmnet");
            var loadBalancingRuleName  = Recording.GenerateAssetName("azsmnet");
            var probeName           = Recording.GenerateAssetName("azsmnet");
            var inboundNatRule1Name = Recording.GenerateAssetName("azsmnet");
            var inboundNatRule2Name = Recording.GenerateAssetName("azsmnet");

            // Populate the loadBalancerCreateOrUpdateParameter
            LoadBalancer loadBalancer = new LoadBalancer()
            {
                Location = location,
                FrontendIPConfigurations =
                {
                    new FrontendIPConfiguration()
                    {
                        Name            = frontendIpConfigName,
                        PublicIPAddress = new PublicIPAddress()
                        {
                            Id = lbPublicIp.Id
                        }
                    }
                },
                BackendAddressPools =
                {
                    new BackendAddressPool()
                    {
                        Name = backEndAddressPoolName,
                    }
                },
                LoadBalancingRules =
                {
                    new LoadBalancingRule()
                    {
                        Name = loadBalancingRuleName,
                        FrontendIPConfiguration = new SubResource()
                        {
                            Id = GetChildLbResourceId(TestEnvironment.SubscriptionId,
                                                      resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName)
                        },
                        Protocol             = TransportProtocol.Tcp,
                        FrontendPort         = 80,
                        BackendPort          = 80,
                        EnableFloatingIP     = false,
                        IdleTimeoutInMinutes = 15,
                        BackendAddressPool   = new SubResource()
                        {
                            Id = GetChildLbResourceId(TestEnvironment.SubscriptionId,
                                                      resourceGroupName, lbName, "backendAddressPools", backEndAddressPoolName)
                        },
                        Probe = new SubResource()
                        {
                            Id = GetChildLbResourceId(TestEnvironment.SubscriptionId,
                                                      resourceGroupName, lbName, "probes", probeName)
                        }
                    }
                },
                Probes =
                {
                    new Probe()
                    {
                        Name              = probeName,
                        Protocol          = ProbeProtocol.Http,
                        Port              = 80,
                        RequestPath       = "healthcheck.aspx",
                        IntervalInSeconds = 10,
                        NumberOfProbes    = 2
                    }
                },
                InboundNatRules =
                {
                    new InboundNatRule()
                    {
                        Name = inboundNatRule1Name,
                        FrontendIPConfiguration = new SubResource()
                        {
                            Id = GetChildLbResourceId(TestEnvironment.SubscriptionId,
                                                      resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName)
                        },
                        Protocol             = TransportProtocol.Tcp,
                        FrontendPort         = 3389,
                        BackendPort          = 3389,
                        IdleTimeoutInMinutes = 15,
                        EnableFloatingIP     = false
                    },
                    new InboundNatRule()
                    {
                        Name = inboundNatRule2Name,
                        FrontendIPConfiguration = new SubResource()
                        {
                            Id = GetChildLbResourceId(TestEnvironment.SubscriptionId,
                                                      resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName)
                        },
                        Protocol             = TransportProtocol.Tcp,
                        FrontendPort         = 3390,
                        BackendPort          = 3389,
                        IdleTimeoutInMinutes = 15,
                        EnableFloatingIP     = false,
                    }
                }
            };

            // Create the loadBalancer
            Operation <LoadBalancer> putLoadBalancerOperation = await NetworkManagementClient.LoadBalancers.StartCreateOrUpdateAsync(resourceGroupName, lbName, loadBalancer);

            await WaitForCompletionAsync(putLoadBalancerOperation);

            Response <LoadBalancer> getLoadBalancer = await NetworkManagementClient.LoadBalancers.GetAsync(resourceGroupName, lbName);

            // Associate the nic with LB
            nic1.IpConfigurations.First().LoadBalancerBackendAddressPools.Add(getLoadBalancer.Value.BackendAddressPools.First());
            nic1.IpConfigurations.First().LoadBalancerInboundNatRules.Add(getLoadBalancer.Value.InboundNatRules.First());
            nic2.IpConfigurations.First().LoadBalancerBackendAddressPools.Add(getLoadBalancer.Value.BackendAddressPools.First());
            nic3.IpConfigurations.First().LoadBalancerInboundNatRules.Add(getLoadBalancer.Value.InboundNatRules[1]);

            // Put Nics
            NetworkInterfacesCreateOrUpdateOperation createOrUpdateOperation1 = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nic1name, nic1);

            await WaitForCompletionAsync(createOrUpdateOperation1);

            NetworkInterfacesCreateOrUpdateOperation createOrUpdateOperation2 = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nic2name, nic2);

            await WaitForCompletionAsync(createOrUpdateOperation2);

            NetworkInterfacesCreateOrUpdateOperation createOrUpdateOperation3 = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nic3name, nic3);

            await WaitForCompletionAsync(createOrUpdateOperation3);

            // Get Nics
            await NetworkManagementClient.NetworkInterfaces.GetAsync(resourceGroupName, nic1name);

            await NetworkManagementClient.NetworkInterfaces.GetAsync(resourceGroupName, nic2name);

            await NetworkManagementClient.NetworkInterfaces.GetAsync(resourceGroupName, nic3name);

            // Get lb with expanded nics from nat rules
            getLoadBalancer = await NetworkManagementClient.LoadBalancers.GetAsync(resourceGroupName, lbName, "InboundNatRules/backendIPConfiguration");

            foreach (InboundNatRule natRule in getLoadBalancer.Value.InboundNatRules)
            {
                Assert.NotNull(natRule.BackendIPConfiguration);
                Assert.NotNull(natRule.BackendIPConfiguration.Id);
                Assert.NotNull(natRule.BackendIPConfiguration.Name);
                Assert.NotNull(natRule.BackendIPConfiguration.Etag);
                Assert.AreEqual(natRule.Id, natRule.BackendIPConfiguration.LoadBalancerInboundNatRules[0].Id);
            }

            // Get lb with expanded nics from pools
            getLoadBalancer = await NetworkManagementClient.LoadBalancers.GetAsync(resourceGroupName, lbName, "BackendAddressPools/backendIPConfigurations");

            foreach (BackendAddressPool pool in getLoadBalancer.Value.BackendAddressPools)
            {
                foreach (NetworkInterfaceIPConfiguration ipconfig in getLoadBalancer.Value.BackendAddressPools.First().BackendIPConfigurations)
                {
                    Assert.NotNull(ipconfig.Id);
                    Assert.NotNull(ipconfig.Name);
                    Assert.NotNull(ipconfig.Etag);
                    Assert.AreEqual(pool.Id, ipconfig.LoadBalancerBackendAddressPools[0].Id);
                }
            }

            // Get lb with expanded publicip
            getLoadBalancer = await NetworkManagementClient.LoadBalancers.GetAsync(resourceGroupName, lbName, "FrontendIPConfigurations/PublicIPAddress");

            foreach (FrontendIPConfiguration ipconfig in getLoadBalancer.Value.FrontendIPConfigurations)
            {
                Assert.NotNull(ipconfig.PublicIPAddress);
                Assert.NotNull(ipconfig.PublicIPAddress.Id);
                Assert.NotNull(ipconfig.PublicIPAddress.Name);
                Assert.NotNull(ipconfig.PublicIPAddress.Etag);
                Assert.AreEqual(ipconfig.Id, ipconfig.PublicIPAddress.IpConfiguration.Id);
            }

            // Get NIC with expanded subnet
            nic1 = await NetworkManagementClient.NetworkInterfaces.GetAsync(resourceGroupName, nic1name, "IPConfigurations/Subnet");

            foreach (NetworkInterfaceIPConfiguration ipconfig in nic1.IpConfigurations)
            {
                Assert.NotNull(ipconfig.Subnet);
                Assert.NotNull(ipconfig.Subnet.Id);
                Assert.NotNull(ipconfig.Subnet.Name);
                Assert.NotNull(ipconfig.Subnet.Etag);
                Assert.IsNotEmpty(ipconfig.Subnet.IpConfigurations);
            }

            // Get subnet with expanded ipconfigurations
            Response <Subnet> subnet = await NetworkManagementClient.Subnets.GetAsync(
                resourceGroupName,
                vnetName,
                subnetName,
                "IPConfigurations");

            foreach (IPConfiguration ipconfig in subnet.Value.IpConfigurations)
            {
                Assert.NotNull(ipconfig.Name);
                Assert.NotNull(ipconfig.Id);
                Assert.NotNull(ipconfig.Etag);
                Assert.NotNull(ipconfig.PrivateIPAddress);
            }

            // Get publicIPAddress with expanded ipconfigurations
            Response <PublicIPAddress> publicip = await NetworkManagementClient.PublicIPAddresses.GetAsync(
                resourceGroupName,
                lbPublicIpName,
                "IPConfiguration");

            Assert.NotNull(publicip.Value.IpConfiguration);
            Assert.NotNull(publicip.Value.IpConfiguration.Id);
            Assert.NotNull(publicip.Value.IpConfiguration.Name);
            Assert.NotNull(publicip.Value.IpConfiguration.Etag);

            // Delete LoadBalancer
            LoadBalancersDeleteOperation deleteOperation = await NetworkManagementClient.LoadBalancers.StartDeleteAsync(resourceGroupName, lbName);

            await WaitForCompletionAsync(deleteOperation);

            // Verify Delete
            AsyncPageable <LoadBalancer> listLoadBalancerAP = NetworkManagementClient.LoadBalancers.ListAsync(resourceGroupName);
            List <LoadBalancer>          listLoadBalancer   = await listLoadBalancerAP.ToEnumerableAsync();

            Assert.IsEmpty(listLoadBalancer);

            // Delete all NetworkInterfaces
            await NetworkManagementClient.NetworkInterfaces.StartDeleteAsync(resourceGroupName, nic1name);

            await NetworkManagementClient.NetworkInterfaces.StartDeleteAsync(resourceGroupName, nic2name);

            await NetworkManagementClient.NetworkInterfaces.StartDeleteAsync(resourceGroupName, nic3name);

            // Delete all PublicIPAddresses
            await NetworkManagementClient.PublicIPAddresses.StartDeleteAsync(resourceGroupName, lbPublicIpName);
        }
Ejemplo n.º 4
0
        public async Task VirtualNetworkCheckIpAddressAvailabilityTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("csmrg");

            string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/virtualNetworks");

            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            string vnetName   = Recording.GenerateAssetName("azsmnet");
            string subnetName = Recording.GenerateAssetName("azsmnet");

            VirtualNetwork vnet = new VirtualNetwork()
            {
                Location = location,

                AddressSpace = new AddressSpace()
                {
                    AddressPrefixes = { "10.0.0.0/16", }
                },
                DhcpOptions = new DhcpOptions()
                {
                    DnsServers = { "10.1.1.1", "10.1.2.4" }
                },
                Subnets = { new Subnet()
                            {
                                Name = subnetName, AddressPrefix = "10.0.1.0/24"
                            } }
            };

            // Put Vnet
            VirtualNetworksCreateOrUpdateOperation putVnetResponseOperation = await NetworkManagementClient.VirtualNetworks.StartCreateOrUpdateAsync(resourceGroupName, vnetName, vnet);

            Response <VirtualNetwork> putVnetResponse = await WaitForCompletionAsync(putVnetResponseOperation);

            Assert.AreEqual("Succeeded", putVnetResponse.Value.ProvisioningState.ToString());

            Response <Subnet> getSubnetResponse = await NetworkManagementClient.Subnets.GetAsync(resourceGroupName, vnetName, subnetName);

            // Create Nic
            string nicName      = Recording.GenerateAssetName("azsmnet");
            string ipConfigName = Recording.GenerateAssetName("azsmnet");

            NetworkInterface nicParameters = new NetworkInterface()
            {
                Location         = location,
                Tags             = { { "key", "value" } },
                IpConfigurations =
                {
                    new NetworkInterfaceIPConfiguration()
                    {
                        Name = ipConfigName,
                        PrivateIPAllocationMethod = IPAllocationMethod.Static,
                        PrivateIPAddress          = "10.0.1.9",
                        Subnet = new Subnet()
                        {
                            Id = getSubnetResponse.Value.Id
                        }
                    }
                }
            };

            NetworkInterfacesCreateOrUpdateOperation putNicResponseOperation = await NetworkManagementClient.NetworkInterfaces.StartCreateOrUpdateAsync(resourceGroupName, nicName, nicParameters);

            await WaitForCompletionAsync(putNicResponseOperation);

            // Check Ip Address availability API
            Response <IPAddressAvailabilityResult> responseAvailable = await NetworkManagementClient.VirtualNetworks.CheckIPAddressAvailabilityAsync(resourceGroupName, vnetName, "10.0.1.10");

            Assert.True(responseAvailable.Value.Available);
            Assert.IsEmpty(responseAvailable.Value.AvailableIPAddresses);

            Response <IPAddressAvailabilityResult> responseTaken = await NetworkManagementClient.VirtualNetworks.CheckIPAddressAvailabilityAsync(resourceGroupName, vnetName, "10.0.1.9");

            Assert.False(responseTaken.Value.Available);
            Assert.AreEqual(5, responseTaken.Value.AvailableIPAddresses.Count);

            await NetworkManagementClient.NetworkInterfaces.StartDeleteAsync(resourceGroupName, nicName);

            await NetworkManagementClient.VirtualNetworks.StartDeleteAsync(resourceGroupName, vnetName);
        }