public async Task PublicIpAddressApiTest() { string resourceGroupName = Recording.GenerateAssetName("csmrg"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/publicIPAddresses"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); // Create the parameter for PUT PublicIPAddress string publicIpName = Recording.GenerateAssetName("ipname"); string domainNameLabel = Recording.GenerateAssetName("domain"); PublicIPAddress publicIp = new PublicIPAddress() { Location = location, Tags = { { "key", "value" } }, PublicIPAllocationMethod = IPAllocationMethod.Dynamic, DnsSettings = new PublicIPAddressDnsSettings() { DomainNameLabel = domainNameLabel } }; // Put PublicIPAddress PublicIPAddressesCreateOrUpdateOperation putPublicIpAddressResponseOperation = await NetworkManagementClient.PublicIPAddresses.StartCreateOrUpdateAsync(resourceGroupName, publicIpName, publicIp); Response <PublicIPAddress> putPublicIpAddressResponse = await WaitForCompletionAsync(putPublicIpAddressResponseOperation); Assert.AreEqual("Succeeded", putPublicIpAddressResponse.Value.ProvisioningState.ToString()); // Get PublicIPAddress Response <PublicIPAddress> getPublicIpAddressResponse = await NetworkManagementClient.PublicIPAddresses.GetAsync(resourceGroupName, publicIpName); Assert.AreEqual(4, getPublicIpAddressResponse.Value.IdleTimeoutInMinutes); Assert.NotNull(getPublicIpAddressResponse.Value.ResourceGuid); // Get List of PublicIPAddress AsyncPageable <PublicIPAddress> getPublicIpAddressListResponseAP = NetworkManagementClient.PublicIPAddresses.ListAsync(resourceGroupName); List <PublicIPAddress> getPublicIpAddressListResponse = await getPublicIpAddressListResponseAP.ToEnumerableAsync(); Has.One.EqualTo(getPublicIpAddressListResponse); ArePublicIpAddressesEqual(getPublicIpAddressResponse, getPublicIpAddressListResponse.First()); // Get List of PublicIPAddress in a subscription AsyncPageable <PublicIPAddress> getPublicIpAddressListSubscriptionResponseAP = NetworkManagementClient.PublicIPAddresses.ListAllAsync(); List <PublicIPAddress> getPublicIpAddressListSubscriptionResponse = await getPublicIpAddressListSubscriptionResponseAP.ToEnumerableAsync(); Assert.IsNotEmpty(getPublicIpAddressListSubscriptionResponse); // Delete PublicIPAddress PublicIPAddressesDeleteOperation deleteOperation = await NetworkManagementClient.PublicIPAddresses.StartDeleteAsync(resourceGroupName, publicIpName); await WaitForCompletionAsync(deleteOperation); // Get PublicIPAddress getPublicIpAddressListResponseAP = NetworkManagementClient.PublicIPAddresses.ListAsync(resourceGroupName); getPublicIpAddressListResponse = await getPublicIpAddressListResponseAP.ToEnumerableAsync(); Assert.IsEmpty(getPublicIpAddressListResponse); }
public void VmssPublicIpAddressApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1, true); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Compute/virtualMachineScaleSets"); string resourceGroupName = TestUtilities.GenerateName(); string deploymentName = TestUtilities.GenerateName("vmss"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); DeploymentUpdate.CreateVmss(resourcesClient, resourceGroupName, deploymentName); string virtualMachineScaleSetName = "vmssip"; var vmssListAllPageResult = networkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetPublicIPAddresses(resourceGroupName, virtualMachineScaleSetName); var vmssListAllResult = vmssListAllPageResult.ToList(); var firstResult = vmssListAllResult.First(); Assert.NotNull(vmssListAllResult); Assert.Equal("Succeeded", firstResult.ProvisioningState); Assert.NotNull(firstResult.ResourceGuid); var idItem = firstResult.Id; var vmIndex = GetNameById(idItem, "virtualMachines"); var nicName = GetNameById(idItem, "networkInterfaces"); var ipConfigName = GetNameById(idItem, "ipConfigurations"); var ipName = GetNameById(idItem, "publicIPAddresses"); var vmssListPageResult = networkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetVMPublicIPAddresses( resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName, ipConfigName); var vmssListResult = vmssListPageResult.ToList(); Assert.Single(vmssListResult); var vmssGetResult = networkManagementClient.PublicIPAddresses.GetVirtualMachineScaleSetPublicIPAddress( resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName, ipConfigName, ipName); Assert.NotNull(vmssGetResult); Assert.Equal("Succeeded", vmssGetResult.ProvisioningState); Assert.NotNull(vmssGetResult.ResourceGuid); resourcesClient.ResourceGroups.Delete(resourceGroupName); } }
public void RouteFilterApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1, true); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/routefilters"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = location }); // Create route filter string filterName = "filter"; string ruleName = "rule"; var filter = TestHelper.CreateDefaultRouteFilter(resourceGroupName, filterName, location, networkManagementClient); Assert.Equal(filter.Name, filterName); Assert.Empty(filter.Rules); // Update route filter with rule by put on parent resources filter = TestHelper.CreateDefaultRouteFilter(resourceGroupName, filterName, location, networkManagementClient, true); Assert.Equal(filter.Name, filterName); Assert.NotEmpty(filter.Rules); // Update route filter and delete rules filter = TestHelper.CreateDefaultRouteFilter(resourceGroupName, filterName, location, networkManagementClient); Assert.Equal(filter.Name, filterName); Assert.Empty(filter.Rules); filter = TestHelper.CreateDefaultRouteFilterRule(resourceGroupName, filterName, ruleName, location, networkManagementClient); Assert.Equal(filter.Name, filterName); Assert.NotEmpty(filter.Rules); resourcesClient.ResourceGroups.Delete(resourceGroupName); } }
public async Task BGPCommunityApiTest() { _ = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/routefilters"); AsyncPageable <Models.BgpServiceCommunity> communitiesAsync = NetworkManagementClient.BgpServiceCommunities.ListAsync(); Task <List <Models.BgpServiceCommunity> > communities = communitiesAsync.ToEnumerableAsync(); Assert.NotNull(communities); Assert.True(communities.Result.First().BgpCommunities.First().IsAuthorizedToUse); }
public async Task VmssNetworkInterfaceApiTest() { string resourceGroupName = Recording.GenerateAssetName("azsmnet"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Compute/virtualMachineScaleSets"); string deploymentName = Recording.GenerateAssetName("vmss"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); await CreateVmss(ResourceManagementClient, resourceGroupName, deploymentName); string virtualMachineScaleSetName = "vmssip"; AsyncPageable <PublicIPAddress> vmssListAllPageResultAP = NetworkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetPublicIPAddressesAsync(resourceGroupName, virtualMachineScaleSetName); List <PublicIPAddress> vmssListAllPageResult = await vmssListAllPageResultAP.ToEnumerableAsync(); List <PublicIPAddress> vmssListAllResult = vmssListAllPageResult.ToList(); PublicIPAddress firstResult = vmssListAllResult.First(); Assert.NotNull(vmssListAllResult); Assert.AreEqual("Succeeded", firstResult.ProvisioningState.ToString()); Assert.NotNull(firstResult.ResourceGuid); string idItem = firstResult.Id; string vmIndex = GetNameById(idItem, "virtualMachines"); string nicName = GetNameById(idItem, "networkInterfaces"); // Verify that NICs contain refernce to publicip, nsg and dns settings AsyncPageable <NetworkInterface> listNicPerVmssAP = NetworkManagementClient.NetworkInterfaces.ListVirtualMachineScaleSetNetworkInterfacesAsync(resourceGroupName, virtualMachineScaleSetName); List <NetworkInterface> listNicPerVmss = await listNicPerVmssAP.ToEnumerableAsync(); Assert.NotNull(listNicPerVmss); foreach (NetworkInterface nic in listNicPerVmss) { VerifyVmssNicProperties(nic); } // Verify nics on a vm level AsyncPageable <NetworkInterface> listNicPerVmAP = NetworkManagementClient.NetworkInterfaces.ListVirtualMachineScaleSetVMNetworkInterfacesAsync(resourceGroupName, virtualMachineScaleSetName, vmIndex); List <NetworkInterface> listNicPerVm = await listNicPerVmAP.ToEnumerableAsync(); Assert.NotNull(listNicPerVm); Has.One.EqualTo(listNicPerVm); foreach (NetworkInterface nic in listNicPerVm) { VerifyVmssNicProperties(nic); } // Verify getting individual nic Response <NetworkInterface> getNic = await NetworkManagementClient.NetworkInterfaces.GetVirtualMachineScaleSetNetworkInterfaceAsync(resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName); Assert.NotNull(getNic); VerifyVmssNicProperties(getNic); }
public void ApplicationGatewayApiTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler); var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/applicationgateways"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); var vnetName = TestUtilities.GenerateName(); var subnetName = TestUtilities.GenerateName(); var virtualNetwork = TestHelper.CreateVirtualNetwork(vnetName, subnetName, resourceGroupName, location, networkResourceProviderClient); var getSubnetResponse = networkResourceProviderClient.Subnets.Get(resourceGroupName, vnetName, subnetName); Console.WriteLine("Virtual Network GatewaySubnet Id: {0}", getSubnetResponse.Subnet.Id); var subnet = getSubnetResponse.Subnet; var appGw = CreateApplicationGateway(location, subnet, resourceGroupName, networkResourceProviderClient.Credentials.SubscriptionId); // Put AppGw var putAppGwResponse = networkResourceProviderClient.ApplicationGateways.CreateOrUpdate(resourceGroupName, appGw.Name, appGw); Assert.Equal(HttpStatusCode.OK, putAppGwResponse.StatusCode); Assert.Equal("Succeeded", putAppGwResponse.Status); // Get AppGw var getResp = networkResourceProviderClient.ApplicationGateways.Get(resourceGroupName, appGw.Name); CompareApplicationGateway(appGw, getResp.ApplicationGateway); //Start AppGw var startResult = networkResourceProviderClient.ApplicationGateways.Start(resourceGroupName, appGw.Name); Assert.Equal(HttpStatusCode.OK, startResult.StatusCode); Assert.Equal("Succeeded", startResult.Status); //Stop AppGw var stopResult = networkResourceProviderClient.ApplicationGateways.Stop(resourceGroupName, appGw.Name); Assert.Equal(HttpStatusCode.OK, stopResult.StatusCode); Assert.Equal("Succeeded", stopResult.Status); // Delete AppGw var deleteResult = networkResourceProviderClient.ApplicationGateways.Delete(resourceGroupName, appGw.Name); Assert.Equal(HttpStatusCode.OK, deleteResult.StatusCode); } }
public void UsageTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler); var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkSecurityGroups"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); string networkSecurityGroupName = TestUtilities.GenerateName(); var networkSecurityGroup = new NetworkSecurityGroup() { Location = location, }; // Put Nsg var putNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup); Assert.Equal(HttpStatusCode.OK, putNsgResponse.StatusCode); Assert.Equal("Succeeded", putNsgResponse.Status); var getNsgResponse = networkResourceProviderClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName); Assert.Equal(HttpStatusCode.OK, getNsgResponse.StatusCode); // Query for usages var usagesResponse = networkResourceProviderClient.Usages.List(getNsgResponse.NetworkSecurityGroup.Location.Replace(" ", string.Empty)); Assert.True(usagesResponse.StatusCode == HttpStatusCode.OK); // Verify that the strings are populated Assert.NotNull(usagesResponse.Usages); Assert.True(usagesResponse.Usages.Any()); foreach (var usage in usagesResponse.Usages) { Assert.True(usage.Limit > 0); Assert.NotNull(usage.Name); Assert.True(!string.IsNullOrEmpty(usage.Name.LocalizedValue)); Assert.True(!string.IsNullOrEmpty(usage.Name.Value)); } } }
public async Task CheckDnsAvailabilityTest() { string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/publicIPAddresses"); location = location.Replace(" ", ""); string domainNameLabel = Recording.GenerateAssetName("domainnamelabel"); Response <Models.DnsNameAvailabilityResult> dnsNameAvailability = await ServiceOperations.CheckDnsNameAvailabilityAsync(location, domainNameLabel); Assert.True(dnsNameAvailability.Value.Available); }
public async Task CheckPrivateLinkServiceVisibilityTest() { string resourceGroupName = Recording.GenerateAssetName("cplsrg"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/connections"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); var param = new CheckPrivateLinkServiceVisibilityRequest("mypls.00000000-0000-0000-0000-000000000000.azure.privatelinkservice"); var checkRawResponse = await PrivateLinkServicesOperations.StartCheckPrivateLinkServiceVisibilityByResourceGroupAsync(location, resourceGroupName, param); PrivateLinkServiceVisibility response = await WaitForCompletionAsync(checkRawResponse); Assert.False(response.Visible); }
public async Task EmptyRouteTableTest() { string resourceGroupName = Recording.GenerateAssetName("csmrg"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/routeTables"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); string routeTableName = Recording.GenerateAssetName("azsmnet"); RouteTable routeTable = new RouteTable() { Location = location, }; // Put RouteTable RouteTablesCreateOrUpdateOperation putRouteTableResponseOperation = await NetworkManagementClient.RouteTables.StartCreateOrUpdateAsync(resourceGroupName, routeTableName, routeTable); Response <RouteTable> putRouteTableResponse = await WaitForCompletionAsync(putRouteTableResponseOperation); Assert.AreEqual("Succeeded", putRouteTableResponse.Value.ProvisioningState.ToString()); // Get RouteTable Response <RouteTable> getRouteTableResponse = await NetworkManagementClient.RouteTables.GetAsync(resourceGroupName, routeTableName); Assert.AreEqual(routeTableName, getRouteTableResponse.Value.Name); Assert.False(getRouteTableResponse.Value.Routes.Any()); // List RouteTable AsyncPageable <RouteTable> listRouteTableResponseAP = NetworkManagementClient.RouteTables.ListAsync(resourceGroupName); List <RouteTable> listRouteTableResponse = await listRouteTableResponseAP.ToEnumerableAsync(); Has.One.EqualTo(listRouteTableResponse); Assert.AreEqual(getRouteTableResponse.Value.Name, listRouteTableResponse.First().Name); Assert.AreEqual(getRouteTableResponse.Value.Id, listRouteTableResponse.First().Id); // Delete RouteTable RouteTablesDeleteOperation deleteOperation = await NetworkManagementClient.RouteTables.StartDeleteAsync(resourceGroupName, routeTableName); await WaitForCompletionAsync(deleteOperation); // Verify delete listRouteTableResponseAP = NetworkManagementClient.RouteTables.ListAsync(resourceGroupName); listRouteTableResponse = await listRouteTableResponseAP.ToEnumerableAsync(); Assert.IsEmpty(listRouteTableResponse); }
public async Task VmssPublicIpAddressApiTest() { string resourceGroupName = Recording.GenerateAssetName("azsmnet"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Compute/virtualMachineScaleSets"); string deploymentName = Recording.GenerateAssetName("vmss"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); await CreateVmss(ResourceManagementClient, resourceGroupName, deploymentName); string virtualMachineScaleSetName = "vmssip"; AsyncPageable <PublicIPAddress> vmssListAllPageResultAP = NetworkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetPublicIPAddressesAsync(resourceGroupName, virtualMachineScaleSetName); List <PublicIPAddress> vmssListAllPageResult = await vmssListAllPageResultAP.ToEnumerableAsync(); List <PublicIPAddress> vmssListAllResult = vmssListAllPageResult.ToList(); PublicIPAddress firstResult = vmssListAllResult.First(); Assert.NotNull(vmssListAllResult); Assert.AreEqual("Succeeded", firstResult.ProvisioningState.ToString()); Assert.NotNull(firstResult.ResourceGuid); string idItem = firstResult.Id; string vmIndex = GetNameById(idItem, "virtualMachines"); string nicName = GetNameById(idItem, "networkInterfaces"); string ipConfigName = GetNameById(idItem, "ipConfigurations"); string ipName = GetNameById(idItem, "publicIPAddresses"); AsyncPageable <PublicIPAddress> vmssListPageResultAP = NetworkManagementClient.PublicIPAddresses.ListVirtualMachineScaleSetVMPublicIPAddressesAsync( resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName, ipConfigName); List <PublicIPAddress> vmssListPageResult = await vmssListPageResultAP.ToEnumerableAsync(); List <PublicIPAddress> vmssListResult = vmssListPageResult.ToList(); Has.One.EqualTo(vmssListResult); Response <PublicIPAddress> vmssGetResult = await NetworkManagementClient.PublicIPAddresses.GetVirtualMachineScaleSetPublicIPAddressAsync( resourceGroupName, virtualMachineScaleSetName, vmIndex, nicName, ipConfigName, ipName); Assert.NotNull(vmssGetResult); Assert.AreEqual("Succeeded", vmssGetResult.Value.ProvisioningState.ToString()); Assert.NotNull(vmssGetResult.Value.ResourceGuid); }
public void CheckDnsAvailabilityTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler); var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler); var location = GetNrpServiceEndpoint(NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/virtualNetworks")); string domainNameLabel = TestUtilities.GenerateName("domainnamelabel"); var dnsNameAvailability = networkResourceProviderClient.CheckDnsNameAvailability(location, domainNameLabel); Assert.True(dnsNameAvailability.DnsNameAvailability); } }
public void BGPCommunityApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/routefilters"); var communities = networkManagementClient.BgpServiceCommunities.List(); Assert.NotNull(communities); Assert.True(communities.First().BgpCommunities.First().IsAuthorizedToUse); } }
public async Task UsageTest() { string resourceGroupName = Recording.GenerateAssetName("csmrg"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/networkSecurityGroups"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); string networkSecurityGroupName = Recording.GenerateAssetName("azsmnet"); NetworkSecurityGroup networkSecurityGroup = new NetworkSecurityGroup() { Location = location, }; // Put Nsg NetworkSecurityGroupsCreateOrUpdateOperation putNsgResponseOperation = await NetworkManagementClient.NetworkSecurityGroups.StartCreateOrUpdateAsync(resourceGroupName, networkSecurityGroupName, networkSecurityGroup); Response <NetworkSecurityGroup> putNsgResponse = await WaitForCompletionAsync(putNsgResponseOperation); Assert.AreEqual("Succeeded", putNsgResponse.Value.ProvisioningState.ToString()); Response <NetworkSecurityGroup> getNsgResponse = await NetworkManagementClient.NetworkSecurityGroups.GetAsync(resourceGroupName, networkSecurityGroupName); // Query for usages AsyncPageable <Usage> usagesResponseAP = NetworkManagementClient.Usages.ListAsync(getNsgResponse.Value.Location.Replace(" ", string.Empty)); List <Usage> usagesResponse = await usagesResponseAP.ToEnumerableAsync(); // Verify that the strings are populated Assert.NotNull(usagesResponse); Assert.True(usagesResponse.Any()); foreach (Usage usage in usagesResponse) { Assert.True(usage.Limit > 0); Assert.NotNull(usage.Name); Assert.True(!string.IsNullOrEmpty(usage.Name.LocalizedValue)); Assert.True(!string.IsNullOrEmpty(usage.Name.Value)); } }
public async Task RouteFilterApiTest() { string resourceGroupName = Recording.GenerateAssetName("csmrg"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/routefilters"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); // Create route filter string filterName = "filter"; string ruleName = "rule"; Models.RouteFilter filter = await CreateDefaultRouteFilter(resourceGroupName, filterName, location, NetworkManagementClient); Assert.AreEqual(filter.Name, filterName); Assert.IsEmpty(filter.Rules); // Update route filter with rule by put on parent resources filter = await CreateDefaultRouteFilter(resourceGroupName, filterName, location, NetworkManagementClient, true); Assert.AreEqual(filter.Name, filterName); Assert.IsNotEmpty(filter.Rules); // Update route filter and delete rules filter = await CreateDefaultRouteFilter(resourceGroupName, filterName, location, NetworkManagementClient); Assert.AreEqual(filter.Name, filterName); Assert.IsEmpty(filter.Rules); filter = await CreateDefaultRouteFilterRule(resourceGroupName, filterName, ruleName, location, NetworkManagementClient); Assert.AreEqual(filter.Name, filterName); Assert.IsNotEmpty(filter.Rules); }
public void CheckDnsAvailabilityTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/publicIPAddresses"); location = location.Replace(" ", ""); string domainNameLabel = TestUtilities.GenerateName("domainnamelabel"); var dnsNameAvailability = networkManagementClient.CheckDnsNameAvailability(location, domainNameLabel); Assert.True(dnsNameAvailability.Available); } }
public async Task RoutesApiTest() { string resourceGroupName = Recording.GenerateAssetName("csmrg"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/routeTables"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); string routeTableName = Recording.GenerateAssetName("azsmnet"); string route1Name = Recording.GenerateAssetName("azsmnet"); string route2Name = Recording.GenerateAssetName("azsmnet"); RouteTable routeTable = new RouteTable() { Location = location, }; // Add a route Route route1 = new Route() { AddressPrefix = "192.168.1.0/24", Name = route1Name, NextHopIpAddress = "23.108.1.1", NextHopType = RouteNextHopType.VirtualAppliance }; routeTable.Routes.Add(route1); // Put RouteTable RouteTablesCreateOrUpdateOperation putRouteTableResponseOperation = await NetworkManagementClient.RouteTables.StartCreateOrUpdateAsync(resourceGroupName, routeTableName, routeTable); Response <RouteTable> putRouteTableResponse = await WaitForCompletionAsync(putRouteTableResponseOperation); Assert.AreEqual("Succeeded", putRouteTableResponse.Value.ProvisioningState.ToString()); // Get RouteTable Response <RouteTable> getRouteTableResponse = await NetworkManagementClient.RouteTables.GetAsync(resourceGroupName, routeTableName); Assert.AreEqual(routeTableName, getRouteTableResponse.Value.Name); Assert.AreEqual(1, getRouteTableResponse.Value.Routes.Count); Assert.AreEqual(route1Name, getRouteTableResponse.Value.Routes[0].Name); Assert.AreEqual("192.168.1.0/24", getRouteTableResponse.Value.Routes[0].AddressPrefix); Assert.AreEqual("23.108.1.1", getRouteTableResponse.Value.Routes[0].NextHopIpAddress); Assert.AreEqual(RouteNextHopType.VirtualAppliance, getRouteTableResponse.Value.Routes[0].NextHopType); // Get Route Response <Route> getRouteResponse = await NetworkManagementClient.Routes.GetAsync(resourceGroupName, routeTableName, route1Name); Assert.AreEqual(routeTableName, getRouteTableResponse.Value.Name); Assert.AreEqual(1, getRouteTableResponse.Value.Routes.Count); Assert.AreEqual(getRouteResponse.Value.Name, getRouteTableResponse.Value.Routes[0].Name); Assert.AreEqual(getRouteResponse.Value.AddressPrefix, getRouteTableResponse.Value.Routes[0].AddressPrefix); Assert.AreEqual(getRouteResponse.Value.NextHopIpAddress, getRouteTableResponse.Value.Routes[0].NextHopIpAddress); Assert.AreEqual(getRouteResponse.Value.NextHopType, getRouteTableResponse.Value.Routes[0].NextHopType); // Add another route Route route2 = new Route() { AddressPrefix = "10.0.1.0/24", Name = route2Name, NextHopType = RouteNextHopType.VnetLocal }; await NetworkManagementClient.Routes.StartCreateOrUpdateAsync(resourceGroupName, routeTableName, route2Name, route2); getRouteTableResponse = await NetworkManagementClient.RouteTables.GetAsync(resourceGroupName, routeTableName); Assert.AreEqual(routeTableName, getRouteTableResponse.Value.Name); Assert.AreEqual(2, getRouteTableResponse.Value.Routes.Count); Assert.AreEqual(route2Name, getRouteTableResponse.Value.Routes[1].Name); Assert.AreEqual("10.0.1.0/24", getRouteTableResponse.Value.Routes[1].AddressPrefix); Assert.True(string.IsNullOrEmpty(getRouteTableResponse.Value.Routes[1].NextHopIpAddress)); Assert.AreEqual(RouteNextHopType.VnetLocal, getRouteTableResponse.Value.Routes[1].NextHopType); Response <Route> getRouteResponse2 = await NetworkManagementClient.Routes.GetAsync(resourceGroupName, routeTableName, route2Name); Assert.AreEqual(getRouteResponse2.Value.Name, getRouteTableResponse.Value.Routes[1].Name); Assert.AreEqual(getRouteResponse2.Value.AddressPrefix, getRouteTableResponse.Value.Routes[1].AddressPrefix); Assert.AreEqual(getRouteResponse2.Value.NextHopIpAddress, getRouteTableResponse.Value.Routes[1].NextHopIpAddress); Assert.AreEqual(getRouteResponse2.Value.NextHopType, getRouteTableResponse.Value.Routes[1].NextHopType); // list route AsyncPageable <Route> listRouteResponseAP = NetworkManagementClient.Routes.ListAsync(resourceGroupName, routeTableName); List <Route> listRouteResponse = await listRouteResponseAP.ToEnumerableAsync(); Assert.AreEqual(2, listRouteResponse.Count()); Assert.AreEqual(getRouteResponse.Value.Name, listRouteResponse.First().Name); Assert.AreEqual(getRouteResponse.Value.AddressPrefix, listRouteResponse.First().AddressPrefix); Assert.AreEqual(getRouteResponse.Value.NextHopIpAddress, listRouteResponse.First().NextHopIpAddress); Assert.AreEqual(getRouteResponse.Value.NextHopType, listRouteResponse.First().NextHopType); Assert.AreEqual(getRouteResponse2.Value.Name, listRouteResponse.ElementAt(1).Name); Assert.AreEqual(getRouteResponse2.Value.AddressPrefix, listRouteResponse.ElementAt(1).AddressPrefix); Assert.AreEqual(getRouteResponse2.Value.NextHopIpAddress, listRouteResponse.ElementAt(1).NextHopIpAddress); Assert.AreEqual(getRouteResponse2.Value.NextHopType, listRouteResponse.ElementAt(1).NextHopType); // Delete a route await NetworkManagementClient.Routes.StartDeleteAsync(resourceGroupName, routeTableName, route1Name); listRouteResponseAP = NetworkManagementClient.Routes.ListAsync(resourceGroupName, routeTableName); listRouteResponse = await listRouteResponseAP.ToEnumerableAsync(); Has.One.EqualTo(listRouteResponse); Assert.AreEqual(getRouteResponse2.Value.Name, listRouteResponse.First().Name); Assert.AreEqual(getRouteResponse2.Value.AddressPrefix, listRouteResponse.First().AddressPrefix); Assert.AreEqual(getRouteResponse2.Value.NextHopIpAddress, listRouteResponse.First().NextHopIpAddress); Assert.AreEqual(getRouteResponse2.Value.NextHopType, listRouteResponse.First().NextHopType); // Delete route await NetworkManagementClient.Routes.StartDeleteAsync(resourceGroupName, routeTableName, route2Name); listRouteResponseAP = NetworkManagementClient.Routes.ListAsync(resourceGroupName, routeTableName); listRouteResponse = await listRouteResponseAP.ToEnumerableAsync(); Assert.IsEmpty(listRouteResponse); // Delete RouteTable await NetworkManagementClient.RouteTables.StartDeleteAsync(resourceGroupName, routeTableName); // Verify delete AsyncPageable <RouteTable> listRouteTableResponseAP = NetworkManagementClient.RouteTables.ListAsync(resourceGroupName); List <RouteTable> listRouteTableResponse = await listRouteTableResponseAP.ToEnumerableAsync(); Assert.IsEmpty(listRouteTableResponse); }
public void VirtualNetworkApiTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler); var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/virtualNetworks"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); string vnetName = TestUtilities.GenerateName(); string subnet1Name = TestUtilities.GenerateName(); string subnet2Name = TestUtilities.GenerateName(); var vnet = new VirtualNetwork() { Location = location, AddressSpace = new AddressSpace() { AddressPrefixes = new List <string>() { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = new List <string>() { "10.1.1.1", "10.1.2.4" } }, Subnets = new List <Subnet>() { new Subnet() { Name = subnet1Name, AddressPrefix = "10.0.1.0/24", }, new Subnet() { Name = subnet2Name, AddressPrefix = "10.0.2.0/24", } } }; // Put Vnet var putVnetResponse = networkResourceProviderClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, vnetName, vnet); Assert.Equal(HttpStatusCode.OK, putVnetResponse.StatusCode); Assert.Equal("Succeeded", putVnetResponse.Status); // Get Vnet var getVnetResponse = networkResourceProviderClient.VirtualNetworks.Get(resourceGroupName, vnetName); Assert.Equal(HttpStatusCode.OK, getVnetResponse.StatusCode); Assert.Equal(vnetName, getVnetResponse.VirtualNetwork.Name); Assert.NotNull(getVnetResponse.VirtualNetwork.ResourceGuid); Assert.Equal(Microsoft.Azure.Management.Resources.Models.ProvisioningState.Succeeded, getVnetResponse.VirtualNetwork.ProvisioningState); Assert.Equal("10.1.1.1", getVnetResponse.VirtualNetwork.DhcpOptions.DnsServers[0]); Assert.Equal("10.1.2.4", getVnetResponse.VirtualNetwork.DhcpOptions.DnsServers[1]); Assert.Equal("10.0.0.0/16", getVnetResponse.VirtualNetwork.AddressSpace.AddressPrefixes[0]); Assert.Equal(subnet1Name, getVnetResponse.VirtualNetwork.Subnets[0].Name); Assert.Equal(subnet2Name, getVnetResponse.VirtualNetwork.Subnets[1].Name); // Get all Vnets var getAllVnets = networkResourceProviderClient.VirtualNetworks.List(resourceGroupName); Assert.Equal(HttpStatusCode.OK, getAllVnets.StatusCode); Assert.Equal(vnetName, getAllVnets.VirtualNetworks[0].Name); Assert.Equal(Microsoft.Azure.Management.Resources.Models.ProvisioningState.Succeeded, getAllVnets.VirtualNetworks[0].ProvisioningState); Assert.Equal("10.0.0.0/16", getAllVnets.VirtualNetworks[0].AddressSpace.AddressPrefixes[0]); Assert.Equal(subnet1Name, getAllVnets.VirtualNetworks[0].Subnets[0].Name); Assert.Equal(subnet2Name, getAllVnets.VirtualNetworks[0].Subnets[1].Name); // Get all Vnets in a subscription var getAllVnetInSubscription = networkResourceProviderClient.VirtualNetworks.ListAll(); Assert.Equal(HttpStatusCode.OK, getAllVnetInSubscription.StatusCode); Assert.Equal(vnetName, getAllVnetInSubscription.VirtualNetworks[0].Name); Assert.Equal(Microsoft.Azure.Management.Resources.Models.ProvisioningState.Succeeded, getAllVnetInSubscription.VirtualNetworks[0].ProvisioningState); Assert.Equal("10.0.0.0/16", getAllVnetInSubscription.VirtualNetworks[0].AddressSpace.AddressPrefixes[0]); Assert.Equal(subnet1Name, getAllVnetInSubscription.VirtualNetworks[0].Subnets[0].Name); Assert.Equal(subnet2Name, getAllVnetInSubscription.VirtualNetworks[0].Subnets[1].Name); // Delete Vnet var deleteVnetResponse = networkResourceProviderClient.VirtualNetworks.Delete(resourceGroupName, vnetName); Assert.Equal(HttpStatusCode.OK, deleteVnetResponse.StatusCode); // Get all Vnets getAllVnets = networkResourceProviderClient.VirtualNetworks.List(resourceGroupName); Assert.Equal(HttpStatusCode.OK, getAllVnets.StatusCode); Assert.Equal(0, getAllVnets.VirtualNetworks.Count); } }
public void PublicIpAddressApiTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler); var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/publicIPAddresses"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); // Create the parameter for PUT PublicIpAddress string publicIpName = TestUtilities.GenerateName(); string domainNameLabel = TestUtilities.GenerateName(); var publicIp = new PublicIpAddress() { Location = location, Tags = new Dictionary <string, string>() { { "key", "value" } }, PublicIpAllocationMethod = IpAllocationMethod.Dynamic, DnsSettings = new PublicIpAddressDnsSettings() { DomainNameLabel = domainNameLabel } }; // Put PublicIpAddress var putPublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.CreateOrUpdate(resourceGroupName, publicIpName, publicIp); Assert.Equal(HttpStatusCode.OK, putPublicIpAddressResponse.StatusCode); Assert.Equal("Succeeded", putPublicIpAddressResponse.Status); // Get PublicIpAddress var getPublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.Get(resourceGroupName, publicIpName); Assert.Equal(HttpStatusCode.OK, getPublicIpAddressResponse.StatusCode); Assert.Equal(4, getPublicIpAddressResponse.PublicIpAddress.IdleTimeoutInMinutes); Assert.NotNull(getPublicIpAddressResponse.PublicIpAddress.ResourceGuid); // Get List of PublicIpAddress var getPublicIpAddressListResponse = networkResourceProviderClient.PublicIpAddresses.List(resourceGroupName); Assert.Equal(HttpStatusCode.OK, getPublicIpAddressListResponse.StatusCode); Assert.Equal(1, getPublicIpAddressListResponse.PublicIpAddresses.Count); ArePublicIpAddressesEqual(getPublicIpAddressResponse.PublicIpAddress, getPublicIpAddressListResponse.PublicIpAddresses[0]); // Get List of PublicIpAddress in a subscription var getPublicIpAddressListSubscriptionResponse = networkResourceProviderClient.PublicIpAddresses.ListAll(); Assert.Equal(HttpStatusCode.OK, getPublicIpAddressListSubscriptionResponse.StatusCode); Assert.Equal(1, getPublicIpAddressListSubscriptionResponse.PublicIpAddresses.Count); ArePublicIpAddressesEqual(getPublicIpAddressResponse.PublicIpAddress, getPublicIpAddressListSubscriptionResponse.PublicIpAddresses[0]); // Delete PublicIpAddress var deletePublicIpAddressResponse = networkResourceProviderClient.PublicIpAddresses.Delete(resourceGroupName, publicIpName); Assert.Equal(HttpStatusCode.OK, deletePublicIpAddressResponse.StatusCode); // Get PublicIpAddress getPublicIpAddressListResponse = networkResourceProviderClient.PublicIpAddresses.List(resourceGroupName); Assert.Equal(HttpStatusCode.OK, getPublicIpAddressListResponse.StatusCode); Assert.Equal(0, getPublicIpAddressListResponse.PublicIpAddresses.Count); } }
public void ExpandResourceTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/loadBalancers"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = location }); // Create lbPublicIP string lbPublicIpName = TestUtilities.GenerateName(); string lbDomaingNameLabel = TestUtilities.GenerateName(); var lbPublicIp = TestHelper.CreateDefaultPublicIpAddress( lbPublicIpName, resourceGroupName, lbDomaingNameLabel, location, networkManagementClient); // Create Vnet string vnetName = TestUtilities.GenerateName(); string subnetName = TestUtilities.GenerateName(); var vnet = TestHelper.CreateVirtualNetwork(vnetName, subnetName, resourceGroupName, location, networkManagementClient); // Create Nics string nic1name = TestUtilities.GenerateName(); string nic2name = TestUtilities.GenerateName(); string nic3name = TestUtilities.GenerateName(); var nic1 = TestHelper.CreateNetworkInterface( nic1name, resourceGroupName, null, vnet.Subnets[0].Id, location, "ipconfig", networkManagementClient); var nic2 = TestHelper.CreateNetworkInterface( nic2name, resourceGroupName, null, vnet.Subnets[0].Id, location, "ipconfig", networkManagementClient); var nic3 = TestHelper.CreateNetworkInterface( nic3name, resourceGroupName, null, vnet.Subnets[0].Id, location, "ipconfig", networkManagementClient); // Create the LoadBalancer var lbName = TestUtilities.GenerateName(); var frontendIpConfigName = TestUtilities.GenerateName(); var backEndAddressPoolName = TestUtilities.GenerateName(); var loadBalancingRuleName = TestUtilities.GenerateName(); var probeName = TestUtilities.GenerateName(); var inboundNatRule1Name = TestUtilities.GenerateName(); var inboundNatRule2Name = TestUtilities.GenerateName(); // Populate the loadBalancerCreateOrUpdateParameter var loadBalancer = new LoadBalancer() { Location = location, FrontendIPConfigurations = new List <FrontendIPConfiguration>() { new FrontendIPConfiguration() { Name = frontendIpConfigName, PublicIPAddress = new PublicIPAddress() { Id = lbPublicIp.Id } } }, BackendAddressPools = new List <BackendAddressPool>() { new BackendAddressPool() { Name = backEndAddressPoolName, } }, LoadBalancingRules = new List <LoadBalancingRule>() { new LoadBalancingRule() { Name = loadBalancingRuleName, FrontendIPConfiguration = new Microsoft.Azure.Management.Network.Models.SubResource() { Id = TestHelper.GetChildLbResourceId(networkManagementClient.SubscriptionId, resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName) }, Protocol = TransportProtocol.Tcp, FrontendPort = 80, BackendPort = 80, EnableFloatingIP = false, IdleTimeoutInMinutes = 15, BackendAddressPool = new Microsoft.Azure.Management.Network.Models.SubResource() { Id = TestHelper.GetChildLbResourceId(networkManagementClient.SubscriptionId, resourceGroupName, lbName, "backendAddressPools", backEndAddressPoolName) }, Probe = new Microsoft.Azure.Management.Network.Models.SubResource() { Id = TestHelper.GetChildLbResourceId(networkManagementClient.SubscriptionId, resourceGroupName, lbName, "probes", probeName) } } }, Probes = new List <Probe>() { new Probe() { Name = probeName, Protocol = ProbeProtocol.Http, Port = 80, RequestPath = "healthcheck.aspx", IntervalInSeconds = 10, NumberOfProbes = 2 } }, InboundNatRules = new List <InboundNatRule>() { new InboundNatRule() { Name = inboundNatRule1Name, FrontendIPConfiguration = new Microsoft.Azure.Management.Network.Models.SubResource() { Id = TestHelper.GetChildLbResourceId(networkManagementClient.SubscriptionId, resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName) }, Protocol = TransportProtocol.Tcp, FrontendPort = 3389, BackendPort = 3389, IdleTimeoutInMinutes = 15, EnableFloatingIP = false }, new InboundNatRule() { Name = inboundNatRule2Name, FrontendIPConfiguration = new Microsoft.Azure.Management.Network.Models.SubResource() { Id = TestHelper.GetChildLbResourceId(networkManagementClient.SubscriptionId, resourceGroupName, lbName, "FrontendIPConfigurations", frontendIpConfigName) }, Protocol = TransportProtocol.Tcp, FrontendPort = 3390, BackendPort = 3389, IdleTimeoutInMinutes = 15, EnableFloatingIP = false, } } }; // Create the loadBalancer var putLoadBalancer = networkManagementClient.LoadBalancers.CreateOrUpdate(resourceGroupName, lbName, loadBalancer); var getLoadBalancer = networkManagementClient.LoadBalancers.Get(resourceGroupName, lbName); // Associate the nic with LB nic1.IpConfigurations.First().LoadBalancerBackendAddressPools = new List <BackendAddressPool> { getLoadBalancer.BackendAddressPools.First() }; nic1.IpConfigurations.First().LoadBalancerInboundNatRules = new List <InboundNatRule> { getLoadBalancer.InboundNatRules.First() }; nic2.IpConfigurations.First().LoadBalancerBackendAddressPools = new List <BackendAddressPool> { getLoadBalancer.BackendAddressPools.First() }; nic3.IpConfigurations.First().LoadBalancerInboundNatRules = new List <InboundNatRule> { getLoadBalancer.InboundNatRules[1] }; // Put Nics networkManagementClient.NetworkInterfaces.CreateOrUpdate(resourceGroupName, nic1name, nic1); networkManagementClient.NetworkInterfaces.CreateOrUpdate(resourceGroupName, nic2name, nic2); networkManagementClient.NetworkInterfaces.CreateOrUpdate(resourceGroupName, nic3name, nic3); // Get Nics nic1 = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, nic1name); nic2 = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, nic2name); nic3 = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, nic3name); // Get lb with expanded nics from nat rules getLoadBalancer = networkManagementClient.LoadBalancers.Get(resourceGroupName, lbName, "InboundNatRules/backendIPConfiguration"); foreach (var natRule in getLoadBalancer.InboundNatRules) { Assert.NotNull(natRule.BackendIPConfiguration); Assert.NotNull(natRule.BackendIPConfiguration.Id); Assert.NotNull(natRule.BackendIPConfiguration.Name); Assert.NotNull(natRule.BackendIPConfiguration.Etag); Assert.Equal(natRule.Id, natRule.BackendIPConfiguration.LoadBalancerInboundNatRules[0].Id); } // Get lb with expanded nics from pools getLoadBalancer = networkManagementClient.LoadBalancers.Get(resourceGroupName, lbName, "BackendAddressPools/backendIPConfigurations"); foreach (var pool in getLoadBalancer.BackendAddressPools) { foreach (var ipconfig in getLoadBalancer.BackendAddressPools.First().BackendIPConfigurations) { Assert.NotNull(ipconfig.Id); Assert.NotNull(ipconfig.Name); Assert.NotNull(ipconfig.Etag); Assert.Equal(pool.Id, ipconfig.LoadBalancerBackendAddressPools[0].Id); } } // Get lb with expanded publicip getLoadBalancer = networkManagementClient.LoadBalancers.Get(resourceGroupName, lbName, "FrontendIPConfigurations/PublicIPAddress"); foreach (var ipconfig in getLoadBalancer.FrontendIPConfigurations) { Assert.NotNull(ipconfig.PublicIPAddress); Assert.NotNull(ipconfig.PublicIPAddress.Id); Assert.NotNull(ipconfig.PublicIPAddress.Name); Assert.NotNull(ipconfig.PublicIPAddress.Etag); Assert.Equal(ipconfig.Id, ipconfig.PublicIPAddress.IpConfiguration.Id); } // Get NIC with expanded subnet nic1 = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, nic1name, "IPConfigurations/Subnet"); foreach (var ipconfig in nic1.IpConfigurations) { Assert.NotNull(ipconfig.Subnet); Assert.NotNull(ipconfig.Subnet.Id); Assert.NotNull(ipconfig.Subnet.Name); Assert.NotNull(ipconfig.Subnet.Etag); Assert.NotEqual(0, ipconfig.Subnet.IpConfigurations.Count()); } // Get subnet with expanded ipconfigurations var subnet = networkManagementClient.Subnets.Get( resourceGroupName, vnetName, subnetName, "IPConfigurations"); foreach (var ipconfig in subnet.IpConfigurations) { Assert.NotNull(ipconfig.Name); Assert.NotNull(ipconfig.Id); Assert.NotNull(ipconfig.Etag); Assert.NotNull(ipconfig.PrivateIPAddress); } // Get publicIPAddress with expanded ipconfigurations var publicip = networkManagementClient.PublicIPAddresses.Get( resourceGroupName, lbPublicIpName, "IPConfiguration"); Assert.NotNull(publicip.IpConfiguration); Assert.NotNull(publicip.IpConfiguration.Id); Assert.NotNull(publicip.IpConfiguration.Name); Assert.NotNull(publicip.IpConfiguration.Etag); // Delete LoadBalancer networkManagementClient.LoadBalancers.Delete(resourceGroupName, lbName); // Verify Delete var listLoadBalancer = networkManagementClient.LoadBalancers.List(resourceGroupName); Assert.Equal(0, listLoadBalancer.Count()); // Delete all NetworkInterfaces networkManagementClient.NetworkInterfaces.Delete(resourceGroupName, nic1name); networkManagementClient.NetworkInterfaces.Delete(resourceGroupName, nic2name); networkManagementClient.NetworkInterfaces.Delete(resourceGroupName, nic3name); // Delete all PublicIPAddresses networkManagementClient.PublicIPAddresses.Delete(resourceGroupName, lbPublicIpName); } }
public async Task SubnetResourceNavigationLinksTest() { 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.0.0/24", } } }; VirtualNetworksCreateOrUpdateOperation putVnetResponseOperation = await NetworkManagementClient.VirtualNetworks.StartCreateOrUpdateAsync(resourceGroupName, vnetName, vnet); await WaitForCompletionAsync(putVnetResponseOperation); Response <Subnet> getSubnetResponse = await NetworkManagementClient.Subnets.GetAsync(resourceGroupName, vnetName, subnetName); Assert.Null(getSubnetResponse.Value.ResourceNavigationLinks); //TODO:Need RedisManagementClient //redisClient.Redis.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, redisName, parameters: new RedisCreateOrUpdateParameters //{ // Location = location, // Sku = new Microsoft.Azure.Management.Redis.Models.Sku() // { // Name = SkuName.Premium, // Family = SkuFamily.P, // Capacity = 1 // }, // SubnetId = getSubnetResponse.Id //}).Wait(); // wait for maximum 30 minutes for cache to create //for (int i = 0; i < 60; i++) //{ // TestUtilities.Wait(new TimeSpan(0, 0, 30)); // RedisResource responseGet = redisClient.Redis.Get(resourceGroupName: resourceGroupName, name: redisName); // if ("succeeded".Equals(responseGet.ProvisioningState, StringComparison.OrdinalIgnoreCase)) // { // break; // } // Assert.False(i == 60, "Cache is not in succeeded state even after 30 min."); //} getSubnetResponse = await NetworkManagementClient.Subnets.GetAsync(resourceGroupName, vnetName, subnetName); Assert.AreEqual(1, getSubnetResponse.Value.ResourceNavigationLinks.Count); }
public void NetworkSecurityGroupWithRulesApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkSecurityGroups"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); string networkSecurityGroupName = TestUtilities.GenerateName(); string securityRule1 = TestUtilities.GenerateName(); string securityRule2 = TestUtilities.GenerateName(); string destinationPortRange = "123-3500"; var networkSecurityGroup = new NetworkSecurityGroup() { Location = location, SecurityRules = new List <SecurityRule>() { new SecurityRule() { Name = securityRule1, Access = SecurityRuleAccess.Allow, Description = "Test security rule", DestinationAddressPrefix = "*", DestinationPortRange = destinationPortRange, Direction = SecurityRuleDirection.Inbound, Priority = 500, Protocol = SecurityRuleProtocol.Tcp, SourceAddressPrefix = "*", SourcePortRange = "655" } } }; // Put Nsg var putNsgResponse = networkManagementClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup); Assert.Equal("Succeeded", putNsgResponse.ProvisioningState); // Get NSG var getNsgResponse = networkManagementClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName); Assert.Equal(networkSecurityGroupName, getNsgResponse.Name); Assert.Equal(6, getNsgResponse.DefaultSecurityRules.Count); Assert.Equal("AllowVnetInBound", getNsgResponse.DefaultSecurityRules[0].Name); Assert.Equal("AllowAzureLoadBalancerInBound", getNsgResponse.DefaultSecurityRules[1].Name); Assert.Equal("DenyAllInBound", getNsgResponse.DefaultSecurityRules[2].Name); Assert.Equal("AllowVnetOutBound", getNsgResponse.DefaultSecurityRules[3].Name); Assert.Equal("AllowInternetOutBound", getNsgResponse.DefaultSecurityRules[4].Name); Assert.Equal("DenyAllOutBound", getNsgResponse.DefaultSecurityRules[5].Name); // Verify the security rule Assert.Equal(SecurityRuleAccess.Allow, getNsgResponse.SecurityRules[0].Access); Assert.Equal("Test security rule", getNsgResponse.SecurityRules[0].Description); Assert.Equal("*", getNsgResponse.SecurityRules[0].DestinationAddressPrefix); Assert.Equal(destinationPortRange, getNsgResponse.SecurityRules[0].DestinationPortRange); Assert.Equal(SecurityRuleDirection.Inbound, getNsgResponse.SecurityRules[0].Direction); Assert.Equal(500, getNsgResponse.SecurityRules[0].Priority); Assert.Equal(SecurityRuleProtocol.Tcp, getNsgResponse.SecurityRules[0].Protocol); Assert.Equal("Succeeded", getNsgResponse.SecurityRules[0].ProvisioningState); Assert.Equal("*", getNsgResponse.SecurityRules[0].SourceAddressPrefix); Assert.Equal("655", getNsgResponse.SecurityRules[0].SourcePortRange); // List NSG var listNsgResponse = networkManagementClient.NetworkSecurityGroups.List(resourceGroupName); Assert.Single(listNsgResponse); Assert.Equal(networkSecurityGroupName, listNsgResponse.First().Name); Assert.Equal(6, listNsgResponse.First().DefaultSecurityRules.Count); Assert.Equal("AllowVnetInBound", listNsgResponse.First().DefaultSecurityRules[0].Name); Assert.Equal("AllowAzureLoadBalancerInBound", listNsgResponse.First().DefaultSecurityRules[1].Name); Assert.Equal("DenyAllInBound", listNsgResponse.First().DefaultSecurityRules[2].Name); Assert.Equal("AllowVnetOutBound", listNsgResponse.First().DefaultSecurityRules[3].Name); Assert.Equal("AllowInternetOutBound", listNsgResponse.First().DefaultSecurityRules[4].Name); Assert.Equal("DenyAllOutBound", listNsgResponse.First().DefaultSecurityRules[5].Name); Assert.Equal(getNsgResponse.Etag, listNsgResponse.First().Etag); // List NSG in a subscription var listNsgSubsciptionResponse = networkManagementClient.NetworkSecurityGroups.ListAll(); Assert.NotEmpty(listNsgSubsciptionResponse); // Add a new security rule var SecurityRule = new SecurityRule() { Name = securityRule2, Access = SecurityRuleAccess.Deny, Description = "Test outbound security rule", DestinationAddressPrefix = "*", DestinationPortRange = destinationPortRange, Direction = SecurityRuleDirection.Outbound, Priority = 501, Protocol = SecurityRuleProtocol.Udp, SourceAddressPrefix = "*", SourcePortRange = "656", }; networkSecurityGroup.SecurityRules.Add(SecurityRule); putNsgResponse = networkManagementClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup); // Get NSG getNsgResponse = networkManagementClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName); // Verify the security rule Assert.Equal(SecurityRuleAccess.Deny, getNsgResponse.SecurityRules[1].Access); Assert.Equal("Test outbound security rule", getNsgResponse.SecurityRules[1].Description); Assert.Equal("*", getNsgResponse.SecurityRules[1].DestinationAddressPrefix); Assert.Equal(destinationPortRange, getNsgResponse.SecurityRules[1].DestinationPortRange); Assert.Equal(SecurityRuleDirection.Outbound, getNsgResponse.SecurityRules[1].Direction); Assert.Equal(501, getNsgResponse.SecurityRules[1].Priority); Assert.Equal(SecurityRuleProtocol.Udp, getNsgResponse.SecurityRules[1].Protocol); Assert.Equal("Succeeded", getNsgResponse.SecurityRules[1].ProvisioningState); Assert.Equal("*", getNsgResponse.SecurityRules[1].SourceAddressPrefix); Assert.Equal("656", getNsgResponse.SecurityRules[1].SourcePortRange); // List Default Security Groups var listDefaultSecurityGroups = networkManagementClient.DefaultSecurityRules.List(resourceGroupName, networkSecurityGroupName); Assert.NotEmpty(listDefaultSecurityGroups); // Get Defaul Security Group var getDefaultSecurityGroups = networkManagementClient.DefaultSecurityRules.Get(resourceGroupName, networkSecurityGroupName, listDefaultSecurityGroups.First().Name); Assert.Equal(listDefaultSecurityGroups.First().Name, getDefaultSecurityGroups.Name); // Delete NSG networkManagementClient.NetworkSecurityGroups.Delete(resourceGroupName, networkSecurityGroupName); // List NSG listNsgResponse = networkManagementClient.NetworkSecurityGroups.List(resourceGroupName); Assert.Empty(listNsgResponse); } }
public void ApplicationGatewayApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/applicationgateways"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); var vnetName = TestUtilities.GenerateName(); var gwSubnetName = TestUtilities.GenerateName(); var subnet2Name = TestUtilities.GenerateName(); var appGwName = TestUtilities.GenerateName(); var vnet = new VirtualNetwork() { Location = location, AddressSpace = new AddressSpace() { AddressPrefixes = new List <string>() { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = new List <string>() { "10.1.1.1", "10.1.2.4" } }, Subnets = new List <Subnet>() { new Subnet() { Name = gwSubnetName, AddressPrefix = "10.0.0.0/24", }, new Subnet() { Name = subnet2Name, AddressPrefix = "10.0.1.0/24", } } }; var putVnetResponse = networkManagementClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, vnetName, vnet); var getVnetResponse = networkManagementClient.VirtualNetworks.Get(resourceGroupName, vnetName); var getSubnetResponse = networkManagementClient.Subnets.Get(resourceGroupName, vnetName, gwSubnetName); Console.WriteLine("Virtual Network GatewaySubnet Id: {0}", getSubnetResponse.Id); var gwSubnet = getSubnetResponse; var appGw = CreateApplicationGateway(location, gwSubnet, resourceGroupName, appGwName, networkManagementClient.SubscriptionId); // Put AppGw var putAppGwResponse = networkManagementClient.ApplicationGateways.CreateOrUpdate(resourceGroupName, appGwName, appGw); Assert.Equal("Succeeded", putAppGwResponse.ProvisioningState); // Get AppGw var getGateway = networkManagementClient.ApplicationGateways.Get(resourceGroupName, appGwName); Assert.Equal(appGwName, getGateway.Name); CompareApplicationGateway(appGw, getGateway); // Create Nics string nic1name = TestUtilities.GenerateName(); string nic2name = TestUtilities.GenerateName(); var nic1 = TestHelper.CreateNetworkInterface( nic1name, resourceGroupName, null, getVnetResponse.Subnets[1].Id, location, "ipconfig", networkManagementClient); var nic2 = TestHelper.CreateNetworkInterface( nic2name, resourceGroupName, null, getVnetResponse.Subnets[1].Id, location, "ipconfig", networkManagementClient); // Add NIC to application gateway backend address pool. nic1.IpConfigurations[0].ApplicationGatewayBackendAddressPools = new List <ApplicationGatewayBackendAddressPool> { getGateway.BackendAddressPools[1] }; nic2.IpConfigurations[0].ApplicationGatewayBackendAddressPools = new List <ApplicationGatewayBackendAddressPool> { getGateway.BackendAddressPools[1] }; // Put Nics networkManagementClient.NetworkInterfaces.CreateOrUpdate(resourceGroupName, nic1name, nic1); networkManagementClient.NetworkInterfaces.CreateOrUpdate(resourceGroupName, nic2name, nic2); //Start AppGw networkManagementClient.ApplicationGateways.Start(resourceGroupName, appGwName); // Get AppGw and make sure nics are added to backend getGateway = networkManagementClient.ApplicationGateways.Get(resourceGroupName, appGwName); Assert.Equal(2, getGateway.BackendAddressPools[1].BackendIPConfigurations.Count); //Stop AppGw networkManagementClient.ApplicationGateways.Stop(resourceGroupName, appGwName); // Delete AppGw networkManagementClient.ApplicationGateways.Delete(resourceGroupName, appGwName); } }
public void SubnetApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/virtualNetworks"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); string vnetName = TestUtilities.GenerateName(); string subnet1Name = TestUtilities.GenerateName(); string subnet2Name = TestUtilities.GenerateName(); var vnet = new VirtualNetwork() { Location = location, AddressSpace = new AddressSpace() { AddressPrefixes = new List <string>() { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = new List <string>() { "10.1.1.1", "10.1.2.4" } }, Subnets = new List <Subnet>() { new Subnet() { Name = subnet1Name, AddressPrefix = "10.0.0.0/24", } } }; var putVnetResponse = networkManagementClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, vnetName, vnet); // Create a Subnet // Populate paramters for a Subnet var subnet = new Subnet() { Name = subnet2Name, AddressPrefix = "10.0.1.0/24", }; #region Verification var putSubnetResponse = networkManagementClient.Subnets.CreateOrUpdate(resourceGroupName, vnetName, subnet2Name, subnet); var getVnetResponse = networkManagementClient.VirtualNetworks.Get(resourceGroupName, vnetName); Assert.Equal(2, getVnetResponse.Subnets.Count()); var getSubnetResponse = networkManagementClient.Subnets.Get(resourceGroupName, vnetName, subnet2Name); // Verify the getSubnetResponse Assert.True(AreSubnetsEqual(getVnetResponse.Subnets[1], getSubnetResponse)); var getSubnetListResponse = networkManagementClient.Subnets.List(resourceGroupName, vnetName); // Verify ListSubnets Assert.True(AreSubnetsEqual(getVnetResponse.Subnets, getSubnetListResponse)); // Delete the subnet "subnet1" networkManagementClient.Subnets.Delete(resourceGroupName, vnetName, subnet2Name); // Verify that the deletion was successful getSubnetListResponse = networkManagementClient.Subnets.List(resourceGroupName, vnetName); Assert.Equal(1, getSubnetListResponse.Count()); Assert.Equal(subnet1Name, getSubnetListResponse.ElementAt(0).Name); #endregion } }
public void SubnetResourceNavigationLinksTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler3 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var redisClient = RedisCacheManagementTestUtilities.GetRedisManagementClientWithHandler(context, handler3); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/virtualNetworks"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); string vnetName = TestUtilities.GenerateName(); string subnetName = TestUtilities.GenerateName(); string redisName = TestUtilities.GenerateName(); var vnet = new VirtualNetwork() { Location = location, AddressSpace = new AddressSpace() { AddressPrefixes = new List <string>() { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = new List <string>() { "10.1.1.1", "10.1.2.4" } }, Subnets = new List <Subnet>() { new Subnet() { Name = subnetName, AddressPrefix = "10.0.0.0/24", } } }; var putVnetResponse = networkManagementClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, vnetName, vnet); var getSubnetResponse = networkManagementClient.Subnets.Get(resourceGroupName, vnetName, subnetName); Assert.Null(getSubnetResponse.ResourceNavigationLinks); redisClient.Redis.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, redisName, parameters: new RedisCreateOrUpdateParameters { Location = location, Sku = new Sku() { Name = SkuName.Premium, Family = SkuFamily.P, Capacity = 1 }, SubnetId = getSubnetResponse.Id }).Wait(); // wait for maximum 30 minutes for cache to create for (int i = 0; i < 60; i++) { TestUtilities.Wait(new TimeSpan(0, 0, 30)); RedisResource responseGet = redisClient.Redis.Get(resourceGroupName: resourceGroupName, name: redisName); if ("succeeded".Equals(responseGet.ProvisioningState, StringComparison.OrdinalIgnoreCase)) { break; } Assert.False(i == 60, "Cache is not in succeeded state even after 30 min."); } getSubnetResponse = networkManagementClient.Subnets.Get(resourceGroupName, vnetName, subnetName); Assert.Equal(1, getSubnetResponse.ResourceNavigationLinks.Count); } }
public async Task SubnetApiTest() { 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 subnet1Name = Recording.GenerateAssetName("azsmnet"); string subnet2Name = 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 = subnet1Name, AddressPrefix = "10.0.0.0/24", } } }; VirtualNetworksCreateOrUpdateOperation putVnetResponseOperation = await NetworkManagementClient.VirtualNetworks.StartCreateOrUpdateAsync(resourceGroupName, vnetName, vnet); await WaitForCompletionAsync(putVnetResponseOperation); // Create a Subnet // Populate paramters for a Subnet Subnet subnet = new Subnet() { Name = subnet2Name, AddressPrefix = "10.0.1.0/24", }; #region Verification SubnetsCreateOrUpdateOperation putSubnetResponseOperation = await NetworkManagementClient.Subnets.StartCreateOrUpdateAsync(resourceGroupName, vnetName, subnet2Name, subnet); await WaitForCompletionAsync(putSubnetResponseOperation); Response <VirtualNetwork> getVnetResponse = await NetworkManagementClient.VirtualNetworks.GetAsync(resourceGroupName, vnetName); Assert.AreEqual(2, getVnetResponse.Value.Subnets.Count()); Response <Subnet> getSubnetResponse = await NetworkManagementClient.Subnets.GetAsync(resourceGroupName, vnetName, subnet2Name); // Verify the getSubnetResponse Assert.True(AreSubnetsEqual(getVnetResponse.Value.Subnets[1], getSubnetResponse)); AsyncPageable <Subnet> getSubnetListResponseAP = NetworkManagementClient.Subnets.ListAsync(resourceGroupName, vnetName); List <Subnet> getSubnetListResponse = await getSubnetListResponseAP.ToEnumerableAsync(); // Verify ListSubnets Assert.True(AreSubnetsEqual(getVnetResponse.Value.Subnets, getSubnetListResponse)); // Delete the subnet "subnet1" await NetworkManagementClient.Subnets.StartDeleteAsync(resourceGroupName, vnetName, subnet2Name); // Verify that the deletion was successful getSubnetListResponseAP = NetworkManagementClient.Subnets.ListAsync(resourceGroupName, vnetName); getSubnetListResponse = await getSubnetListResponseAP.ToEnumerableAsync(); Has.One.EqualTo(getSubnetListResponse); Assert.AreEqual(subnet1Name, getSubnetListResponse.ElementAt(0).Name); #endregion }
public void PublicIpAddressApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/publicIPAddresses"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); // Create the parameter for PUT PublicIPAddress string publicIpName = TestUtilities.GenerateName(); string domainNameLabel = TestUtilities.GenerateName(); var publicIp = new PublicIPAddress() { Location = location, Tags = new Dictionary <string, string>() { { "key", "value" } }, PublicIPAllocationMethod = IPAllocationMethod.Dynamic, DnsSettings = new PublicIPAddressDnsSettings() { DomainNameLabel = domainNameLabel } }; // Put PublicIPAddress var putPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.CreateOrUpdate(resourceGroupName, publicIpName, publicIp); Assert.Equal("Succeeded", putPublicIpAddressResponse.ProvisioningState); // Get PublicIPAddress var getPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.Get(resourceGroupName, publicIpName); Assert.Equal(4, getPublicIpAddressResponse.IdleTimeoutInMinutes); Assert.NotNull(getPublicIpAddressResponse.ResourceGuid); // Get List of PublicIPAddress var getPublicIpAddressListResponse = networkManagementClient.PublicIPAddresses.List(resourceGroupName); Assert.Single(getPublicIpAddressListResponse); ArePublicIpAddressesEqual(getPublicIpAddressResponse, getPublicIpAddressListResponse.First()); // Get List of PublicIPAddress in a subscription var getPublicIpAddressListSubscriptionResponse = networkManagementClient.PublicIPAddresses.ListAll(); Assert.NotEmpty(getPublicIpAddressListSubscriptionResponse); // Delete PublicIPAddress networkManagementClient.PublicIPAddresses.Delete(resourceGroupName, publicIpName); // Get PublicIPAddress getPublicIpAddressListResponse = networkManagementClient.PublicIPAddresses.List(resourceGroupName); Assert.Empty(getPublicIpAddressListResponse); } }
public void NetworkSecurityGroupApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkSecurityGroups"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); string networkSecurityGroupName = TestUtilities.GenerateName(); var networkSecurityGroup = new NetworkSecurityGroup() { Location = location, }; // Put Nsg var putNsgResponse = networkManagementClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup); Assert.Equal("Succeeded", putNsgResponse.ProvisioningState); // Get NSG var getNsgResponse = networkManagementClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName); Assert.Equal(networkSecurityGroupName, getNsgResponse.Name); Assert.NotNull(getNsgResponse.ResourceGuid); Assert.Equal(6, getNsgResponse.DefaultSecurityRules.Count); Assert.Equal("AllowVnetInBound", getNsgResponse.DefaultSecurityRules[0].Name); Assert.Equal("AllowAzureLoadBalancerInBound", getNsgResponse.DefaultSecurityRules[1].Name); Assert.Equal("DenyAllInBound", getNsgResponse.DefaultSecurityRules[2].Name); Assert.Equal("AllowVnetOutBound", getNsgResponse.DefaultSecurityRules[3].Name); Assert.Equal("AllowInternetOutBound", getNsgResponse.DefaultSecurityRules[4].Name); Assert.Equal("DenyAllOutBound", getNsgResponse.DefaultSecurityRules[5].Name); // Verify a default security rule Assert.Equal(SecurityRuleAccess.Allow, getNsgResponse.DefaultSecurityRules[0].Access); Assert.Equal("Allow inbound traffic from all VMs in VNET", getNsgResponse.DefaultSecurityRules[0].Description); Assert.Equal("VirtualNetwork", getNsgResponse.DefaultSecurityRules[0].DestinationAddressPrefix); Assert.Equal("*", getNsgResponse.DefaultSecurityRules[0].DestinationPortRange); Assert.Equal(SecurityRuleDirection.Inbound, getNsgResponse.DefaultSecurityRules[0].Direction); Assert.Equal(65000, getNsgResponse.DefaultSecurityRules[0].Priority); Assert.Equal(SecurityRuleProtocol.Asterisk, getNsgResponse.DefaultSecurityRules[0].Protocol); Assert.Equal("Succeeded", getNsgResponse.DefaultSecurityRules[0].ProvisioningState); Assert.Equal("VirtualNetwork", getNsgResponse.DefaultSecurityRules[0].SourceAddressPrefix); Assert.Equal("*", getNsgResponse.DefaultSecurityRules[0].SourcePortRange); // List NSG var listNsgResponse = networkManagementClient.NetworkSecurityGroups.List(resourceGroupName); Assert.Single(listNsgResponse); Assert.Equal(networkSecurityGroupName, listNsgResponse.First().Name); Assert.Equal(6, listNsgResponse.First().DefaultSecurityRules.Count); Assert.Equal("AllowVnetInBound", listNsgResponse.First().DefaultSecurityRules[0].Name); Assert.Equal("AllowAzureLoadBalancerInBound", listNsgResponse.First().DefaultSecurityRules[1].Name); Assert.Equal("DenyAllInBound", listNsgResponse.First().DefaultSecurityRules[2].Name); Assert.Equal("AllowVnetOutBound", listNsgResponse.First().DefaultSecurityRules[3].Name); Assert.Equal("AllowInternetOutBound", listNsgResponse.First().DefaultSecurityRules[4].Name); Assert.Equal("DenyAllOutBound", listNsgResponse.First().DefaultSecurityRules[5].Name); Assert.Equal(getNsgResponse.Etag, listNsgResponse.First().Etag); // List NSG in a subscription var listNsgSubsciptionResponse = networkManagementClient.NetworkSecurityGroups.ListAll(); Assert.NotEmpty(listNsgSubsciptionResponse); // Delete NSG networkManagementClient.NetworkSecurityGroups.Delete(resourceGroupName, networkSecurityGroupName); // List NSG listNsgResponse = networkManagementClient.NetworkSecurityGroups.List(resourceGroupName); Assert.Empty(listNsgResponse); } }
public void NetworkInterfaceEnableIPForwardingTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(handler); var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler); var location = NetworkManagementTestUtilities.GetResourceLocation(resourcesClient, "Microsoft.Network/networkInterfaces"); string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); // Create Vnet // Populate parameter for Put Vnet string vnetName = TestUtilities.GenerateName(); string subnetName = TestUtilities.GenerateName(); var vnet = new VirtualNetwork() { Location = location, AddressSpace = new AddressSpace() { AddressPrefixes = new List <string>() { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = new List <string>() { "10.1.1.1", "10.1.2.4" } }, Subnets = new List <Subnet>() { new Subnet() { Name = subnetName, AddressPrefix = "10.0.0.0/24", } } }; var putVnetResponse = networkResourceProviderClient.VirtualNetworks.CreateOrUpdate(resourceGroupName, vnetName, vnet); Assert.Equal(HttpStatusCode.OK, putVnetResponse.StatusCode); var getSubnetResponse = networkResourceProviderClient.Subnets.Get(resourceGroupName, vnetName, subnetName); // Create Nic string nicName = TestUtilities.GenerateName(); string ipConfigName = TestUtilities.GenerateName(); var nicParameters = new NetworkInterface() { Location = location, Name = nicName, Tags = new Dictionary <string, string>() { { "key", "value" } }, IpConfigurations = new List <NetworkInterfaceIpConfiguration>() { new NetworkInterfaceIpConfiguration() { Name = ipConfigName, PrivateIpAllocationMethod = IpAllocationMethod.Dynamic, Subnet = new ResourceId() { Id = getSubnetResponse.Subnet.Id } } }, EnableIPForwarding = false, }; // Test NIC apis var putNicResponse = networkResourceProviderClient.NetworkInterfaces.CreateOrUpdate(resourceGroupName, nicName, nicParameters); Assert.Equal(HttpStatusCode.OK, putNicResponse.StatusCode); var getNicResponse = networkResourceProviderClient.NetworkInterfaces.Get(resourceGroupName, nicName); Assert.Equal(getNicResponse.NetworkInterface.Name, nicName); Assert.Equal(getNicResponse.NetworkInterface.ProvisioningState, Microsoft.Azure.Management.Resources.Models.ProvisioningState.Succeeded); Assert.Null(getNicResponse.NetworkInterface.VirtualMachine); Assert.Null(getNicResponse.NetworkInterface.MacAddress); Assert.Equal(1, getNicResponse.NetworkInterface.IpConfigurations.Count); Assert.Equal(ipConfigName, getNicResponse.NetworkInterface.IpConfigurations[0].Name); Assert.False(getNicResponse.NetworkInterface.EnableIPForwarding); getNicResponse.NetworkInterface.EnableIPForwarding = true; networkResourceProviderClient.NetworkInterfaces.CreateOrUpdate(resourceGroupName, nicName, getNicResponse.NetworkInterface); getNicResponse = networkResourceProviderClient.NetworkInterfaces.Get(resourceGroupName, nicName); Assert.Equal(getNicResponse.NetworkInterface.Name, nicName); Assert.True(getNicResponse.NetworkInterface.EnableIPForwarding); // Delete Nic var deleteNicResponse = networkResourceProviderClient.NetworkInterfaces.Delete(resourceGroupName, nicName); Assert.Equal(HttpStatusCode.OK, deleteNicResponse.StatusCode); var getListNicResponse = networkResourceProviderClient.NetworkInterfaces.List(resourceGroupName); Assert.Equal(0, getListNicResponse.NetworkInterfaces.Count); // Delete VirtualNetwork var deleteVnetResponse = networkResourceProviderClient.VirtualNetworks.Delete(resourceGroupName, vnetName); Assert.Equal(HttpStatusCode.OK, deleteVnetResponse.StatusCode); } }
public async Task SubnetRouteTableTest() { string resourceGroupName = Recording.GenerateAssetName("csmrg"); string location = await NetworkManagementTestUtilities.GetResourceLocation(ResourceManagementClient, "Microsoft.Network/routeTables"); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location)); string routeTableName = Recording.GenerateAssetName("azsmnet"); string route1Name = Recording.GenerateAssetName("azsmnet"); RouteTable routeTable = new RouteTable() { Location = location, }; routeTable.Routes = new List <Route>(); Route route1 = new Route() { AddressPrefix = "192.168.1.0/24", Name = route1Name, NextHopIpAddress = "23.108.1.1", NextHopType = RouteNextHopType.VirtualAppliance }; routeTable.Routes.Add(route1); // Put RouteTable RouteTablesCreateOrUpdateOperation putRouteTableResponseOperation = await NetworkManagementClient.RouteTables.StartCreateOrUpdateAsync(resourceGroupName, routeTableName, routeTable); Response <RouteTable> putRouteTableResponse = await WaitForCompletionAsync(putRouteTableResponseOperation); Assert.AreEqual("Succeeded", putRouteTableResponse.Value.ProvisioningState.ToString()); // Get RouteTable Response <RouteTable> getRouteTableResponse = await NetworkManagementClient.RouteTables.GetAsync(resourceGroupName, routeTableName); // Verify that the subnet reference is null Assert.Null(getRouteTableResponse.Value.Subnets); // Create Vnet with subnet and add a route table string vnetName = Recording.GenerateAssetName("azsmnet"); string subnetName = Recording.GenerateAssetName("azsmnet"); var vnet = new VirtualNetwork() { Location = location, AddressSpace = new AddressSpace() { AddressPrefixes = new List <string>() { "10.0.0.0/16", } }, DhcpOptions = new DhcpOptions() { DnsServers = new List <string>() { "10.1.1.1", "10.1.2.4" } }, Subnets = new List <Subnet>() { new Subnet() { Name = subnetName, AddressPrefix = "10.0.0.0/24", RouteTable = new RouteTable() { Id = getRouteTableResponse.Value.Id, } } } }; 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); Assert.AreEqual(getSubnetResponse.Value.RouteTable.Id, getRouteTableResponse.Value.Id); // Get RouteTable getRouteTableResponse = await NetworkManagementClient.RouteTables.GetAsync(resourceGroupName, routeTableName); Assert.AreEqual(1, getRouteTableResponse.Value.Subnets.Count); Assert.AreEqual(getSubnetResponse.Value.Id, getRouteTableResponse.Value.Subnets[0].Id); }