Example #1
0
        public void VirtualNetworkGatewayConnectionWithBgpTest()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                string virtualNetworkSiteName = "gatewayVirtualNetworkSiteName";
                string vnetGatewayName        = "bgpTestVirtualNetworkGateway";

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.GatewayNetworkConfigurationParameters);

                // Put a virtual network gateway with a feature set that allows BGP (dynamic routing, >= standard)
                GatewayGetOperationStatusResponse response = networkTestClient.Gateways.CreateVirtualNetworkGateway(
                    virtualNetworkSiteName,
                    new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting,
                    GatewaySKU  = GatewaySKU.Standard
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                // Call list, make sure the virtual network gateway exists, then check for BgpSettings
                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                ListVirtualNetworkGatewaysResponse.VirtualNetworkGateway vnetGateway =
                    listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(gw => gw.GatewayName.Equals(vnetGatewayName));
                Assert.NotNull(vnetGateway.BgpSettings);
                string virtualNetworkGatewayId = vnetGateway.GatewayId.ToString();

                // Create a local network gateway with BGP settings
                string localNetworkGatewayName = "bgpTestLocalNetworkGateway";
                var    param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localNetworkGatewayName,
                    IpAddress   = localNetworkGatewayIpAddress,
                    BgpSettings = new BgpSettings()
                    {
                        Asn = 1234,
                        BgpPeeringAddress = "200.168.1.1",
                        PeerWeight        = 5
                    }
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);

                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                ListLocalNetworkGatewaysResponse.LocalNetworkGateway localNetworkGateway =
                    listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(gw => gw.GatewayName.Equals(localNetworkGatewayName));
                string localNetworkGatewayId = localNetworkGateway.Id.ToString();

                // Create a connection from the virtual network gateway to the local network gateway
                // with BGP enabled
                string gatewayConnectionName = "bgpTestConnection";

                GatewayGetOperationStatusResponse gatewayGetOperationStatusResponse =
                    networkTestClient.Gateways.CreateGatewayConnection(
                        new GatewayConnectionCreateParameters()
                {
                    ConnectedEntityId       = localNetworkGatewayId,
                    GatewayConnectionName   = gatewayConnectionName,
                    GatewayConnectionType   = GatewayConnectionType.IPsec,
                    VirtualNetworkGatewayId = vnetGateway.GatewayId,
                    RoutingWeight           = 3,
                    SharedKey = "abc",
                    EnableBgp = true
                }
                        );
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                GatewayConnectionGetResponse gatewayConnectionGetResponse = networkTestClient.Gateways.GetGatewayConnection(virtualNetworkGatewayId, localNetworkGatewayId);
                Assert.True(gatewayConnectionGetResponse.EnableBgp, "Connection should have BGP enabled");

                gatewayGetOperationStatusResponse = networkTestClient.Gateways.DeleteGatewayConnection(virtualNetworkGatewayId, localNetworkGatewayId);
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(virtualNetworkGatewayId);
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);
            }
        }
