/// <summary>
 /// Initializes a new instance of the VirtualNetworkGatewayConnection
 /// class.
 /// </summary>
 /// <param name="virtualNetworkGateway1">The reference to virtual
 /// network gateway resource.</param>
 /// <param name="connectionType">Gateway connection type. Possible
 /// values are: 'Ipsec','Vnet2Vnet','ExpressRoute', and 'VPNClient.
 /// Possible values include: 'IPsec', 'Vnet2Vnet', 'ExpressRoute',
 /// 'VPNClient'</param>
 /// <param name="id">Resource ID.</param>
 /// <param name="name">Resource name.</param>
 /// <param name="type">Resource type.</param>
 /// <param name="location">Resource location.</param>
 /// <param name="tags">Resource tags.</param>
 /// <param name="authorizationKey">The authorizationKey.</param>
 /// <param name="virtualNetworkGateway2">The reference to virtual
 /// network gateway resource.</param>
 /// <param name="localNetworkGateway2">The reference to local network
 /// gateway resource.</param>
 /// <param name="connectionProtocol">Connection protocol used for this
 /// connection. Possible values include: 'IKEv2', 'IKEv1'</param>
 /// <param name="routingWeight">The routing weight.</param>
 /// <param name="sharedKey">The IPSec shared key.</param>
 /// <param name="connectionStatus">Virtual network Gateway connection
 /// status. Possible values are 'Unknown', 'Connecting', 'Connected'
 /// and 'NotConnected'. Possible values include: 'Unknown',
 /// 'Connecting', 'Connected', 'NotConnected'</param>
 /// <param name="tunnelConnectionStatus">Collection of all tunnels'
 /// connection health status.</param>
 /// <param name="egressBytesTransferred">The egress bytes transferred
 /// in this connection.</param>
 /// <param name="ingressBytesTransferred">The ingress bytes transferred
 /// in this connection.</param>
 /// <param name="peer">The reference to peerings resource.</param>
 /// <param name="enableBgp">EnableBgp flag</param>
 /// <param name="usePolicyBasedTrafficSelectors">Enable policy-based
 /// traffic selectors.</param>
 /// <param name="ipsecPolicies">The IPSec Policies to be considered by
 /// this connection.</param>
 /// <param name="resourceGuid">The resource GUID property of the
 /// VirtualNetworkGatewayConnection resource.</param>
 /// <param name="provisioningState">The provisioning state of the
 /// VirtualNetworkGatewayConnection resource. Possible values are:
 /// 'Updating', 'Deleting', and 'Failed'.</param>
 /// <param name="expressRouteGatewayBypass">Bypass ExpressRoute Gateway
 /// for data forwarding</param>
 /// <param name="etag">Gets a unique read-only string that changes
 /// whenever the resource is updated.</param>
 public VirtualNetworkGatewayConnection(VirtualNetworkGateway virtualNetworkGateway1, string connectionType, string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), string authorizationKey = default(string), VirtualNetworkGateway virtualNetworkGateway2 = default(VirtualNetworkGateway), LocalNetworkGateway localNetworkGateway2 = default(LocalNetworkGateway), string connectionProtocol = default(string), int?routingWeight = default(int?), string sharedKey = default(string), string connectionStatus = default(string), IList <TunnelConnectionHealth> tunnelConnectionStatus = default(IList <TunnelConnectionHealth>), long?egressBytesTransferred = default(long?), long?ingressBytesTransferred = default(long?), SubResource peer = default(SubResource), bool?enableBgp = default(bool?), bool?usePolicyBasedTrafficSelectors = default(bool?), IList <IpsecPolicy> ipsecPolicies = default(IList <IpsecPolicy>), string resourceGuid = default(string), string provisioningState = default(string), bool?expressRouteGatewayBypass = default(bool?), string etag = default(string))
     : base(id, name, type, location, tags)
 {
     AuthorizationKey       = authorizationKey;
     VirtualNetworkGateway1 = virtualNetworkGateway1;
     VirtualNetworkGateway2 = virtualNetworkGateway2;
     LocalNetworkGateway2   = localNetworkGateway2;
     ConnectionType         = connectionType;
     ConnectionProtocol     = connectionProtocol;
     RoutingWeight          = routingWeight;
     SharedKey               = sharedKey;
     ConnectionStatus        = connectionStatus;
     TunnelConnectionStatus  = tunnelConnectionStatus;
     EgressBytesTransferred  = egressBytesTransferred;
     IngressBytesTransferred = ingressBytesTransferred;
     Peer      = peer;
     EnableBgp = enableBgp;
     UsePolicyBasedTrafficSelectors = usePolicyBasedTrafficSelectors;
     IpsecPolicies             = ipsecPolicies;
     ResourceGuid              = resourceGuid;
     ProvisioningState         = provisioningState;
     ExpressRouteGatewayBypass = expressRouteGatewayBypass;
     Etag = etag;
     CustomInit();
 }
 /// <summary>
 /// The Put LocalNetworkGateway operation creates/updates a local
 /// network gateway in the specified resource group through Network
 /// resource provider.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Network.ILocalNetworkGatewayOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='localNetworkGatewayName'>
 /// Required. The name of the local network gateway.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Create or update Local
 /// Network Gateway operation through Network resource provider.
 /// </param>
 /// <returns>
 /// Response for PutLocalNetworkGateway Api servive call
 /// </returns>
 public static LocalNetworkGatewayPutResponse BeginCreateOrUpdating(this ILocalNetworkGatewayOperations operations, string resourceGroupName, string localNetworkGatewayName, LocalNetworkGateway parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ILocalNetworkGatewayOperations)s).BeginCreateOrUpdatingAsync(resourceGroupName, localNetworkGatewayName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public PSLocalNetworkGateway ToPsLocalNetworkGateway(LocalNetworkGateway localnetGateway)
        {
            var psLocalNetworkGateway = Mapper.Map<PSLocalNetworkGateway>(localnetGateway);

            psLocalNetworkGateway.Tag = TagsConversionHelper.CreateTagHashtable(localnetGateway.Tags);

            return psLocalNetworkGateway;
        }
 /// <summary>
 /// Initializes a new instance of the VirtualNetworkGatewayConnection
 /// class.
 /// </summary>
 public VirtualNetworkGatewayConnection(string etag = default(string), string authorizationKey = default(string), VirtualNetworkGateway virtualNetworkGateway1 = default(VirtualNetworkGateway), VirtualNetworkGateway virtualNetworkGateway2 = default(VirtualNetworkGateway), LocalNetworkGateway localNetworkGateway2 = default(LocalNetworkGateway), string connectionType = default(string), int routingWeight = default(int), string sharedKey = default(string), string connectionStatus = default(string), ulong egressBytesTransferred = default(ulong), ulong ingressBytesTransferred = default(ulong), SubResource peer = default(SubResource), bool enableBgp = default(bool), string resourceGuid = default(string), string provisioningState = default(string))
 {
     Etag                    = etag;
     AuthorizationKey        = authorizationKey;
     VirtualNetworkGateway1  = virtualNetworkGateway1;
     VirtualNetworkGateway2  = virtualNetworkGateway2;
     LocalNetworkGateway2    = localNetworkGateway2;
     ConnectionType          = connectionType;
     RoutingWeight           = routingWeight;
     SharedKey               = sharedKey;
     ConnectionStatus        = connectionStatus;
     EgressBytesTransferred  = egressBytesTransferred;
     IngressBytesTransferred = ingressBytesTransferred;
     Peer                    = peer;
     EnableBgp               = enableBgp;
     ResourceGuid            = resourceGuid;
     ProvisioningState       = provisioningState;
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the VirtualNetworkGatewayConnection
 /// class.
 /// </summary>
 public VirtualNetworkGatewayConnection(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), string authorizationKey = default(string), VirtualNetworkGateway virtualNetworkGateway1 = default(VirtualNetworkGateway), VirtualNetworkGateway virtualNetworkGateway2 = default(VirtualNetworkGateway), LocalNetworkGateway localNetworkGateway2 = default(LocalNetworkGateway), string connectionType = default(string), int?routingWeight = default(int?), string sharedKey = default(string), string connectionStatus = default(string), long?egressBytesTransferred = default(long?), long?ingressBytesTransferred = default(long?), SubResource peer = default(SubResource), bool?enableBgp = default(bool?), string resourceGuid = default(string), string provisioningState = default(string), string etag = default(string))
     : base(id, name, type, location, tags)
 {
     AuthorizationKey       = authorizationKey;
     VirtualNetworkGateway1 = virtualNetworkGateway1;
     VirtualNetworkGateway2 = virtualNetworkGateway2;
     LocalNetworkGateway2   = localNetworkGateway2;
     ConnectionType         = connectionType;
     RoutingWeight          = routingWeight;
     SharedKey               = sharedKey;
     ConnectionStatus        = connectionStatus;
     EgressBytesTransferred  = egressBytesTransferred;
     IngressBytesTransferred = ingressBytesTransferred;
     Peer              = peer;
     EnableBgp         = enableBgp;
     ResourceGuid      = resourceGuid;
     ProvisioningState = provisioningState;
     Etag              = etag;
 }
 /// <summary>
 /// The Put LocalNetworkGateway operation creates/updates a local
 /// network gateway in the specified resource group through Network
 /// resource provider.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Network.ILocalNetworkGatewayOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='localNetworkGatewayName'>
 /// Required. The name of the local network gateway.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Create or update Local
 /// Network Gateway operation through Network resource provider.
 /// </param>
 /// <returns>
 /// Response for PutLocalNetworkGateway Api servive call
 /// </returns>
 public static Task<LocalNetworkGatewayPutResponse> BeginCreateOrUpdatingAsync(this ILocalNetworkGatewayOperations operations, string resourceGroupName, string localNetworkGatewayName, LocalNetworkGateway parameters)
 {
     return operations.BeginCreateOrUpdatingAsync(resourceGroupName, localNetworkGatewayName, parameters, CancellationToken.None);
 }
        public void VirtualNetworkGatewayConnectionSharedKeyOperationsApisTest()
        {
            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/connections");

                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                    new ResourceGroup
                    {
                        Location = location
                    });


                // 1. SetVirtualNetworkGatewayConnectionSharedKey API

                // Pre-requsite:- CreateVirtualNetworkGatewayConnection first

                // Create VirtualNetworkGateway1

                // a. Create PublicIPAddress(Gateway Ip) using Put PublicIpAddress API
                string publicIpName = TestUtilities.GenerateName();
                string domainNameLabel = TestUtilities.GenerateName();

                var nic1publicIp = TestHelper.CreateDefaultPublicIpAddress(publicIpName, resourceGroupName, domainNameLabel, location, networkResourceProviderClient);
                Console.WriteLine("PublicIPAddress(Gateway Ip) :{0}", nic1publicIp.Id);

                // b. Create Virtual Network using Put VirtualNetwork API
                string vnetName = TestUtilities.GenerateName();
                string subnetName = "GatewaySubnet";

                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);

                // c. CreateVirtualNetworkGateway API
                string virtualNetworkGatewayName = TestUtilities.GenerateName();
                string ipConfigName = TestUtilities.GenerateName();

                var virtualNetworkGateway = new VirtualNetworkGateway()
                {
                    Location = location,
                    Name = virtualNetworkGatewayName,
                    Tags = new Dictionary<string, string>()
                        {
                           {"key","value"}
                        },
                    EnableBgp = false,
                    GatewayType = VirtualNetworkGatewayType.Vpn,
                    VpnType = VpnType.RouteBased,
                    IpConfigurations = new List<VirtualNetworkGatewayIpConfiguration>()
                    {
                        new VirtualNetworkGatewayIpConfiguration()
                        {
                             Name = ipConfigName,
                             PrivateIpAllocationMethod = IpAllocationMethod.Dynamic,
                             PublicIpAddress = new ResourceId()
                             {
                                 Id = nic1publicIp.Id
                             },
                             Subnet = new ResourceId()
                             {
                                 Id = getSubnetResponse.Subnet.Id
                             }
                        }
                    }
                };

                var putVirtualNetworkGatewayResponse = networkResourceProviderClient.VirtualNetworkGateways.CreateOrUpdate(resourceGroupName, virtualNetworkGatewayName, virtualNetworkGateway);
                Assert.Equal(HttpStatusCode.OK, putVirtualNetworkGatewayResponse.StatusCode);
                Assert.Equal("Succeeded", putVirtualNetworkGatewayResponse.Status);
                var getVirtualNetworkGatewayResponse = networkResourceProviderClient.VirtualNetworkGateways.Get(resourceGroupName, virtualNetworkGatewayName);

                // Create LocalNetworkGateway2
                string localNetworkGatewayName = TestUtilities.GenerateName();
                string gatewayIp = "192.168.3.4";

                var localNetworkGateway = new LocalNetworkGateway()
                {
                    Location = location,
                    Name = localNetworkGatewayName,
                    Tags = new Dictionary<string, string>()
                        {
                           {"test","value"}
                        },
                    GatewayIpAddress = gatewayIp,
                    LocalNetworkAddressSpace = new AddressSpace()
                    {
                        AddressPrefixes = new List<string>()
                        {
                            "192.168.0.0/16",
                        }
                    }
                };

                var putLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.CreateOrUpdate(resourceGroupName, localNetworkGatewayName, localNetworkGateway);
                Assert.Equal(HttpStatusCode.OK, putLocalNetworkGatewayResponse.StatusCode);
                Assert.Equal("Succeeded", putLocalNetworkGatewayResponse.Status);
                var getLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.Get(resourceGroupName, localNetworkGatewayName);
                getLocalNetworkGatewayResponse.LocalNetworkGateway.Location = location;

                // CreaetVirtualNetworkGatewayConnection API
                string VirtualNetworkGatewayConnectionName = TestUtilities.GenerateName();
                var virtualNetworkGatewayConneciton = new VirtualNetworkGatewayConnection()
                {
                    Location = location,
                    Name = VirtualNetworkGatewayConnectionName,
                    VirtualNetworkGateway1 = getVirtualNetworkGatewayResponse.VirtualNetworkGateway,
                    LocalNetworkGateway2 = getLocalNetworkGatewayResponse.LocalNetworkGateway,
                    ConnectionType = VirtualNetworkGatewayConnectionType.IPsec,
                    RoutingWeight = 3,
                    SharedKey = "abc"
                };
                var putVirtualNetworkGatewayConnectionResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.CreateOrUpdate(resourceGroupName, VirtualNetworkGatewayConnectionName, virtualNetworkGatewayConneciton);
                Assert.Equal(HttpStatusCode.OK, putVirtualNetworkGatewayConnectionResponse.StatusCode);
                Assert.Equal("Succeeded", putVirtualNetworkGatewayConnectionResponse.Status);

                // SetVirtualNetworkGatewayConnectionSharedKey API on created connection above:- virtualNetworkGatewayConneciton
                string connectionSharedKeyName = VirtualNetworkGatewayConnectionName;
                var connectionSharedKey = new ConnectionSharedKey()
                {
                    Value = "TestSharedKeyValue"
                };

                var putConnectionSharedKeyResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.SetSharedKey(resourceGroupName, connectionSharedKeyName, connectionSharedKey);
                Assert.Equal(HttpStatusCode.OK, putConnectionSharedKeyResponse.StatusCode);
                Assert.Equal("Succeeded", putConnectionSharedKeyResponse.Status);

                // 2. GetVirtualNetworkGatewayConnectionSharedKey API
                var getconnectionSharedKeyResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.GetSharedKey(resourceGroupName, connectionSharedKeyName);
                Assert.Equal(HttpStatusCode.OK, getconnectionSharedKeyResponse.StatusCode);
                Console.WriteLine("ConnectionSharedKey details:- Value: {0}", getconnectionSharedKeyResponse.Value);

                // 3A. VirtualNetworkGatewayConnectionResetSharedKey API
                var connectionResetSharedKey = new ConnectionResetSharedKey()
                {
                    KeyLength = 50
                };
                var resetConnectionResetSharedKeyResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.ResetSharedKey(resourceGroupName, connectionSharedKeyName, connectionResetSharedKey);
                Assert.Equal(HttpStatusCode.OK, resetConnectionResetSharedKeyResponse.StatusCode);
                Assert.Equal("Succeeded", resetConnectionResetSharedKeyResponse.Status);

                // 3B. GetVirtualNetworkGatewayConnectionSharedKey API after VirtualNetworkGatewayConnectionResetSharedKey API was called
                getconnectionSharedKeyResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.GetSharedKey(resourceGroupName, connectionSharedKeyName);
                Assert.Equal(HttpStatusCode.OK, getconnectionSharedKeyResponse.StatusCode);
                Console.WriteLine("ConnectionSharedKey details:- Value: {0}", getconnectionSharedKeyResponse.Value);
            }
        }
        public void VirtualNetworkGatewayConnectionOperationsApisTest()
        {
            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/connections");

                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                    new ResourceGroup
                    {
                        Location = location
                    });

                // 1. CreateVirtualNetworkGatewayConnection API

                // A. Prerequisite:- Create VirtualNetworkGateway1
                // a. Create PublicIPAddress(Gateway Ip) using Put PublicIpAddress API
                string publicIpName = TestUtilities.GenerateName();
                string domainNameLabel = TestUtilities.GenerateName();

                var nic1publicIp = TestHelper.CreateDefaultPublicIpAddress(publicIpName, resourceGroupName, domainNameLabel, location, networkResourceProviderClient);
                Console.WriteLine("PublicIPAddress(Gateway Ip) :{0}", nic1publicIp.Id);


                // b. Create Virtual Network using Put VirtualNetwork API
                string vnetName = TestUtilities.GenerateName();
                string subnetName = "GatewaySubnet";

                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);

                //c. CreateVirtualNetworkGateway API
                string virtualNetworkGatewayName = TestUtilities.GenerateName();
                string ipConfigName = TestUtilities.GenerateName();

                var virtualNetworkGateway = new VirtualNetworkGateway()
                {
                    Location = location,
                    Name = virtualNetworkGatewayName,
                    Tags = new Dictionary<string, string>()
                        {
                           {"key","value"}
                        },
                    EnableBgp = false,
                    GatewayType = VirtualNetworkGatewayType.Vpn,
                    VpnType = VpnType.RouteBased,
                    IpConfigurations = new List<VirtualNetworkGatewayIpConfiguration>()
                    {
                        new VirtualNetworkGatewayIpConfiguration()
                        {
                             Name = ipConfigName,
                             PrivateIpAllocationMethod = IpAllocationMethod.Dynamic,
                             PublicIpAddress = new ResourceId()
                             {
                                 Id = nic1publicIp.Id
                             },
                             Subnet = new ResourceId()
                             {
                                 Id = getSubnetResponse.Subnet.Id
                             }
                        }
                    }
                };

                var putVirtualNetworkGatewayResponse = networkResourceProviderClient.VirtualNetworkGateways.CreateOrUpdate(resourceGroupName, virtualNetworkGatewayName, virtualNetworkGateway);
                Assert.Equal(HttpStatusCode.OK, putVirtualNetworkGatewayResponse.StatusCode);
                Assert.Equal("Succeeded", putVirtualNetworkGatewayResponse.Status);
                var getVirtualNetworkGatewayResponse = networkResourceProviderClient.VirtualNetworkGateways.Get(resourceGroupName, virtualNetworkGatewayName);

                //B. Create LocalNetworkGateway2
                string localNetworkGatewayName = TestUtilities.GenerateName();
                string gatewayIp = "192.168.3.4";

                var localNetworkGateway = new LocalNetworkGateway()
                {
                    Location = location,
                    Name = localNetworkGatewayName,
                    Tags = new Dictionary<string, string>()
                        {
                           {"test","value"}
                        },
                    GatewayIpAddress = gatewayIp,
                    LocalNetworkAddressSpace = new AddressSpace()
                    {
                        AddressPrefixes = new List<string>()
                        {
                            "192.168.0.0/16",
                        }
                    }
                };

                var putLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.CreateOrUpdate(resourceGroupName, localNetworkGatewayName, localNetworkGateway);
                Assert.Equal(HttpStatusCode.OK, putLocalNetworkGatewayResponse.StatusCode);
                Assert.Equal("Succeeded", putLocalNetworkGatewayResponse.Status);
                var getLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.Get(resourceGroupName, localNetworkGatewayName);
                getLocalNetworkGatewayResponse.LocalNetworkGateway.Location = location;

                // C. CreaetVirtualNetworkGatewayConnection API
                string VirtualNetworkGatewayConnectionName = TestUtilities.GenerateName();
                var virtualNetworkGatewayConneciton = new VirtualNetworkGatewayConnection()
                {
                    Location = location,
                    Name = VirtualNetworkGatewayConnectionName,
                    VirtualNetworkGateway1 = getVirtualNetworkGatewayResponse.VirtualNetworkGateway,
                    LocalNetworkGateway2 = getLocalNetworkGatewayResponse.LocalNetworkGateway,
                    ConnectionType = VirtualNetworkGatewayConnectionType.IPsec,
                    RoutingWeight = 3,
                    SharedKey = "abc"
                };
                var putVirtualNetworkGatewayConnectionResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.CreateOrUpdate(resourceGroupName, VirtualNetworkGatewayConnectionName, virtualNetworkGatewayConneciton);
                Assert.Equal(HttpStatusCode.OK, putVirtualNetworkGatewayConnectionResponse.StatusCode);
                Assert.Equal("Succeeded", putVirtualNetworkGatewayConnectionResponse.Status);

                // 2. GetVirtualNetworkGatewayConnection API
                var getVirtualNetworkGatewayConnectionResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.Get(resourceGroupName, VirtualNetworkGatewayConnectionName);
                Assert.Equal(HttpStatusCode.OK, getVirtualNetworkGatewayConnectionResponse.StatusCode);
                Console.WriteLine("GatewayConnection details:- GatewayLocation: {0}, GatewayConnectionId:{1}, VirtualNetworkGateway1 name={2} & Id={3}, LocalNetworkGateway2 name={4} & Id={5}, ConnectionType={6} RoutingWeight={7} SharedKey={8}",
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.Location, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.Id,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.Name,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.VirtualNetworkGateway1.Name, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.VirtualNetworkGateway1.Id,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.LocalNetworkGateway2.Name, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.LocalNetworkGateway2.Id,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.ConnectionType, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.RoutingWeight,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.SharedKey);
                Assert.Equal(VirtualNetworkGatewayConnectionType.IPsec, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.ConnectionType);
                Assert.Equal(3, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.RoutingWeight);
                Assert.Equal("abc", getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.SharedKey);

                // 3A. UpdateVirtualNetworkGatewayConnection API :- RoutingWeight = 3 => 4, SharedKey = "abc"=> "xyz"
                virtualNetworkGatewayConneciton.RoutingWeight = 4;
                virtualNetworkGatewayConneciton.SharedKey = "xyz";

                putVirtualNetworkGatewayConnectionResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.CreateOrUpdate(resourceGroupName, VirtualNetworkGatewayConnectionName, virtualNetworkGatewayConneciton);
                Assert.Equal(HttpStatusCode.OK, putVirtualNetworkGatewayConnectionResponse.StatusCode);
                Assert.Equal("Succeeded", putVirtualNetworkGatewayConnectionResponse.Status);

                // 3B. GetVirtualNetworkGatewayConnection API after Updating RoutingWeight = 3 => 4, SharedKey = "abc"=> "xyz"
                getVirtualNetworkGatewayConnectionResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.Get(resourceGroupName, VirtualNetworkGatewayConnectionName);
                Assert.Equal(HttpStatusCode.OK, getVirtualNetworkGatewayConnectionResponse.StatusCode);
                Console.WriteLine("GatewayConnection details:- GatewayLocation: {0}, GatewayConnectionId:{1}, VirtualNetworkGateway1 name={2} & Id={3}, LocalNetworkGateway2 name={4} & Id={5}, ConnectionType={6} RoutingWeight={7} SharedKey={8}",
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.Location, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.Id,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.Name,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.VirtualNetworkGateway1.Name, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.VirtualNetworkGateway1.Id,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.LocalNetworkGateway2.Name, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.LocalNetworkGateway2.Id,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.ConnectionType, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.RoutingWeight,
                    getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.SharedKey);
                Assert.Equal(4, getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.RoutingWeight);
                Assert.Equal("xyz", getVirtualNetworkGatewayConnectionResponse.VirtualNetworkGatewayConnection.SharedKey);

                // 4. ListVitualNetworkGatewayConnections API
                var listVirtualNetworkGatewayConectionResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listVirtualNetworkGatewayConectionResponse.StatusCode);
                Console.WriteLine("ListVirtualNetworkGatewayConnections count ={0} ", listVirtualNetworkGatewayConectionResponse.VirtualNetworkGatewayConnections.Count);
                Assert.Equal(1, listVirtualNetworkGatewayConectionResponse.VirtualNetworkGatewayConnections.Count);

                // 5A. DeleteVirtualNetworkGatewayConnection API
                var deleteVirtualNetworkGatewayConnectionResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.Delete(resourceGroupName, VirtualNetworkGatewayConnectionName);
                Assert.Equal(HttpStatusCode.OK, deleteVirtualNetworkGatewayConnectionResponse.StatusCode);

                // 5B. ListVitualNetworkGatewayConnections API after DeleteVirtualNetworkGatewayConnection API called
                listVirtualNetworkGatewayConectionResponse = networkResourceProviderClient.VirtualNetworkGatewayConnections.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listVirtualNetworkGatewayConectionResponse.StatusCode);
                Console.WriteLine("ListVirtualNetworkGatewayConnections count ={0} ", listVirtualNetworkGatewayConectionResponse.VirtualNetworkGatewayConnections.Count);
                Assert.Equal(0, listVirtualNetworkGatewayConectionResponse.VirtualNetworkGatewayConnections.Count);

            }
        }
        public void LocalNettworkGatewayOperationsApisTest()
        {
            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/localNetworkGateways");

                string resourceGroupName = TestUtilities.GenerateName("csmrg");
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                    new ResourceGroup
                    {
                        Location = location
                    });

                // 1. CreateLocalNetworkGateway API
                string localNetworkGatewayName = TestUtilities.GenerateName();
                string gatewayIp = "192.168.3.4";
                string addressPrefixes = "192.168.0.0/16";
                string newAddressPrefixes = "200.168.0.0/16";

                var localNetworkGateway = new LocalNetworkGateway()
                {
                    Location = location,
                    Name = localNetworkGatewayName,
                    Tags = new Dictionary<string, string>()
                        {
                           {"test","value"}
                        },
                    GatewayIpAddress = gatewayIp,
                    LocalNetworkAddressSpace = new AddressSpace()
                    {
                        AddressPrefixes = new List<string>()
                        {
                            addressPrefixes,
                        }
                    }
                };

                var putLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.CreateOrUpdate(resourceGroupName, localNetworkGatewayName, localNetworkGateway);
                Assert.Equal(HttpStatusCode.OK, putLocalNetworkGatewayResponse.StatusCode);
                Assert.Equal("Succeeded", putLocalNetworkGatewayResponse.Status);

                // 2. GetLocalNetworkGateway API
                var getLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.Get(resourceGroupName, localNetworkGatewayName);
                Assert.Equal(HttpStatusCode.OK, getLocalNetworkGatewayResponse.StatusCode);
                getLocalNetworkGatewayResponse.LocalNetworkGateway.Location = location;
                Console.WriteLine("Local Network Gateway details:- GatewayLocation: {0}, GatewayId:{1}, GatewayName={2} GatewayIpAddress={3} LocalNetworkAddressSpace={4}",
                    getLocalNetworkGatewayResponse.LocalNetworkGateway.Location,
                    getLocalNetworkGatewayResponse.LocalNetworkGateway.Id, getLocalNetworkGatewayResponse.LocalNetworkGateway.Name,
                    getLocalNetworkGatewayResponse.LocalNetworkGateway.GatewayIpAddress, getLocalNetworkGatewayResponse.LocalNetworkGateway.LocalNetworkAddressSpace.AddressPrefixes[0].ToString());
                Assert.Equal(gatewayIp, getLocalNetworkGatewayResponse.LocalNetworkGateway.GatewayIpAddress);
                Assert.Equal(addressPrefixes, getLocalNetworkGatewayResponse.LocalNetworkGateway.LocalNetworkAddressSpace.AddressPrefixes[0].ToString());

                // 3A. UpdateLocalNetworkgateway API :- LocalNetworkGateway LocalNetworkAddressSpace from "192.168.0.0/16" => "200.168.0.0/16"
                getLocalNetworkGatewayResponse.LocalNetworkGateway.LocalNetworkAddressSpace = new AddressSpace()
                {
                    AddressPrefixes = new List<string>()
                        {
                            newAddressPrefixes,
                        }
                };

                putLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.CreateOrUpdate(resourceGroupName, localNetworkGatewayName, getLocalNetworkGatewayResponse.LocalNetworkGateway);
                Assert.Equal(HttpStatusCode.OK, putLocalNetworkGatewayResponse.StatusCode);
                Assert.Equal("Succeeded", putLocalNetworkGatewayResponse.Status);

                // 3B. GetLocalNetworkGateway API after Updating LocalNetworkGateway LocalNetworkAddressSpace from "192.168.0.0/16" => "200.168.0.0/16"
                getLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.Get(resourceGroupName, localNetworkGatewayName);
                Assert.Equal(HttpStatusCode.OK, getLocalNetworkGatewayResponse.StatusCode);
                getLocalNetworkGatewayResponse.LocalNetworkGateway.Location = location;
                Console.WriteLine("Local Network Gateway details:- GatewayLocation: {0}, GatewayId:{1}, GatewayName={2} GatewayIpAddress={3} LocalNetworkAddressSpace={4}",
                    getLocalNetworkGatewayResponse.LocalNetworkGateway.Location, getLocalNetworkGatewayResponse.LocalNetworkGateway.Id,
                    getLocalNetworkGatewayResponse.LocalNetworkGateway.Name, getLocalNetworkGatewayResponse.LocalNetworkGateway.GatewayIpAddress,
                    getLocalNetworkGatewayResponse.LocalNetworkGateway.LocalNetworkAddressSpace.AddressPrefixes[0].ToString());
                Assert.Equal(newAddressPrefixes, getLocalNetworkGatewayResponse.LocalNetworkGateway.LocalNetworkAddressSpace.AddressPrefixes[0].ToString());

                // 4. ListLocalNetworkGateways API
                var listLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewayResponse.StatusCode);
                Console.WriteLine("ListLocalNetworkGateways count ={0} ", listLocalNetworkGatewayResponse.LocalNetworkGateways.Count);
                Assert.Equal(1, listLocalNetworkGatewayResponse.LocalNetworkGateways.Count);

                // 5A. DeleteLocalNetworkGateway API
                var deleteLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.Delete(resourceGroupName, localNetworkGatewayName);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);

                // 5B. ListLocalNetworkGateways API after DeleteLocalNetworkGateway API was called
                listLocalNetworkGatewayResponse = networkResourceProviderClient.LocalNetworkGateways.List(resourceGroupName);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewayResponse.StatusCode);
                Console.WriteLine("ListLocalNetworkGateways count ={0} ", listLocalNetworkGatewayResponse.LocalNetworkGateways.Count);
                Assert.Equal(0, listLocalNetworkGatewayResponse.LocalNetworkGateways.Count);
            }
        }