public PSApplicationGateway ToPsApplicationGateway(ApplicationGateway appGw)
        {
            var psAppGw = Mapper.Map<PSApplicationGateway>(appGw);

            psAppGw.Tag = TagsConversionHelper.CreateTagHashtable(appGw.Tags);

            return psAppGw;
        }
 /// <summary>
 /// The Put ApplicationGateway operation creates/updates a
 /// ApplicationGateway
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Network.IApplicationGatewayOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='applicationGatewayName'>
 /// Required. The name of the ApplicationGateway.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the create/delete
 /// ApplicationGateway operation
 /// </param>
 /// <returns>
 /// Response of Put ApplicationGateway operation
 /// </returns>
 public static ApplicationGatewayPutResponse BeginCreateOrUpdating(this IApplicationGatewayOperations operations, string resourceGroupName, string applicationGatewayName, ApplicationGateway parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IApplicationGatewayOperations)s).BeginCreateOrUpdatingAsync(resourceGroupName, applicationGatewayName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 private ApplicationGateway CreateApplicationGateway()
 {
     var appGwName = "azsmnet_appGw";
     var gatewayIpConfigName = "azsmnet_gatewayIpConfigName";
     var frontendIpConfigName = "azsmnet_frontendIpConfigName";
     var frontendPortName = "azsmnet_frontendPortName";
     var backendAddressPoolName = "azsmnet_backendAddressPoolName";
     var backendHttpSettingsName = "azsmnet_backendHttpSettingsName";
     var requestRoutingRuleName = "azsmnet_requestRoutingRuleName";
     var httpListenerName = "azsmnet_httpListenerName";
     
     var appGw = new ApplicationGateway()
     {
         Location = location,
         Name = appGwName,
         Sku = new ApplicationGatewaySku()
             {
                 Name = ApplicationGatewaySkuName.StandardMedium,
                 Tier = ApplicationGatewayTier.Standard,
                 Capacity = 2
             },
         GatewayIpConfigurations = new List<ApplicationGatewayIpConfiguration>()
             {
                 new ApplicationGatewayIpConfiguration()
                 {
                     Name = gatewayIpConfigName,
                     Subnet = new ResourceId()
                     {
                         Id = subnet.Id
                     }
                 }
             },            
         FrontendIpConfigurations = new List<ApplicationGatewayFrontendIpConfiguration>() 
             { 
                 new ApplicationGatewayFrontendIpConfiguration()
                 {
                     Name = frontendIpConfigName,
                     PrivateIpAllocationMethod = IpAllocationMethod.Dynamic,
                     Subnet = new ResourceId()
                     {
                         Id = subnet.Id
                     }                          
                 }                    
             },
         FrontendPorts = new List<ApplicationGatewayFrontendPort>
             {
                 new ApplicationGatewayFrontendPort()
                 {
                     Name = frontendPortName,
                     Port = 80
                 }
             },
         BackendAddressPools = new List<ApplicationGatewayBackendAddressPool>
             {
                 new ApplicationGatewayBackendAddressPool()
                 {
                     Name = backendAddressPoolName,
                     BackendAddresses = new List<ApplicationGatewayBackendAddress>()
                     {
                         new ApplicationGatewayBackendAddress()
                         {
                             IpAddress = "10.2.0.1"
                         },
                         new ApplicationGatewayBackendAddress()
                         {
                             IpAddress = "10.2.0.2"
                         }
                     }
                 }
             },
         BackendHttpSettingsCollection = new List<ApplicationGatewayBackendHttpSettings> 
             {
                 new ApplicationGatewayBackendHttpSettings()
                 {
                     Name = backendHttpSettingsName,
                     Port = 80,
                     Protocol = ApplicationGatewayProtocol.Http,
                     CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Enabled
                 }
             },
         HttpListeners = new List<ApplicationGatewayHttpListener>
             {
                 new ApplicationGatewayHttpListener()
                 {
                     Name = httpListenerName,
                     FrontendPort = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId,
                             resourceGroupName, appGwName, "frontendPorts", frontendPortName)
                     },
                     FrontendIpConfiguration = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId,
                             resourceGroupName, appGwName, "frontendIPConfigurations", frontendIpConfigName)
                     },
                     SslCertificate = null,
                     Protocol = ApplicationGatewayProtocol.Http
                 }
             },
         RequestRoutingRules = new List<ApplicationGatewayRequestRoutingRule>()
             {
                 new ApplicationGatewayRequestRoutingRule()
                 {
                     Name = requestRoutingRuleName,
                     RuleType = ApplicationGatewayRequestRoutingRuleType.Basic,
                     HttpListener = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId,
                             resourceGroupName, appGwName, "httpListeners", httpListenerName)
                     },
                     BackendAddressPool = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId,
                             resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName)
                     },
                     BackendHttpSettings = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(networkResourceProviderClient.Credentials.SubscriptionId,
                             resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettingsName)
                     }
                 }
             }
     };
     return appGw;
 }
        private void CompareApplicationGateway(ApplicationGateway gw1, ApplicationGateway gw2)
        {

            Assert.Equal(gw1.Name, gw2.Name);
            Assert.Equal(gw1.Sku.Name, gw2.Sku.Name);
            Assert.Equal(gw1.Sku.Tier, gw2.Sku.Tier);
            Assert.Equal(gw1.Sku.Capacity, gw2.Sku.Capacity);
            Assert.Equal(gw1.GatewayIpConfigurations.Count, gw2.GatewayIpConfigurations.Count);
            Assert.Equal(gw1.FrontendIpConfigurations.Count, gw2.FrontendIpConfigurations.Count);
            Assert.Equal(gw1.FrontendPorts.Count, gw2.FrontendPorts.Count);
            Assert.Equal(gw1.SslCertificates.Count, gw2.SslCertificates.Count);
            Assert.Equal(gw1.BackendAddressPools.Count, gw2.BackendAddressPools.Count);
            Assert.Equal(gw1.BackendHttpSettingsCollection.Count, gw2.BackendHttpSettingsCollection.Count);
            Assert.Equal(gw1.HttpListeners.Count, gw2.HttpListeners.Count);
            Assert.Equal(gw1.RequestRoutingRules.Count, gw2.RequestRoutingRules.Count);
        }
 private ApplicationGateway CreateApplicationGateway(string location, Subnet subnet, string resourceGroupName, string subscriptionId)
 {
     var appGwName = TestUtilities.GenerateName();
     var gatewayIPConfigName = TestUtilities.GenerateName();
     var frontendIPConfigName = TestUtilities.GenerateName();
     var frontendPortName = TestUtilities.GenerateName();
     var backendAddressPoolName = TestUtilities.GenerateName();
     var backendHttpSettingsName = TestUtilities.GenerateName();
     var requestRoutingRuleName = TestUtilities.GenerateName();
     var httpListenerName = TestUtilities.GenerateName();
     
     var appGw = new ApplicationGateway()
     {
         Location = location,
         Name = appGwName,
         Sku = new ApplicationGatewaySku()
             {
                 Name = ApplicationGatewaySkuName.StandardSmall,
                 Tier = ApplicationGatewayTier.Standard,
                 Capacity = 2
             },
         GatewayIPConfigurations = new List<ApplicationGatewayIPConfiguration>()
             {
                 new ApplicationGatewayIPConfiguration()
                 {
                     Name = gatewayIPConfigName,
                     Subnet = new ResourceId()
                     {
                         Id = subnet.Id
                     }
                 }
             },            
         FrontendIPConfigurations = new List<ApplicationGatewayFrontendIPConfiguration>() 
             { 
                 new ApplicationGatewayFrontendIPConfiguration()
                 {
                     Name = frontendIPConfigName,
                     PrivateIPAllocationMethod = IpAllocationMethod.Dynamic,
                     Subnet = new ResourceId()
                     {
                         Id = subnet.Id
                     }                          
                 }                    
             },
         FrontendPorts = new List<ApplicationGatewayFrontendPort>
             {
                 new ApplicationGatewayFrontendPort()
                 {
                     Name = frontendPortName,
                     Port = 80
                 }
             },
         BackendAddressPools = new List<ApplicationGatewayBackendAddressPool>
             {
                 new ApplicationGatewayBackendAddressPool()
                 {
                     Name = backendAddressPoolName,
                     BackendAddresses = new List<ApplicationGatewayBackendAddress>()
                     {
                         new ApplicationGatewayBackendAddress()
                         {
                             IpAddress = "104.42.6.202"
                         },
                         new ApplicationGatewayBackendAddress()
                         {
                             IpAddress = "23.99.1.115"
                         }
                     }
                 }
             },
         BackendHttpSettingsCollection = new List<ApplicationGatewayBackendHttpSettings> 
             {
                 new ApplicationGatewayBackendHttpSettings()
                 {
                     Name = backendHttpSettingsName,
                     Port = 80,
                     Protocol = ApplicationGatewayProtocol.Http,
                     CookieBasedAffinity = ApplicationGatewayCookieBasedAffinity.Disabled
                 }
             },
         HttpListeners = new List<ApplicationGatewayHttpListener>
             {
                 new ApplicationGatewayHttpListener()
                 {
                     Name = httpListenerName,
                     FrontendPort = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(subscriptionId,
                             resourceGroupName, appGwName, "frontendPorts", frontendPortName)
                     },
                     FrontendIPConfiguration = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(subscriptionId,
                             resourceGroupName, appGwName, "frontendIPConfigurations", frontendIPConfigName)
                     },
                     SslCertificate = null,
                     Protocol = ApplicationGatewayProtocol.Http
                 }
             },
         RequestRoutingRules = new List<ApplicationGatewayRequestRoutingRule>()
             {
                 new ApplicationGatewayRequestRoutingRule()
                 {
                     Name = requestRoutingRuleName,
                     RuleType = ApplicationGatewayRequestRoutingRuleType.Basic,
                     HttpListener = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(subscriptionId,
                             resourceGroupName, appGwName, "httpListeners", httpListenerName)
                     },
                     BackendAddressPool = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(subscriptionId,
                             resourceGroupName, appGwName, "backendAddressPools", backendAddressPoolName)
                     },
                     BackendHttpSettings = new ResourceId()
                     {
                         Id = GetChildAppGwResourceId(subscriptionId,
                             resourceGroupName, appGwName, "backendHttpSettingsCollection", backendHttpSettingsName)
                     }
                 }
             }
     };
     return appGw;
 }
 /// <summary>
 /// The Put ApplicationGateway operation creates/updates a
 /// ApplicationGateway
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Network.IApplicationGatewayOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='applicationGatewayName'>
 /// Required. The name of the ApplicationGateway.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the create/delete
 /// ApplicationGateway operation
 /// </param>
 /// <returns>
 /// Response of Put ApplicationGateway operation
 /// </returns>
 public static Task<ApplicationGatewayPutResponse> BeginCreateOrUpdatingAsync(this IApplicationGatewayOperations operations, string resourceGroupName, string applicationGatewayName, ApplicationGateway parameters)
 {
     return operations.BeginCreateOrUpdatingAsync(resourceGroupName, applicationGatewayName, parameters, CancellationToken.None);
 }