public void AvailableProvidersListAzureLocationCountryStateCitySpecifiedTest() { 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); AvailableProvidersListParameters parameters = new AvailableProvidersListParameters(); parameters.AzureLocations = new List <string>(); parameters.AzureLocations.Add("West US"); parameters.Country = "United States"; parameters.State = "washington"; parameters.City = "seattle"; var providersList = networkManagementClient.NetworkWatchers.ListAvailableProviders("NetworkWatcherRG", "NetworkWatcher", parameters); Assert.Equal("United States", providersList.Countries[0].CountryName); Assert.Equal("washington", providersList.Countries[0].States[0].StateName); Assert.Equal("seattle", providersList.Countries[0].States[0].Cities[0].CityName); } }
public void AzureReachabilityReportStateLevelAggregationTest() { 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); AzureReachabilityReportParameters parameters = new AzureReachabilityReportParameters(); parameters.AzureLocations = new List <string>(); parameters.AzureLocations.Add("West US"); parameters.ProviderLocation = new AzureReachabilityReportLocation(); parameters.ProviderLocation.Country = "United States"; parameters.ProviderLocation.State = "washington"; parameters.StartTime = DateTime.Now.AddDays(-10); parameters.EndTime = DateTime.Now.AddDays(-5); var report = networkManagementClient.NetworkWatchers.GetAzureReachabilityReport("NetworkWatcherRG", "NetworkWatcher", parameters); //Validation Assert.Equal("State", report.AggregationLevel); Assert.Equal("United States", report.ProviderLocation.Country); Assert.Equal("washington", report.ProviderLocation.State); Assert.Equal("West US", report.ReachabilityReport[0].AzureLocation); } }
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 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 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 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 static void CreateVm( ResourceManagementClient resourcesClient, string resourceGroupName, string location, string virtualMachineName, string storageAccountName, string networkInterfaceName, string networkSecurityGroupName, string diagnosticsStorageAccountName, string deploymentName) { string deploymentParams = @"{" + @"'resourceGroupName': {'value': '" + resourceGroupName + "'}," + @"'location': {'value': '" + location + "'}," + @"'virtualMachineName': { 'value': '" + virtualMachineName + "'}," + @"'virtualMachineSize': { 'value': 'Standard_DS1_v2'}," + @"'adminUsername': { 'value': 'netanalytics32'}," + @"'storageAccountName': { 'value': '" + storageAccountName + "'}," + @"'routeTableName': { 'value': '" + resourceGroupName + "RT'}," + @"'virtualNetworkName': { 'value': '" + resourceGroupName + "-vnet'}," + @"'networkInterfaceName': { 'value': '" + networkInterfaceName + "'}," + @"'networkSecurityGroupName': { 'value': '" + networkSecurityGroupName + "'}," + @"'adminPassword': { 'value': '" + NetworkManagementTestUtilities.GetRandomPassword() + "'}," + @"'storageAccountType': { 'value': 'Premium_LRS'}," + @"'diagnosticsStorageAccountName': { 'value': '" + diagnosticsStorageAccountName + "'}," + @"'diagnosticsStorageAccountId': { 'value': 'Microsoft.Storage/storageAccounts/" + diagnosticsStorageAccountName + "'}," + @"'diagnosticsStorageAccountType': { 'value': 'Standard_LRS'}," + @"'addressPrefix': { 'value': '10.17.3.0/24'}," + @"'subnetName': { 'value': 'default'}, 'subnetPrefix': { 'value': '10.17.3.0/24'}," + @"'publicIpAddressName': { 'value': '" + virtualMachineName + "-ip'}," + @"'publicIpAddressType': { 'value': 'Dynamic'}" + @"}"; var deploymentProperties = new DeploymentProperties { Template = JObject.Parse(File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "TestData", "DeploymentTemplate.json"))), Parameters = JObject.Parse(deploymentParams), Mode = DeploymentMode.Incremental }; var deployment = resourcesClient.Deployments.CreateOrUpdate(resourceGroupName, deploymentName, new Deployment(deploymentProperties)); }
public void ExpressRouteMicrosoftPeeringApiTest() { 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 = "westus"; string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = location }); string circuitName = "circuit"; var circuit = TestHelper.CreateDefaultExpressRouteCircuit(resourceGroupName, circuitName, location, networkManagementClient); Assert.Equal(circuit.Name, circuitName); Assert.Equal(circuit.ServiceProviderProperties.BandwidthInMbps, Convert.ToInt32(Circuit_BW)); circuit = TestHelper.UpdateDefaultExpressRouteCircuitWithMicrosoftPeering(resourceGroupName, circuitName, networkManagementClient); Assert.Equal(circuit.Name, circuitName); Assert.Equal(circuit.ServiceProviderProperties.BandwidthInMbps, Convert.ToInt32(Circuit_BW)); Assert.NotNull(circuit.Peerings); resourcesClient.ResourceGroups.Delete(resourceGroupName); } }
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 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 ExpressRouteServiceProviderTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (var context = UndoContext.Current) { context.Start(); var networkResourceProviderClient = NetworkManagementTestUtilities.GetNetworkResourceProviderClient(handler); var listServiceProviders = networkResourceProviderClient.ExpressRouteServiceProviders.List(); // Verify properties Assert.Equal(HttpStatusCode.OK, listServiceProviders.StatusCode); Assert.True(listServiceProviders.ExpressRouteServiceProviders.Any()); Assert.True(listServiceProviders.ExpressRouteServiceProviders[0].PeeringLocations.Any()); Assert.True(listServiceProviders.ExpressRouteServiceProviders[0].BandwidthsOffered.Any()); Assert.NotNull(listServiceProviders.ExpressRouteServiceProviders[0].Name); } }
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 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 void PublicIpAddressApiTestWithIdletTimeoutAndReverseFqdn() { 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 = ResourcesManagementTestUtilities.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(); string reverseFqdn; var publicIp = new PublicIPAddress() { Location = location, Tags = new Dictionary <string, string>() { { "key", "value" } }, PublicIPAllocationMethod = IPAllocationMethod.Dynamic, DnsSettings = new PublicIPAddressDnsSettings() { DomainNameLabel = domainNameLabel, }, IdleTimeoutInMinutes = 16, }; // Put PublicIPAddress var putPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.CreateOrUpdate(resourceGroupName, publicIpName, publicIp); Assert.Equal("Succeeded", putPublicIpAddressResponse.ProvisioningState); // Get PublicIPAddress var getPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.Get(resourceGroupName, publicIpName); // Add Reverse FQDN reverseFqdn = getPublicIpAddressResponse.DnsSettings.Fqdn; getPublicIpAddressResponse.DnsSettings.ReverseFqdn = reverseFqdn; putPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.CreateOrUpdate(resourceGroupName, publicIpName, getPublicIpAddressResponse); Assert.Equal("Succeeded", putPublicIpAddressResponse.ProvisioningState); // Get PublicIPAddress getPublicIpAddressResponse = networkManagementClient.PublicIPAddresses.Get(resourceGroupName, publicIpName); Assert.Equal(16, getPublicIpAddressResponse.IdleTimeoutInMinutes); Assert.Equal(reverseFqdn, getPublicIpAddressResponse.DnsSettings.ReverseFqdn); // 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 ExpressRouteCircuitApiTest() { 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/expressRouteCircuits"); var location = "brazilsouth"; string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = location }); string circuitName = TestUtilities.GenerateName(); var circuit = new ExpressRouteCircuit() { Location = location, Sku = new ExpressRouteCircuitSku() { Name = "Standard_MeteredData", Tier = ExpressRouteCircuitSkuTier.Standard, Family = ExpressRouteCircuitSkuFamily.MeteredData }, BillingType = ExpressRouteCircuitBillingType.ServiceProviderType, ServiceProviderProperties = new ExpressRouteCircuitServiceProviderProperties() { ServiceProviderName = "Equinix", PeeringLocation = "Silicon Valley", BandwidthInMbps = 1000 } }; // Create the circuit var putCircuit = networkResourceProviderClient.ExpressRouteCircuits.CreateOrUpdate(resourceGroupName, circuitName, circuit); Assert.Equal(HttpStatusCode.OK, putCircuit.StatusCode); var getCircuit = networkResourceProviderClient.ExpressRouteCircuits.Get(resourceGroupName, circuitName); // Verify properties Assert.Equal(HttpStatusCode.OK, getCircuit.StatusCode); Assert.NotNull(getCircuit.ExpressRouteCircuit); Assert.NotNull(getCircuit.ExpressRouteCircuit.Sku); Assert.NotNull(getCircuit.ExpressRouteCircuit.Etag); Assert.Equal("Standard_MeteredData", getCircuit.ExpressRouteCircuit.Sku.Name); Assert.Equal(ExpressRouteCircuitSkuTier.Standard, getCircuit.ExpressRouteCircuit.Sku.Tier); Assert.Equal(ExpressRouteCircuitSkuFamily.MeteredData, getCircuit.ExpressRouteCircuit.Sku.Family); //Assert.Equal(ExpressRouteCircuitBillingType.ServiceProviderType, getCircuit.ExpressRouteCircuit.BillingType); Assert.NotNull(getCircuit.ExpressRouteCircuit.ServiceProviderProperties); Assert.Equal("Equinix", getCircuit.ExpressRouteCircuit.ServiceProviderProperties.ServiceProviderName); Assert.Equal("Silicon Valley", getCircuit.ExpressRouteCircuit.ServiceProviderProperties.PeeringLocation); Assert.Equal(1000, getCircuit.ExpressRouteCircuit.ServiceProviderProperties.BandwidthInMbps); // Verify List var listCircuit = networkResourceProviderClient.ExpressRouteCircuits.List(resourceGroupName); Assert.Equal(HttpStatusCode.OK, listCircuit.StatusCode); Assert.NotNull(listCircuit.ExpressRouteCircuits); Assert.Equal(1, listCircuit.ExpressRouteCircuits.Count); Assert.Equal(listCircuit.ExpressRouteCircuits[0].Etag, getCircuit.ExpressRouteCircuit.Etag); Assert.Equal(listCircuit.ExpressRouteCircuits[0].Sku.Name, getCircuit.ExpressRouteCircuit.Sku.Name); Assert.Equal(listCircuit.ExpressRouteCircuits[0].Sku.Tier, getCircuit.ExpressRouteCircuit.Sku.Tier); Assert.Equal(listCircuit.ExpressRouteCircuits[0].Sku.Family, getCircuit.ExpressRouteCircuit.Sku.Family); Assert.NotNull(getCircuit.ExpressRouteCircuit.ServiceProviderProperties); Assert.Equal(listCircuit.ExpressRouteCircuits[0].ServiceProviderProperties.ServiceProviderName, getCircuit.ExpressRouteCircuit.ServiceProviderProperties.ServiceProviderName); Assert.Equal(listCircuit.ExpressRouteCircuits[0].ServiceProviderProperties.PeeringLocation, getCircuit.ExpressRouteCircuit.ServiceProviderProperties.PeeringLocation); Assert.Equal(listCircuit.ExpressRouteCircuits[0].ServiceProviderProperties.BandwidthInMbps, getCircuit.ExpressRouteCircuit.ServiceProviderProperties.BandwidthInMbps); // Verify Delete var deleteCircuit = networkResourceProviderClient.ExpressRouteCircuits.Delete(resourceGroupName, circuitName); Assert.Equal(HttpStatusCode.OK, deleteCircuit.StatusCode); listCircuit = networkResourceProviderClient.ExpressRouteCircuits.List(resourceGroupName); Assert.Equal(0, listCircuit.ExpressRouteCircuits.Count); } }
public void ExpressRouteCircuitWithPeeringApiTest() { 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/expressRouteCircuits"); var location = "brazilsouth"; string resourceGroupName = TestUtilities.GenerateName("csmrg"); resourcesClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = location }); string circuitName = TestUtilities.GenerateName(); var circuit = new ExpressRouteCircuit() { Location = location, Sku = new ExpressRouteCircuitSku() { Name = "Standard_MeteredData", Tier = ExpressRouteCircuitSkuTier.Standard, Family = ExpressRouteCircuitSkuFamily.MeteredData }, BillingType = ExpressRouteCircuitBillingType.ServiceProviderType, ServiceProviderProperties = new ExpressRouteCircuitServiceProviderProperties() { ServiceProviderName = "Equinix", PeeringLocation = "Silicon Valley", BandwidthInMbps = 1000 }, Peerings = new List <ExpressRouteCircuitPeering>() { new ExpressRouteCircuitPeering() { Name = "AzurePrivatePeering", PeeringType = ExpressRouteCircuitPeeringType.AzurePrivatePeering, PeerASN = 100, PrimaryPeerAddressPrefix = "192.168.1.0/30", SecondaryPeerAddressPrefix = "192.168.2.0/30", VlanId = 200 } } }; // Create the circuit var putCircuit = networkResourceProviderClient.ExpressRouteCircuits.CreateOrUpdate(resourceGroupName, circuitName, circuit); Assert.Equal(HttpStatusCode.OK, putCircuit.StatusCode); var getCircuit = networkResourceProviderClient.ExpressRouteCircuits.Get(resourceGroupName, circuitName); // Verify properties Assert.Equal(HttpStatusCode.OK, getCircuit.StatusCode); Assert.NotNull(getCircuit.ExpressRouteCircuit); Assert.NotNull(getCircuit.ExpressRouteCircuit.Sku); Assert.Equal("Standard_MeteredData", getCircuit.ExpressRouteCircuit.Sku.Name); Assert.Equal(ExpressRouteCircuitSkuTier.Standard, getCircuit.ExpressRouteCircuit.Sku.Tier); Assert.Equal(ExpressRouteCircuitSkuFamily.MeteredData, getCircuit.ExpressRouteCircuit.Sku.Family); Assert.NotNull(getCircuit.ExpressRouteCircuit.ServiceProviderProperties); Assert.Equal("Equinix", getCircuit.ExpressRouteCircuit.ServiceProviderProperties.ServiceProviderName); Assert.Equal("Silicon Valley", getCircuit.ExpressRouteCircuit.ServiceProviderProperties.PeeringLocation); Assert.Equal(1000, getCircuit.ExpressRouteCircuit.ServiceProviderProperties.BandwidthInMbps); // Verify peering Assert.NotNull(getCircuit.ExpressRouteCircuit.Peerings); Assert.Equal(1, getCircuit.ExpressRouteCircuit.Peerings.Count); Assert.Equal("AzurePrivatePeering", getCircuit.ExpressRouteCircuit.Peerings[0].Name); Assert.Equal(ExpressRouteCircuitPeeringType.AzurePrivatePeering, getCircuit.ExpressRouteCircuit.Peerings[0].PeeringType); Assert.Equal(100, getCircuit.ExpressRouteCircuit.Peerings[0].PeerASN); Assert.Equal("192.168.1.0/30", getCircuit.ExpressRouteCircuit.Peerings[0].PrimaryPeerAddressPrefix); Assert.Equal("192.168.2.0/30", getCircuit.ExpressRouteCircuit.Peerings[0].SecondaryPeerAddressPrefix); Assert.Equal(200, getCircuit.ExpressRouteCircuit.Peerings[0].VlanId); // Get peering alone var getPeering = networkResourceProviderClient.ExpressRouteCircuitPeerings.Get(resourceGroupName, circuitName, "AzurePrivatePeering"); Assert.Equal(HttpStatusCode.OK, getPeering.StatusCode); Assert.Equal("AzurePrivatePeering", getPeering.Peering.Name); Assert.Equal(ExpressRouteCircuitPeeringType.AzurePrivatePeering, getPeering.Peering.PeeringType); Assert.Equal(100, getPeering.Peering.PeerASN); Assert.Equal("192.168.1.0/30", getPeering.Peering.PrimaryPeerAddressPrefix); Assert.Equal("192.168.2.0/30", getPeering.Peering.SecondaryPeerAddressPrefix); Assert.Equal(200, getPeering.Peering.VlanId); Assert.Null(getPeering.Peering.MicrosoftPeeringConfig); // list all peerings var listPeering = networkResourceProviderClient.ExpressRouteCircuitPeerings.List(resourceGroupName, circuitName); Assert.Equal(HttpStatusCode.OK, listPeering.StatusCode); Assert.Equal(1, listPeering.Peerings.Count); Assert.Equal("AzurePrivatePeering", listPeering.Peerings[0].Name); Assert.Equal(ExpressRouteCircuitPeeringType.AzurePrivatePeering, listPeering.Peerings[0].PeeringType); Assert.Equal(100, listPeering.Peerings[0].PeerASN); Assert.Equal("192.168.1.0/30", listPeering.Peerings[0].PrimaryPeerAddressPrefix); Assert.Equal("192.168.2.0/30", listPeering.Peerings[0].SecondaryPeerAddressPrefix); Assert.Equal(200, listPeering.Peerings[0].VlanId); // Add a new peering var peering = new ExpressRouteCircuitPeering() { PeeringType = ExpressRouteCircuitPeeringType.MicrosoftPeering, PeerASN = 100, PrimaryPeerAddressPrefix = "192.168.1.0/30", SecondaryPeerAddressPrefix = "192.168.2.0/30", VlanId = 200, MicrosoftPeeringConfig = new ExpressRouteCircuitPeeringConfig() { AdvertisedPublicPrefixes = new List <string>() { "11.2.3.4/30", "12.2.3.4/30" }, CustomerASN = 1000, RoutingRegistryName = "AFRINIC" } }; var putPeering = networkResourceProviderClient.ExpressRouteCircuitPeerings.CreateOrUpdate(resourceGroupName, circuitName, "MicrosoftPeering", peering); Assert.Equal(HttpStatusCode.OK, putPeering.StatusCode); getPeering = networkResourceProviderClient.ExpressRouteCircuitPeerings.Get(resourceGroupName, circuitName, "MicrosoftPeering"); Assert.Equal(HttpStatusCode.OK, getPeering.StatusCode); Assert.Equal("MicrosoftPeering", getPeering.Peering.Name); Assert.Equal(ExpressRouteCircuitPeeringType.MicrosoftPeering, getPeering.Peering.PeeringType); Assert.Equal(100, getPeering.Peering.PeerASN); Assert.Equal("192.168.1.0/30", getPeering.Peering.PrimaryPeerAddressPrefix); Assert.Equal("192.168.2.0/30", getPeering.Peering.SecondaryPeerAddressPrefix); Assert.Equal(200, getPeering.Peering.VlanId); Assert.NotNull(getPeering.Peering.MicrosoftPeeringConfig); Assert.Equal(2, getPeering.Peering.MicrosoftPeeringConfig.AdvertisedPublicPrefixes.Count); Assert.NotNull(getPeering.Peering.MicrosoftPeeringConfig.AdvertisedPublicPrefixesState); Assert.Equal(1000, getPeering.Peering.MicrosoftPeeringConfig.CustomerASN); Assert.Equal("AFRINIC", getPeering.Peering.MicrosoftPeeringConfig.RoutingRegistryName); listPeering = networkResourceProviderClient.ExpressRouteCircuitPeerings.List(resourceGroupName, circuitName); Assert.Equal(HttpStatusCode.OK, listPeering.StatusCode); Assert.Equal(2, listPeering.Peerings.Count); // Delete Peering var deletePeering = networkResourceProviderClient.ExpressRouteCircuitPeerings.Delete(resourceGroupName, circuitName, "MicrosoftPeering"); Assert.Equal(HttpStatusCode.OK, deletePeering.StatusCode); listPeering = networkResourceProviderClient.ExpressRouteCircuitPeerings.List(resourceGroupName, circuitName); Assert.Equal(HttpStatusCode.OK, listPeering.StatusCode); Assert.Equal(1, listPeering.Peerings.Count); // Verify Delete circuit var deleteCircuit = networkResourceProviderClient.ExpressRouteCircuits.Delete(resourceGroupName, circuitName); Assert.Equal(HttpStatusCode.OK, deleteCircuit.StatusCode); var listCircuit = networkResourceProviderClient.ExpressRouteCircuits.List(resourceGroupName); Assert.Equal(0, listCircuit.ExpressRouteCircuits.Count); } }
public void FlowLogApiTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler3 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler4 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler5 = 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 computeManagementClient = NetworkManagementTestUtilities.GetComputeManagementClientWithHandler(context, handler3); var storageManagementClient = NetworkManagementTestUtilities.GetStorageManagementClientWithHandler(context, handler4); var operationalInsightsManagementClient = NetworkManagementTestUtilities.GetOperationalInsightsManagementClientWithHandler(context, handler5); string location = "eastus2euap"; string workspaceLocation = "East US"; string resourceGroupName = TestUtilities.GenerateName(); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); //Create network security group string networkSecurityGroupName = TestUtilities.GenerateName(); var networkSecurityGroup = new NetworkSecurityGroup() { Location = location, }; // Put Nsg var putNsgResponse = networkManagementClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, networkSecurityGroup); // Get NSG var getNsgResponse = networkManagementClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName); string networkWatcherName = TestUtilities.GenerateName(); NetworkWatcher properties = new NetworkWatcher(); properties.Location = location; //Create network Watcher var createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName, networkWatcherName, properties); //Create storage string storageName = TestUtilities.GenerateName(); var storageParameters = new StorageAccountCreateParameters() { Location = location, Kind = Kind.Storage, Sku = new Sku { Name = SkuName.StandardLRS } }; var storageAccount = storageManagementClient.StorageAccounts.Create(resourceGroupName, storageName, storageParameters); //create workspace string workspaceName = TestUtilities.GenerateName(); var workSpaceParameters = new Workspace() { Location = workspaceLocation }; var workspace = operationalInsightsManagementClient.Workspaces.CreateOrUpdate(resourceGroupName, workspaceName, workSpaceParameters); FlowLogInformation configParameters = new FlowLogInformation() { TargetResourceId = getNsgResponse.Id, Enabled = true, StorageId = storageAccount.Id, RetentionPolicy = new RetentionPolicyParameters { Days = 5, Enabled = true }, FlowAnalyticsConfiguration = new TrafficAnalyticsProperties() { NetworkWatcherFlowAnalyticsConfiguration = new TrafficAnalyticsConfigurationProperties() { Enabled = true, WorkspaceId = workspace.CustomerId, WorkspaceRegion = workspace.Location, WorkspaceResourceId = workspace.Id } } }; //configure flowlog and TA var configureFlowLog1 = networkManagementClient.NetworkWatchers.SetFlowLogConfiguration(resourceGroupName, networkWatcherName, configParameters); FlowLogStatusParameters flowLogParameters = new FlowLogStatusParameters() { TargetResourceId = getNsgResponse.Id }; var queryFlowLogStatus1 = networkManagementClient.NetworkWatchers.GetFlowLogStatus(resourceGroupName, networkWatcherName, flowLogParameters); //check both flowlog and TA config and enabled status Assert.Equal(queryFlowLogStatus1.TargetResourceId, configParameters.TargetResourceId); Assert.True(queryFlowLogStatus1.Enabled); Assert.Equal(queryFlowLogStatus1.StorageId, configParameters.StorageId); Assert.Equal(queryFlowLogStatus1.RetentionPolicy.Days, configParameters.RetentionPolicy.Days); Assert.Equal(queryFlowLogStatus1.RetentionPolicy.Enabled, configParameters.RetentionPolicy.Enabled); Assert.True(queryFlowLogStatus1.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled); Assert.Equal(queryFlowLogStatus1.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId, configParameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceId); Assert.Equal(queryFlowLogStatus1.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion, configParameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceRegion); Assert.Equal(queryFlowLogStatus1.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId, configParameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.WorkspaceResourceId); //disable TA configParameters.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled = false; var configureFlowLog2 = networkManagementClient.NetworkWatchers.SetFlowLogConfiguration(resourceGroupName, networkWatcherName, configParameters); var queryFlowLogStatus2 = networkManagementClient.NetworkWatchers.GetFlowLogStatus(resourceGroupName, networkWatcherName, flowLogParameters); //check TA disabled and ensure flowlog config is unchanged Assert.Equal(queryFlowLogStatus2.TargetResourceId, configParameters.TargetResourceId); Assert.True(queryFlowLogStatus2.Enabled); Assert.Equal(queryFlowLogStatus2.StorageId, configParameters.StorageId); Assert.Equal(queryFlowLogStatus2.RetentionPolicy.Days, configParameters.RetentionPolicy.Days); Assert.Equal(queryFlowLogStatus2.RetentionPolicy.Enabled, configParameters.RetentionPolicy.Enabled); Assert.False(queryFlowLogStatus2.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled); //disable flowlog (and TA) configParameters.Enabled = false; var configureFlowLog3 = networkManagementClient.NetworkWatchers.SetFlowLogConfiguration(resourceGroupName, networkWatcherName, configParameters); var queryFlowLogStatus3 = networkManagementClient.NetworkWatchers.GetFlowLogStatus(resourceGroupName, networkWatcherName, flowLogParameters); //check both flowlog and TA disabled Assert.False(queryFlowLogStatus3.Enabled); Assert.False(queryFlowLogStatus3.FlowAnalyticsConfiguration.NetworkWatcherFlowAnalyticsConfiguration.Enabled); } }
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 ViewNsgRuleApiTest() { 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())) { var resourcesClient = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1); var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2); var computeManagementClient = NetworkManagementTestUtilities.GetComputeManagementClientWithHandler(context, handler3); string location = "westcentralus"; string resourceGroupName = TestUtilities.GenerateName(); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); string virtualMachineName = TestUtilities.GenerateName(); string networkInterfaceName = TestUtilities.GenerateName(); string networkSecurityGroupName = virtualMachineName + "-nsg"; //Deploy VM with template Deployments.CreateVm( resourcesClient: resourcesClient, resourceGroupName: resourceGroupName, location: location, virtualMachineName: virtualMachineName, storageAccountName: TestUtilities.GenerateName(), networkInterfaceName: networkInterfaceName, networkSecurityGroupName: networkSecurityGroupName, diagnosticsStorageAccountName: TestUtilities.GenerateName(), deploymentName: TestUtilities.GenerateName() ); string networkWatcherName = TestUtilities.GenerateName(); NetworkWatcher properties = new NetworkWatcher(); properties.Location = location; //Create network Watcher var createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName, networkWatcherName, properties); var getVm = computeManagementClient.VirtualMachines.Get(resourceGroupName, virtualMachineName); string localIPAddress = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, networkInterfaceName).IpConfigurations.FirstOrDefault().PrivateIPAddress; string securityRule1 = TestUtilities.GenerateName(); // Add a security rule var SecurityRule = new SecurityRule() { Name = securityRule1, Access = SecurityRuleAccess.Deny, Description = "Test outbound security rule", DestinationAddressPrefix = "*", DestinationPortRange = "80", Direction = SecurityRuleDirection.Outbound, Priority = 501, Protocol = SecurityRuleProtocol.Tcp, SourceAddressPrefix = "*", SourcePortRange = "*", }; var nsg = networkManagementClient.NetworkSecurityGroups.Get(resourceGroupName, networkSecurityGroupName); nsg.SecurityRules.Add(SecurityRule); networkManagementClient.NetworkSecurityGroups.CreateOrUpdate(resourceGroupName, networkSecurityGroupName, nsg); SecurityGroupViewParameters sgvProperties = new SecurityGroupViewParameters() { TargetResourceId = getVm.Id }; //Get view security group rules var viewNSGRules = networkManagementClient.NetworkWatchers.GetVMSecurityRules(resourceGroupName, networkWatcherName, sgvProperties); //Verify effective security rule defined earlier var getEffectiveSecurityRule = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.EffectiveSecurityRules.Where(x => x.Name == "UserRule_" + securityRule1); Assert.Equal("Tcp", getEffectiveSecurityRule.FirstOrDefault().Protocol); Assert.Equal(501, getEffectiveSecurityRule.FirstOrDefault().Priority); Assert.Equal("Deny", getEffectiveSecurityRule.FirstOrDefault().Access); Assert.Equal("Outbound", getEffectiveSecurityRule.FirstOrDefault().Direction); Assert.Equal("0.0.0.0/0", getEffectiveSecurityRule.FirstOrDefault().DestinationAddressPrefix); Assert.Equal("80-80", getEffectiveSecurityRule.FirstOrDefault().DestinationPortRange); Assert.Equal("0.0.0.0/0", getEffectiveSecurityRule.FirstOrDefault().SourceAddressPrefix); Assert.Equal("0-65535", getEffectiveSecurityRule.FirstOrDefault().SourcePortRange); //Verify 6 default rules var getDefaultSecurityRule1 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "AllowVnetInBound"); Assert.Equal("*", getDefaultSecurityRule1.FirstOrDefault().Protocol); Assert.Equal(65000, getDefaultSecurityRule1.FirstOrDefault().Priority); Assert.Equal("Allow", getDefaultSecurityRule1.FirstOrDefault().Access); Assert.Equal("Inbound", getDefaultSecurityRule1.FirstOrDefault().Direction); Assert.Equal("VirtualNetwork", getDefaultSecurityRule1.FirstOrDefault().DestinationAddressPrefix); Assert.Equal("*", getDefaultSecurityRule1.FirstOrDefault().DestinationPortRange); Assert.Equal("VirtualNetwork", getDefaultSecurityRule1.FirstOrDefault().SourceAddressPrefix); Assert.Equal("*", getDefaultSecurityRule1.FirstOrDefault().SourcePortRange); var getDefaultSecurityRule2 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "AllowAzureLoadBalancerInBound"); Assert.Equal("*", getDefaultSecurityRule2.FirstOrDefault().Protocol); Assert.Equal(65001, getDefaultSecurityRule2.FirstOrDefault().Priority); Assert.Equal("Allow", getDefaultSecurityRule2.FirstOrDefault().Access); Assert.Equal("Inbound", getDefaultSecurityRule2.FirstOrDefault().Direction); Assert.Equal("*", getDefaultSecurityRule2.FirstOrDefault().DestinationAddressPrefix); Assert.Equal("*", getDefaultSecurityRule2.FirstOrDefault().DestinationPortRange); Assert.Equal("AzureLoadBalancer", getDefaultSecurityRule2.FirstOrDefault().SourceAddressPrefix); Assert.Equal("*", getDefaultSecurityRule2.FirstOrDefault().SourcePortRange); var getDefaultSecurityRule3 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "DenyAllInBound"); Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().Protocol); Assert.Equal(65500, getDefaultSecurityRule3.FirstOrDefault().Priority); Assert.Equal("Deny", getDefaultSecurityRule3.FirstOrDefault().Access); Assert.Equal("Inbound", getDefaultSecurityRule3.FirstOrDefault().Direction); Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().DestinationAddressPrefix); Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().DestinationPortRange); Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().SourceAddressPrefix); Assert.Equal("*", getDefaultSecurityRule3.FirstOrDefault().SourcePortRange); var getDefaultSecurityRule4 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "AllowVnetOutBound"); Assert.Equal("*", getDefaultSecurityRule4.FirstOrDefault().Protocol); Assert.Equal(65000, getDefaultSecurityRule4.FirstOrDefault().Priority); Assert.Equal("Allow", getDefaultSecurityRule4.FirstOrDefault().Access); Assert.Equal("Outbound", getDefaultSecurityRule4.FirstOrDefault().Direction); Assert.Equal("VirtualNetwork", getDefaultSecurityRule4.FirstOrDefault().DestinationAddressPrefix); Assert.Equal("*", getDefaultSecurityRule4.FirstOrDefault().DestinationPortRange); Assert.Equal("VirtualNetwork", getDefaultSecurityRule4.FirstOrDefault().SourceAddressPrefix); Assert.Equal("*", getDefaultSecurityRule4.FirstOrDefault().SourcePortRange); var getDefaultSecurityRule5 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "AllowInternetOutBound"); Assert.Equal("*", getDefaultSecurityRule5.FirstOrDefault().Protocol); Assert.Equal(65001, getDefaultSecurityRule5.FirstOrDefault().Priority); Assert.Equal("Allow", getDefaultSecurityRule5.FirstOrDefault().Access); Assert.Equal("Outbound", getDefaultSecurityRule5.FirstOrDefault().Direction); Assert.Equal("Internet", getDefaultSecurityRule5.FirstOrDefault().DestinationAddressPrefix); Assert.Equal("*", getDefaultSecurityRule5.FirstOrDefault().DestinationPortRange); Assert.Equal("*", getDefaultSecurityRule5.FirstOrDefault().SourceAddressPrefix); Assert.Equal("*", getDefaultSecurityRule5.FirstOrDefault().SourcePortRange); var getDefaultSecurityRule6 = viewNSGRules.NetworkInterfaces.FirstOrDefault().SecurityRuleAssociations.DefaultSecurityRules.Where(x => x.Name == "DenyAllOutBound"); Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().Protocol); Assert.Equal(65500, getDefaultSecurityRule6.FirstOrDefault().Priority); Assert.Equal("Deny", getDefaultSecurityRule6.FirstOrDefault().Access); Assert.Equal("Outbound", getDefaultSecurityRule6.FirstOrDefault().Direction); Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().DestinationAddressPrefix); Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().DestinationPortRange); Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().SourceAddressPrefix); Assert.Equal("*", getDefaultSecurityRule6.FirstOrDefault().SourcePortRange); } }
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); } }