Example #2
0
        public void VirtualNetworkGatewayConnectionAPIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                // 1.CreateGatewayConnection API :-

                // a.CreateVirtualnetworkGateway API
                string virtualNetworkSiteName = "coexistenceVirtualNetworkSiteName";
                string vnetGatewayName        = "coexistenceVnetGateway";

                networkTestClient.EnsureNoNetworkConfigurationExists(virtualNetworkSiteName);

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.CoexistenceFeatureNetworkConfigurationParameters);
                NetworkListResponse listResponse = networkTestClient.ListNetworkConfigurations();
                Assert.NotNull(listResponse);
                Assert.True(listResponse.VirtualNetworkSites.Any(vnet => vnet.Name.Equals(virtualNetworkSiteName)),
                            "Virtual network:" + virtualNetworkSiteName + " is not found!");
                string vnetId = listResponse.First(vnet => vnet.Name.Equals(virtualNetworkSiteName)).Id;

                GatewayGetOperationStatusResponse response =
                    networkTestClient.Gateways.CreateVirtualNetworkGateway(
                        virtualNetworkSiteName,
                        new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                Guid vnetGatewayId = listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)).GatewayId;

                // b.CreateLocalNetworkGateway API
                string localnetGatewayName = "coexistenceLocalnetGateway";

                var param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localnetGatewayName,
                    IpAddress   = localNetworkGatewayIpAddress,
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.Equal(1, listLocalNetworkGatewaysResponse.LocalNetworkGateways.Count);
                string localNetworkGatewayId = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(localnetGateway =>
                                                                                                           localnetGateway.GatewayName.Equals(localnetGatewayName)).Id.ToString();

                // c.CreateGatewayConnection API
                string gatewayConnectionName = "coexistenceGatewayConnection";

                GatewayGetOperationStatusResponse gatewayGetOperationStatusResponse =
                    networkTestClient.Gateways.CreateGatewayConnection(
                        new GatewayConnectionCreateParameters()
                {
                    ConnectedEntityId       = localNetworkGatewayId,
                    GatewayConnectionName   = gatewayConnectionName,
                    GatewayConnectionType   = GatewayConnectionType.IPsec,
                    VirtualNetworkGatewayId = vnetGatewayId,
                    RoutingWeight           = 3,
                    SharedKey = "abc"
                }
                        );
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                // 2.GetGatewayConnection API
                GatewayConnectionGetResponse gatewayConnectionGetResponse = networkTestClient.Gateways.GetGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayConnectionGetResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayConnectionGetResponse.StatusCode);
                Assert.Equal(vnetGatewayId, gatewayConnectionGetResponse.VirtualNetworkGatewayId);
                Assert.Equal(localNetworkGatewayId, gatewayConnectionGetResponse.ConnectedEntityId);
                Assert.Equal(gatewayConnectionName, gatewayConnectionGetResponse.GatewayConnectionName);
                Assert.Equal(GatewayConnectionType.IPsec, gatewayConnectionGetResponse.GatewayConnectionType);
                Assert.Equal(3, gatewayConnectionGetResponse.RoutingWeight);
                Assert.Equal("abc", gatewayConnectionGetResponse.SharedKey);

                // 3.UpdateGatewayConnection API
                gatewayGetOperationStatusResponse = networkTestClient.Gateways.UpdateGatewayConnection(
                    vnetGatewayId.ToString(), localNetworkGatewayId,
                    new UpdateGatewayConnectionParameters()
                {
                    RoutingWeight = 4,
                    SharedKey     = "xyz"
                });
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                // GetGatewayConnection API after UpdateGatewayConnection API
                gatewayConnectionGetResponse = networkTestClient.Gateways.GetGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayConnectionGetResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayConnectionGetResponse.StatusCode);
                Assert.Equal(4, gatewayConnectionGetResponse.RoutingWeight);
                Assert.Equal("xyz", gatewayConnectionGetResponse.SharedKey);

                // 4.ListGatewayConnections API
                GatewayListGatewayConnectionsResponse gatewayListGatewayConnectionsResponse = networkTestClient.Gateways.ListGatewayConnections();
                Assert.NotNull(gatewayListGatewayConnectionsResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayListGatewayConnectionsResponse.StatusCode);
                Assert.Equal(1, gatewayListGatewayConnectionsResponse.VirtualNetworkGatewayConnections.Count);
                Assert.True(gatewayListGatewayConnectionsResponse.VirtualNetworkGatewayConnections.Any(vnetGatewayConnection =>
                                                                                                       vnetGatewayConnection.GatewayConnectionName.Equals(gatewayConnectionName)), "Gateway connection " + gatewayConnectionName + " not found!");

                // 5.DeleteGatewayConnection API
                gatewayGetOperationStatusResponse = networkTestClient.Gateways.DeleteGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                gatewayListGatewayConnectionsResponse = networkTestClient.Gateways.ListGatewayConnections();
                Assert.False(gatewayListGatewayConnectionsResponse.VirtualNetworkGatewayConnections.Any(vnetGatewayConnection => vnetGatewayConnection.GatewayConnectionName.Equals(gatewayConnectionName)),
                             "Virtual network gateway connection: " + gatewayConnectionName + " is not deleted even after DeleteGatewayConnection API call!");

                // Cleanup test setup at end
                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(vnetGatewayId.ToString());
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);
            }
        }
        public void VirtualNetworkGatewayAPIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                string virtualNetworkSiteName = "coexistenceVirtualNetworkSiteName";
                string vnetGatewayName        = "coexistenceVnetGateway";

                networkTestClient.EnsureNoNetworkConfigurationExists(virtualNetworkSiteName);

                // 1.CreateVirtualnetworkGateway API
                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.CoexistenceFeatureNetworkConfigurationParameters);
                NetworkListResponse listResponse = networkTestClient.ListNetworkConfigurations();
                Assert.NotNull(listResponse);
                Assert.True(listResponse.VirtualNetworkSites.Any(vnet => vnet.Name.Equals(virtualNetworkSiteName)),
                            "Virtual network:" + virtualNetworkSiteName + " is not found!");
                string vnetId = listResponse.First(vnet => vnet.Name.Equals(virtualNetworkSiteName)).Id;

                GatewayGetOperationStatusResponse response =
                    networkTestClient.Gateways.CreateVirtualNetworkGateway(
                        virtualNetworkSiteName,
                        new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                // 2.Listvirtualnetworkgateways API
                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                string vnetGatewayId = listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)).GatewayId.ToString();

                // 3.Getvirtualnetworkgateway API
                VirtualNetworkGatewayGetResponse virtualNetworkGatewayGetResponse = networkTestClient.Gateways.GetVirtualNetworkGateway(vnetGatewayId);
                Assert.NotNull(virtualNetworkGatewayGetResponse);
                Assert.Equal(HttpStatusCode.OK, virtualNetworkGatewayGetResponse.StatusCode);
                Assert.Equal(vnetGatewayName, virtualNetworkGatewayGetResponse.GatewayName);
                Assert.Equal(GatewaySKU.Default, virtualNetworkGatewayGetResponse.GatewaySKU);
                Assert.Equal(GatewayType.DynamicRouting, virtualNetworkGatewayGetResponse.GatewayType);

                // 4.ResizeVirtualnetworkGateway API
                ResizeGatewayParameters parameters = new ResizeGatewayParameters()
                {
                    GatewaySKU = GatewaySKU.HighPerformance
                };
                response = networkTestClient.Gateways.ResizeVirtualNetworkGateway(vnetGatewayId, parameters);
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                virtualNetworkGatewayGetResponse = networkTestClient.Gateways.GetVirtualNetworkGateway(vnetGatewayId);
                Assert.NotNull(virtualNetworkGatewayGetResponse);
                Assert.Equal(HttpStatusCode.OK, virtualNetworkGatewayGetResponse.StatusCode);
                Assert.Equal(vnetGatewayName, virtualNetworkGatewayGetResponse.GatewayName);
                Assert.Equal(GatewaySKU.HighPerformance, virtualNetworkGatewayGetResponse.GatewaySKU);

                // 5.ResetVirtualnetworkGateway API
                ResetGatewayParameters resetGatewayParameters = new ResetGatewayParameters();
                response = networkTestClient.Gateways.ResetVirtualNetworkGateway(vnetGatewayId, resetGatewayParameters);
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                // 6.DeleteVirtualNetworkGateway API
                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(vnetGatewayId);
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.False(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Any(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)),
                             "Virtual network: " + virtualNetworkSiteName + " gateway: " + vnetGatewayName + " is not deleted even after DeleteVirtualNetworkGateway API call!");
            }
        }
        public void DiagnosticsV2APIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                // 1.StartDiagnosticsV2 API
                // a.CreateVirtualnetworkGateway API
                string virtualNetworkSiteName = "coexistenceVirtualNetworkSiteName";
                string vnetGatewayName        = "coexistenceVnetGateway";

                networkTestClient.EnsureNoNetworkConfigurationExists(virtualNetworkSiteName);

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.CoexistenceFeatureNetworkConfigurationParameters);
                NetworkListResponse listResponse = networkTestClient.ListNetworkConfigurations();
                Assert.NotNull(listResponse);
                Assert.True(listResponse.VirtualNetworkSites.Any(vnet => vnet.Name.Equals(virtualNetworkSiteName)),
                            "Virtual network:" + virtualNetworkSiteName + " is not found!");
                string vnetId = listResponse.First(vnet => vnet.Name.Equals(virtualNetworkSiteName)).Id;

                GatewayGetOperationStatusResponse response =
                    networkTestClient.Gateways.CreateVirtualNetworkGateway(
                        virtualNetworkSiteName,
                        new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                // Listvirtualnetworkgateways API
                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                Guid vnetGatewayId = listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)).GatewayId;

                // b.StartDiagnosticsV2 API
                StartGatewayPublicDiagnosticsParameters startParameters = new StartGatewayPublicDiagnosticsParameters()
                {
                    Operation           = UpdateGatewayPublicDiagnosticsOperation.StartDiagnostics,
                    CustomerStorageName = "daschult20140611a",
                    // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")]
                    CustomerStorageKey       = "EyXneSsrZJJbBT4bHL6p4KdO+S5YCtM75PAA1gVWd39vwHm2CHfosBRRDkJYJWpY2mpnYlMROpgqmEci6b3u0w==",
                    ContainerName            = "hydra-test-diagnostics",
                    CaptureDurationInSeconds = "60",
                };

                GatewayGetOperationStatusResponse startResponse = networkTestClient.Gateways.StartDiagnosticsV2(vnetGatewayId.ToString(), startParameters);
                Assert.NotNull(startResponse);
                Assert.Equal(HttpStatusCode.OK, startResponse.HttpStatusCode);

                // 2.GetDiagnosticsV2 API
                GatewayDiagnosticsStatus startStatus = networkTestClient.Gateways.GetDiagnosticsV2(vnetGatewayId.ToString());
                Assert.NotNull(startStatus);
                Assert.Equal(HttpStatusCode.OK, startStatus.StatusCode);
                Assert.True(startStatus.DiagnosticsUrl != null, "The diagnostics url was null.");
                Assert.Equal(GatewayDiagnosticsState.InProgress, startStatus.State);

                // StopDiagnosticsV2 API
                StopGatewayPublicDiagnosticsParameters stopParameters = new StopGatewayPublicDiagnosticsParameters();

                GatewayOperationResponse gatewayOperationResponse = networkTestClient.Gateways.StopDiagnosticsV2(vnetGatewayId.ToString(), stopParameters);
                Assert.NotNull(gatewayOperationResponse);
                Assert.Equal(HttpStatusCode.Accepted, gatewayOperationResponse.StatusCode);

                GatewayDiagnosticsStatus stopStatus;
                do
                {
                    stopStatus = networkTestClient.Gateways.GetDiagnosticsV2(vnetGatewayId.ToString());
                    Assert.NotNull(stopStatus);
                } while (stopStatus.State != GatewayDiagnosticsState.Ready);

                Assert.Equal(GatewayDiagnosticsState.Ready, stopStatus.State);
                Assert.True(stopStatus.DiagnosticsUrl != null, "The diagnostics url was null.");
                Assert.True(1 <= stopStatus.DiagnosticsUrl.Length, "The diagnostics url was empty.");

                // Cleanup test setup at end
                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(vnetGatewayId.ToString());
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);
            }
        }
Example #5
0
        public void SharedKeyV2APIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                // 1.ResetSharedKeyV2 API:-
                // a.CreateVirtualnetworkGateway API
                string virtualNetworkSiteName = "coexistenceVirtualNetworkSiteName";
                string vnetGatewayName        = "coexistenceVnetGateway";

                networkTestClient.EnsureNoNetworkConfigurationExists(virtualNetworkSiteName);

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.CoexistenceFeatureNetworkConfigurationParameters);
                NetworkListResponse listResponse = networkTestClient.ListNetworkConfigurations();
                Assert.NotNull(listResponse);
                Assert.True(listResponse.VirtualNetworkSites.Any(vnet => vnet.Name.Equals(virtualNetworkSiteName)),
                            "Virtual network:" + virtualNetworkSiteName + " is not found!");
                string vnetId = listResponse.First(vnet => vnet.Name.Equals(virtualNetworkSiteName)).Id;

                GatewayGetOperationStatusResponse response =
                    networkTestClient.Gateways.CreateVirtualNetworkGateway(
                        virtualNetworkSiteName,
                        new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                Guid vnetGatewayId = listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)).GatewayId;

                // b.CreateLocalNetworkGateway API
                string localnetGatewayName = "coexistenceLocalnetGateway";
                string addressSpace        = "200.168.0.0/16";

                var param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localnetGatewayName,
                    IpAddress   = "204.95.99.237",
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.Equal(1, listLocalNetworkGatewaysResponse.LocalNetworkGateways.Count);
                string localNetworkGatewayId = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(localnetGateway =>
                                                                                                           localnetGateway.GatewayName.Equals(localnetGatewayName)).Id.ToString();

                // c.CreateGatewayConnection API
                string gatewayConnectionName = "coexistenceGatewayConnection";

                GatewayGetOperationStatusResponse gatewayGetOperationStatusResponse =
                    networkTestClient.Gateways.CreateGatewayConnection(
                        new GatewayConnectionCreateParameters()
                {
                    ConnectedEntityId       = localNetworkGatewayId,
                    GatewayConnectionName   = gatewayConnectionName,
                    GatewayConnectionType   = GatewayConnectionType.IPsec,
                    VirtualNetworkGatewayId = vnetGatewayId,
                    RoutingWeight           = 3,
                    SharedKey = "abc"
                }
                        );
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                // d.ResetSharedKeyV2 API
                GatewayResetSharedKeyParameters resetParameters = new GatewayResetSharedKeyParameters()
                {
                    KeyLength = 128,
                };
                GatewayGetOperationStatusResponse resetResponse = networkTestClient.Gateways.ResetSharedKeyV2(vnetGatewayId.ToString(), localNetworkGatewayId, resetParameters);
                Assert.NotNull(resetResponse);
                Assert.Equal(HttpStatusCode.OK, resetResponse.HttpStatusCode);

                // 2.GetSharedKeyV2 API
                const string sharedKeyToSet = "MNO";
                GatewayGetSharedKeyResponse firstGetResponse = networkTestClient.Gateways.GetSharedKeyV2(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(firstGetResponse);
                Assert.Equal(HttpStatusCode.OK, firstGetResponse.StatusCode);
                Assert.NotEqual(sharedKeyToSet, firstGetResponse.SharedKey);

                // 3. SetSharedKeyV2 API
                GatewaySetSharedKeyParameters setParameters = new GatewaySetSharedKeyParameters()
                {
                    Value = sharedKeyToSet
                };

                GatewayGetOperationStatusResponse setResponse = networkTestClient.Gateways.SetSharedKeyV2(vnetGatewayId.ToString(), localNetworkGatewayId, setParameters);
                Assert.NotNull(setResponse);
                Assert.Equal(HttpStatusCode.OK, setResponse.HttpStatusCode);

                // GetSharedKeyV2 API after SetSharedKeyV2 API
                GatewayGetSharedKeyResponse secondGetResponse = networkTestClient.Gateways.GetSharedKeyV2(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(secondGetResponse);
                Assert.Equal(HttpStatusCode.OK, secondGetResponse.StatusCode);
                Assert.Equal(sharedKeyToSet, secondGetResponse.SharedKey);

                // Cleanup test setup at end
                gatewayGetOperationStatusResponse = networkTestClient.Gateways.DeleteGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(vnetGatewayId.ToString());
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);
            }
        }
        public void IPsecParametersV2APIsTests()
        {
            using (NetworkTestClient networkTestClient = new NetworkTestClient())
            {
                // 1.SetIPsecParametersV2 API:-
                // a.CreateVirtualnetworkGateway API
                string virtualNetworkSiteName = "coexistenceVirtualNetworkSiteName";
                string vnetGatewayName        = "coexistenceVnetGateway";

                networkTestClient.EnsureNoNetworkConfigurationExists(virtualNetworkSiteName);

                networkTestClient.SetNetworkConfiguration(NetworkTestConstants.CoexistenceFeatureNetworkConfigurationParameters);
                NetworkListResponse listResponse = networkTestClient.ListNetworkConfigurations();
                Assert.NotNull(listResponse);
                Assert.True(listResponse.VirtualNetworkSites.Any(vnet => vnet.Name.Equals(virtualNetworkSiteName)),
                            "Virtual network:" + virtualNetworkSiteName + " is not found!");
                string vnetId = listResponse.First(vnet => vnet.Name.Equals(virtualNetworkSiteName)).Id;

                GatewayGetOperationStatusResponse response =
                    networkTestClient.Gateways.CreateVirtualNetworkGateway(
                        virtualNetworkSiteName,
                        new VirtualNetworkGatewayCreateParameters()
                {
                    GatewayName = vnetGatewayName,
                    GatewayType = GatewayType.DynamicRouting
                });
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                ListVirtualNetworkGatewaysResponse listVirtualNetworkGatewaysResponse = networkTestClient.Gateways.ListVirtualNetworkGateways();
                Assert.True(listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.Count >= 1);
                Guid vnetGatewayId = listVirtualNetworkGatewaysResponse.VirtualNetworkGateways.First(vnetGateway => vnetGateway.GatewayName.Equals(vnetGatewayName)).GatewayId;

                // b.CreateLocalNetworkGateway API
                string localnetGatewayName = "coexistenceLocalnetGateway";
                string addressSpace        = "200.168.0.0/16";

                var param = new LocalNetworkGatewayCreateParameters()
                {
                    AddressSpace = new LazyList <string>()
                    {
                        addressSpace
                    },
                    GatewayName = localnetGatewayName,
                    IpAddress   = "204.95.99.237",
                };

                LocalNetworkGatewayCreateResponse localNetworkGatewayCreateResponse = networkTestClient.Gateways.CreateLocalNetworkGateway(param);
                Assert.NotNull(localNetworkGatewayCreateResponse);
                Assert.Equal(HttpStatusCode.OK, localNetworkGatewayCreateResponse.StatusCode);
                Assert.NotNull(localNetworkGatewayCreateResponse.LocalNetworkGatewayId);

                ListLocalNetworkGatewaysResponse listLocalNetworkGatewaysResponse = networkTestClient.Gateways.ListLocalNetworkGateways();
                Assert.NotNull(listLocalNetworkGatewaysResponse);
                Assert.Equal(HttpStatusCode.OK, listLocalNetworkGatewaysResponse.StatusCode);
                Assert.Equal(1, listLocalNetworkGatewaysResponse.LocalNetworkGateways.Count);
                string localNetworkGatewayId = listLocalNetworkGatewaysResponse.LocalNetworkGateways.First(localnetGateway =>
                                                                                                           localnetGateway.GatewayName.Equals(localnetGatewayName)).Id.ToString();

                // c.CreateGatewayConnection API
                string gatewayConnectionName = "coexistenceGatewayConnection";

                GatewayGetOperationStatusResponse gatewayGetOperationStatusResponse =
                    networkTestClient.Gateways.CreateGatewayConnection(
                        new GatewayConnectionCreateParameters()
                {
                    ConnectedEntityId       = localNetworkGatewayId,
                    GatewayConnectionName   = gatewayConnectionName,
                    GatewayConnectionType   = GatewayConnectionType.IPsec,
                    VirtualNetworkGatewayId = vnetGatewayId,
                    RoutingWeight           = 3,
                    SharedKey = "abc"
                }
                        );
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                //d. SetIPsecParametersV2 API
                GatewaySetIPsecParametersParameters setParameters = CreateIPSecParameters();
                response = networkTestClient.Gateways.SetIPsecParametersV2(vnetGatewayId.ToString(), localNetworkGatewayId, setParameters);
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);
                Assert.NotNull(response.Id);

                // 2.GetIPsecParametersV2 API
                GatewayGetIPsecParametersResponse paramResponse = networkTestClient.Gateways.GetIPsecParametersV2(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(paramResponse);
                Assert.Equal(HttpStatusCode.OK, paramResponse.StatusCode);
                Assert.NotNull(paramResponse.IPsecParameters);
                Assert.Equal(EncryptionType.NoEncryption, paramResponse.IPsecParameters.EncryptionType);
                Assert.Equal(PfsGroup.PFS1, paramResponse.IPsecParameters.PfsGroup);
                Assert.Equal(102400000, paramResponse.IPsecParameters.SADataSizeKilobytes); //Check for default value
                Assert.Equal(3600, paramResponse.IPsecParameters.SALifeTimeSeconds);        //Check for default value
                Assert.Equal("SHA1", paramResponse.IPsecParameters.HashAlgorithm);          //Check for default value

                // Cleanup test setup at end
                gatewayGetOperationStatusResponse = networkTestClient.Gateways.DeleteGatewayConnection(vnetGatewayId.ToString(), localNetworkGatewayId);
                Assert.NotNull(gatewayGetOperationStatusResponse);
                Assert.Equal(HttpStatusCode.OK, gatewayGetOperationStatusResponse.HttpStatusCode);

                response = networkTestClient.Gateways.DeleteVirtualNetworkGateway(vnetGatewayId.ToString());
                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode);

                AzureOperationResponse deleteLocalNetworkGatewayResponse = networkTestClient.Gateways.DeleteLocalNetworkGateway(localNetworkGatewayId);
                Assert.NotNull(deleteLocalNetworkGatewayResponse);
                Assert.Equal(HttpStatusCode.OK, deleteLocalNetworkGatewayResponse.StatusCode);
            }
        }