/// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (PrivateEndpoint != null)
     {
         PrivateEndpoint.Validate();
     }
 }
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (ExtendedLocation != null)
     {
         ExtendedLocation.Validate();
     }
     if (PrivateEndpoint != null)
     {
         PrivateEndpoint.Validate();
     }
     if (IpConfigurations != null)
     {
         foreach (var element in IpConfigurations)
         {
             if (element != null)
             {
                 element.Validate();
             }
         }
     }
     if (TapConfigurations != null)
     {
         foreach (var element1 in TapConfigurations)
         {
             if (element1 != null)
             {
                 element1.Validate();
             }
         }
     }
 }
 /// <summary>
 /// Initializes a new instance of the NetworkInterface class.
 /// </summary>
 /// <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="extendedLocation">The extended location of the network
 /// interface.</param>
 /// <param name="virtualMachine">The reference to a virtual
 /// machine.</param>
 /// <param name="networkSecurityGroup">The reference to the
 /// NetworkSecurityGroup resource.</param>
 /// <param name="privateEndpoint">A reference to the private endpoint
 /// to which the network interface is linked.</param>
 /// <param name="ipConfigurations">A list of IPConfigurations of the
 /// network interface.</param>
 /// <param name="tapConfigurations">A list of TapConfigurations of the
 /// network interface.</param>
 /// <param name="dnsSettings">The DNS settings in network
 /// interface.</param>
 /// <param name="macAddress">The MAC address of the network
 /// interface.</param>
 /// <param name="primary">Whether this is a primary network interface
 /// on a virtual machine.</param>
 /// <param name="vnetEncryptionSupported">Whether the virtual machine
 /// this nic is attached to supports encryption.</param>
 /// <param name="enableAcceleratedNetworking">If the network interface
 /// is accelerated networking enabled.</param>
 /// <param name="enableIPForwarding">Indicates whether IP forwarding is
 /// enabled on this network interface.</param>
 /// <param name="hostedWorkloads">A list of references to linked
 /// BareMetal resources.</param>
 /// <param name="dscpConfiguration">A reference to the dscp
 /// configuration to which the network interface is linked.</param>
 /// <param name="resourceGuid">The resource GUID property of the
 /// network interface resource.</param>
 /// <param name="provisioningState">The provisioning state of the
 /// network interface resource. Possible values include: 'Succeeded',
 /// 'Updating', 'Deleting', 'Failed'</param>
 /// <param name="workloadType">WorkloadType of the NetworkInterface for
 /// BareMetal resources</param>
 /// <param name="nicType">Type of Network Interface resource. Possible
 /// values include: 'Standard', 'Elastic'</param>
 /// <param name="privateLinkService">Privatelinkservice of the network
 /// interface resource.</param>
 /// <param name="migrationPhase">Migration phase of Network Interface
 /// resource. Possible values include: 'None', 'Prepare', 'Commit',
 /// 'Abort', 'Committed'</param>
 /// <param name="etag">A unique read-only string that changes whenever
 /// the resource is updated.</param>
 public NetworkInterface(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), ExtendedLocation extendedLocation = default(ExtendedLocation), SubResource virtualMachine = default(SubResource), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), PrivateEndpoint privateEndpoint = default(PrivateEndpoint), IList <NetworkInterfaceIPConfiguration> ipConfigurations = default(IList <NetworkInterfaceIPConfiguration>), IList <NetworkInterfaceTapConfiguration> tapConfigurations = default(IList <NetworkInterfaceTapConfiguration>), NetworkInterfaceDnsSettings dnsSettings = default(NetworkInterfaceDnsSettings), string macAddress = default(string), bool?primary = default(bool?), bool?vnetEncryptionSupported = default(bool?), bool?enableAcceleratedNetworking = default(bool?), bool?enableIPForwarding = default(bool?), IList <string> hostedWorkloads = default(IList <string>), SubResource dscpConfiguration = default(SubResource), string resourceGuid = default(string), string provisioningState = default(string), string workloadType = default(string), string nicType = default(string), PrivateLinkService privateLinkService = default(PrivateLinkService), string migrationPhase = default(string), string etag = default(string))
     : base(id, name, type, location, tags)
 {
     ExtendedLocation     = extendedLocation;
     VirtualMachine       = virtualMachine;
     NetworkSecurityGroup = networkSecurityGroup;
     PrivateEndpoint      = privateEndpoint;
     IpConfigurations     = ipConfigurations;
     TapConfigurations    = tapConfigurations;
     DnsSettings          = dnsSettings;
     MacAddress           = macAddress;
     Primary = primary;
     VnetEncryptionSupported     = vnetEncryptionSupported;
     EnableAcceleratedNetworking = enableAcceleratedNetworking;
     EnableIPForwarding          = enableIPForwarding;
     HostedWorkloads             = hostedWorkloads;
     DscpConfiguration           = dscpConfiguration;
     ResourceGuid       = resourceGuid;
     ProvisioningState  = provisioningState;
     WorkloadType       = workloadType;
     NicType            = nicType;
     PrivateLinkService = privateLinkService;
     MigrationPhase     = migrationPhase;
     Etag = etag;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the PrivateEndpointConnection class.
 /// </summary>
 /// <param name="id">Resource ID.</param>
 /// <param name="privateEndpoint">The resource of private end
 /// point.</param>
 /// <param name="privateLinkServiceConnectionState">A collection of
 /// information about the state of the connection between service
 /// consumer and provider.</param>
 /// <param name="name">The name of the resource that is unique within a
 /// resource group. This name can be used to access the
 /// resource.</param>
 public PrivateEndpointConnection(string id = default(string), PrivateEndpoint privateEndpoint = default(PrivateEndpoint), PrivateLinkServiceConnectionState privateLinkServiceConnectionState = default(PrivateLinkServiceConnectionState), string name = default(string))
     : base(id)
 {
     PrivateEndpoint = privateEndpoint;
     PrivateLinkServiceConnectionState = privateLinkServiceConnectionState;
     Name = name;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the PrivateEndpointConnection class.
 /// </summary>
 /// <param name="id">Resource ID.</param>
 /// <param name="privateEndpoint">The resource of private end
 /// point.</param>
 /// <param name="privateLinkServiceConnectionState">A collection of
 /// information about the state of the connection between service
 /// consumer and provider.</param>
 /// <param name="provisioningState">The provisioning state of the
 /// private endpoint connection. Possible values include: 'Succeeded',
 /// 'Updating', 'Deleting', 'Failed'</param>
 /// <param name="name">The name of the resource that is unique within a
 /// resource group. This name can be used to access the
 /// resource.</param>
 /// <param name="type">The resource type.</param>
 /// <param name="etag">A unique read-only string that changes whenever
 /// the resource is updated.</param>
 public PrivateEndpointConnection(string id = default(string), PrivateEndpoint privateEndpoint = default(PrivateEndpoint), PrivateLinkServiceConnectionState privateLinkServiceConnectionState = default(PrivateLinkServiceConnectionState), string provisioningState = default(string), string name = default(string), string type = default(string), string etag = default(string))
     : base(id)
 {
     PrivateEndpoint = privateEndpoint;
     PrivateLinkServiceConnectionState = privateLinkServiceConnectionState;
     ProvisioningState = provisioningState;
     Name = name;
     Type = type;
     Etag = etag;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the
 /// ApplicationGatewayPrivateEndpointConnection class.
 /// </summary>
 /// <param name="id">Resource ID.</param>
 /// <param name="privateEndpoint">The resource of private end
 /// point.</param>
 /// <param name="privateLinkServiceConnectionState">A collection of
 /// information about the state of the connection between service
 /// consumer and provider.</param>
 /// <param name="provisioningState">The provisioning state of the
 /// application gateway private endpoint connection resource. Possible
 /// values include: 'Succeeded', 'Updating', 'Deleting',
 /// 'Failed'</param>
 /// <param name="linkIdentifier">The consumer link id.</param>
 /// <param name="name">Name of the private endpoint connection on an
 /// application gateway.</param>
 /// <param name="etag">A unique read-only string that changes whenever
 /// the resource is updated.</param>
 /// <param name="type">Type of the resource.</param>
 public ApplicationGatewayPrivateEndpointConnection(string id = default(string), PrivateEndpoint privateEndpoint = default(PrivateEndpoint), PrivateLinkServiceConnectionState privateLinkServiceConnectionState = default(PrivateLinkServiceConnectionState), string provisioningState = default(string), string linkIdentifier = default(string), string name = default(string), string etag = default(string), string type = default(string))
     : base(id)
 {
     PrivateEndpoint = privateEndpoint;
     PrivateLinkServiceConnectionState = privateLinkServiceConnectionState;
     ProvisioningState = provisioningState;
     LinkIdentifier    = linkIdentifier;
     Name = name;
     Etag = etag;
     Type = type;
     CustomInit();
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the NetworkInterface class.
 /// </summary>
 /// <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="virtualMachine">The reference of a virtual
 /// machine.</param>
 /// <param name="networkSecurityGroup">The reference of the
 /// NetworkSecurityGroup resource.</param>
 /// <param name="privateEndpoint">A reference to the private endpoint
 /// to which the network interface is linked.</param>
 /// <param name="ipConfigurations">A list of IPConfigurations of the
 /// network interface.</param>
 /// <param name="tapConfigurations">A list of TapConfigurations of the
 /// network interface.</param>
 /// <param name="dnsSettings">The DNS settings in network
 /// interface.</param>
 /// <param name="macAddress">The MAC address of the network
 /// interface.</param>
 /// <param name="primary">Whether this is a primary network interface
 /// on a virtual machine.</param>
 /// <param name="enableAcceleratedNetworking">If the network interface
 /// is accelerated networking enabled.</param>
 /// <param name="enableIPForwarding">Indicates whether IP forwarding is
 /// enabled on this network interface.</param>
 /// <param name="hostedWorkloads">A list of references to linked
 /// BareMetal resources.</param>
 /// <param name="resourceGuid">The resource GUID property of the
 /// network interface resource.</param>
 /// <param name="provisioningState">The provisioning state of the
 /// network interface resource. Possible values include: 'Succeeded',
 /// 'Updating', 'Deleting', 'Failed'</param>
 /// <param name="etag">A unique read-only string that changes whenever
 /// the resource is updated.</param>
 public NetworkInterface(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), SubResource virtualMachine = default(SubResource), NetworkSecurityGroup networkSecurityGroup = default(NetworkSecurityGroup), PrivateEndpoint privateEndpoint = default(PrivateEndpoint), IList <NetworkInterfaceIPConfiguration> ipConfigurations = default(IList <NetworkInterfaceIPConfiguration>), IList <NetworkInterfaceTapConfiguration> tapConfigurations = default(IList <NetworkInterfaceTapConfiguration>), NetworkInterfaceDnsSettings dnsSettings = default(NetworkInterfaceDnsSettings), string macAddress = default(string), bool?primary = default(bool?), bool?enableAcceleratedNetworking = default(bool?), bool?enableIPForwarding = default(bool?), IList <string> hostedWorkloads = default(IList <string>), string resourceGuid = default(string), string provisioningState = default(string), string etag = default(string))
     : base(id, name, type, location, tags)
 {
     VirtualMachine       = virtualMachine;
     NetworkSecurityGroup = networkSecurityGroup;
     PrivateEndpoint      = privateEndpoint;
     IpConfigurations     = ipConfigurations;
     TapConfigurations    = tapConfigurations;
     DnsSettings          = dnsSettings;
     MacAddress           = macAddress;
     Primary = primary;
     EnableAcceleratedNetworking = enableAcceleratedNetworking;
     EnableIPForwarding          = enableIPForwarding;
     HostedWorkloads             = hostedWorkloads;
     ResourceGuid      = resourceGuid;
     ProvisioningState = provisioningState;
     Etag = etag;
     CustomInit();
 }
Example #8
0
        public void TestPrivateEndpointConnection()
        {
            TestInitialize();

            string clusterName  = TestUtilities.GenerateName("hdisdk-pe");
            var    createParams = CommonData.PrepareClusterCreateParamsForWasb();

            createParams.Location = "South Central US";

            var networkProperties = new NetworkProperties(ResourceProviderConnection.Outbound, PrivateLink.Enabled);

            createParams.Properties.NetworkProperties = networkProperties;

            string storageAccountResourceId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Storage/storageAccounts/{2}", CommonData.SubscriptionId, CommonData.ResourceGroupName, CommonData.StorageAccountName);

            createParams.Properties.StorageProfile.Storageaccounts[0].ResourceId = storageAccountResourceId;

            string vnetId   = "/subscriptions/964c10bb-8a6c-43bc-83d3-6b318c6c7305/resourceGroups/rg/providers/Microsoft.Network/virtualNetworks/fakevnet";
            string subnetId = "/subscriptions/964c10bb-8a6c-43bc-83d3-6b318c6c7305/resourceGroups/rg/providers/Microsoft.Network/virtualNetworks/fakevnet/subnets/default";

            foreach (var role in createParams.Properties.ComputeProfile.Roles)
            {
                role.VirtualNetworkProfile = new VirtualNetworkProfile(vnetId, subnetId);
            }

            var cluster = HDInsightClient.Clusters.Create(CommonData.ResourceGroupName, clusterName, createParams);

            var privateLinkResourceListResult = HDInsightClient.PrivateLinkResources.ListByCluster(CommonData.ResourceGroupName, clusterName);

            Assert.NotNull(privateLinkResourceListResult);

            var headNodePrivateLinkResource = privateLinkResourceListResult.Value.Where(pls => pls.Name.Equals("headnode")).FirstOrDefault();

            // call Network sdk to create private endpoint and choose the approve manually way.
            // please notice that the
            NetworkPrivateEndpoint privateEndpointParameter = new NetworkPrivateEndpoint()
            {
                Location = cluster.Location,
                ManualPrivateLinkServiceConnections = new List <NetworkPrivateLinkServiceConnection>
                {
                    new NetworkPrivateLinkServiceConnection()
                    {
                        Name = cluster.Name,               // Private link service name is the cluster name
                        PrivateLinkServiceId = cluster.Id, // Private link service id is the cluster resource id
                        GroupIds             = new List <string> {
                            headNodePrivateLinkResource.GroupId,
                        },
                        RequestMessage = "Want to connect to head node private link resource."
                    },
                },
                Subnet = new Subnet(id: subnetId)
            };
            string privateEndpointName         = "headnodepe";
            var    createPrivateEndpointResult = HDInsightManagementHelper.CreatePrivateEndpoint(CommonData.ResourceGroupName, privateEndpointName, privateEndpointParameter);

            // Get the private endpoint connection and check the status


            var privateEndpointConnectionListResult = HDInsightClient.PrivateEndpointConnections.ListByCluster(CommonData.ResourceGroupName, clusterName);

            Assert.NotNull(privateEndpointConnectionListResult);

            foreach (var privateEndpointConnection in privateEndpointConnectionListResult)
            {
                Assert.Equal(PrivateLinkServiceConnectionStatus.Pending, privateEndpointConnection.PrivateLinkServiceConnectionState.Status);

                //Approve
                privateEndpointConnection.PrivateLinkServiceConnectionState.Status = PrivateLinkServiceConnectionStatus.Approved;
                HDInsightClient.PrivateEndpointConnections.CreateOrUpdate(CommonData.ResourceGroupName, clusterName, privateEndpointConnection.Name, privateEndpointConnection);

                //Delete
                HDInsightClient.PrivateEndpointConnections.Delete(CommonData.ResourceGroupName, clusterName, privateEndpointConnection.Name);
            }
        }
        public async void SetupPrivateEndpointAutoApprovalTests()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                //prepare test base
                var testBase = new ApiManagementTestBase(context);
                // test is done in prod preview environment
                string serviceRegion = "West US 2";
                testBase.location = serviceRegion;
                testBase.serviceProperties.Location = serviceRegion;
                testBase.serviceProperties.Sku      = new ApiManagementServiceSkuProperties(SkuType.Developer, capacity: 1);

                // prepare private endpoint names and ids
                var virtualNetworkName            = TestUtilities.GenerateName("apimvnet");
                var subnetName                    = TestUtilities.GenerateName("apimsubnet");
                var subnetId                      = CreateDefaultVNetWithSubnet(virtualNetworkName, subnetName, testBase);
                var privateEndpointName           = TestUtilities.GenerateName("apimprivateendpoint");
                var privateEndpointConnectionName = TestUtilities.GenerateName("apimprivateendpointconnection");

                var apimPrivateEndpointTypeId       = String.Format(apimPrivateEndpointTypeIdTemplate, testBase.subscriptionId, testBase.rgName);
                var apimPrivateLinkResourceId       = String.Format(apimPrivateLinkResourceIdTemplate, testBase.subscriptionId, testBase.rgName, testBase.serviceName);
                var apimServiceId                   = String.Format(apimServiceIdTemplate, testBase.subscriptionId, testBase.rgName, testBase.serviceName);
                var apimPrivateEndpointId           = String.Format(privateEndpointIdTemplate, testBase.subscriptionId, testBase.rgName, privateEndpointName);
                var apimPrivateEndpointConnectionId = String.Format(apimPrivateEndpointConnectionIdTemplate, testBase.subscriptionId, testBase.rgName, testBase.serviceName, privateEndpointConnectionName);

                //create new service
                var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName,
                    parameters: testBase.serviceProperties);
                // service must be non-consumption and non-vnet to enable private link
                ValidateService(createdService,
                                testBase.serviceName,
                                testBase.rgName,
                                testBase.subscriptionId,
                                testBase.location,
                                testBase.serviceProperties.PublisherEmail,
                                testBase.serviceProperties.PublisherName,
                                testBase.serviceProperties.Sku.Name,
                                testBase.tags,
                                PlatformVersion.Stv2);
                Assert.Equal(VirtualNetworkType.None, createdService.VirtualNetworkType);

                // verify the response of get available private endpoint types in subscription
                bool privateEndpointTypeFound           = false;
                var  pagedAvailablePrivateEndpointTypes = await testBase.networkClient.AvailablePrivateEndpointTypes.ListByResourceGroupAsync(testBase.location, testBase.rgName);

                while (pagedAvailablePrivateEndpointTypes != null && pagedAvailablePrivateEndpointTypes.Count() > 0)
                {
                    Console.WriteLine(pagedAvailablePrivateEndpointTypes);
                    if (pagedAvailablePrivateEndpointTypes.Any(peType =>
                                                               peType.Name == "Microsoft.ApiManagement.service" &&
                                                               peType.Type == "Microsoft.Network/AvailablePrivateEndpointTypes" &&
                                                               peType.ResourceName == "Microsoft.ApiManagement/service" &&
                                                               peType.Id == apimPrivateEndpointTypeId))
                    {
                        privateEndpointTypeFound = true;
                        break;
                    }
                    if (pagedAvailablePrivateEndpointTypes.NextPageLink != null && pagedAvailablePrivateEndpointTypes.NextPageLink != String.Empty)
                    {
                        pagedAvailablePrivateEndpointTypes = await testBase.networkClient.AvailablePrivateEndpointTypes.ListByResourceGroupNextAsync(pagedAvailablePrivateEndpointTypes.NextPageLink);
                    }
                    else
                    {
                        break;
                    }
                }
                Assert.True(privateEndpointTypeFound);

                // verify the response of get available private Link resources in subscription
                var listAvailablePrivateLinkResourceResponse = await testBase.client.PrivateEndpointConnection.ListPrivateLinkResourcesAsync(testBase.rgName, testBase.serviceName);

                Assert.Contains(listAvailablePrivateLinkResourceResponse.Value,
                                plResource =>
                                plResource.Name == privateLinkResourceName &&
                                plResource.Type == "Microsoft.ApiManagement/service/privateLinkResources" &&
                                plResource.Id == apimPrivateLinkResourceId &&
                                plResource.GroupId == privateLinkResourceName &&
                                plResource.RequiredMembers.Count == 1 &&
                                plResource.RequiredMembers.Contains(privateLinkResourceName) &&
                                plResource.RequiredZoneNames.Count == 1 &&
                                plResource.RequiredZoneNames.Contains("privateLink.azure-api.net"));

                // prepare vnet for private endpoint creation
                var plServiceConnection = new NRPPrivateLinkServiceConnection(
                    null,
                    null,
                    apimServiceId,
                    new List <string> {
                    privateLinkResourceName
                },
                    privateEndpointRequestDescription,
                    null,
                    privateEndpointConnectionName);
                var subnet          = new Subnet(subnetId);
                var privateEndpoint = new NRPPrivateEndpoint(
                    null,
                    null,
                    null,
                    testBase.location,
                    null,
                    null,
                    subnet,
                    null,
                    null,
                    new List <NRPPrivateLinkServiceConnection> {
                    plServiceConnection
                });

                // create private endpoint with auto-approval flow
                var createdPrivateEndpoint = await testBase.networkClient.PrivateEndpoints.CreateOrUpdateAsync(testBase.rgName, privateEndpointName, privateEndpoint);

                // verify that the private endpoint connection is created correctly
                Assert.Equal(1, createdPrivateEndpoint.PrivateLinkServiceConnections.Count);
                Assert.Contains(createdPrivateEndpoint.PrivateLinkServiceConnections,
                                connection =>
                                connection.PrivateLinkServiceId == plServiceConnection.PrivateLinkServiceId &&
                                connection.GroupIds.Count == 1 &&
                                connection.PrivateLinkServiceConnectionState.Status == "Approved" &&
                                connection.PrivateLinkServiceConnectionState.Description == privateEndpointRequestDescription &&
                                connection.Name == plServiceConnection.Name &&
                                connection.GroupIds.Contains(privateLinkResourceName));
                Assert.Equal(privateEndpointName, createdPrivateEndpoint.Name);
                Assert.Equal(subnetId, createdPrivateEndpoint.Subnet.Id);
                Assert.Equal("Succeeded", createdPrivateEndpoint.ProvisioningState);

                // verify that the private endpoint connection returned from NRP List is correct
                var nrpListPrivateEndpointsResponse = await testBase.networkClient.PrivateEndpoints.ListAsync(testBase.rgName);

                Assert.Contains(nrpListPrivateEndpointsResponse,
                                pe =>
                                pe.Name == privateEndpointName &&
                                pe.Subnet.Id == subnetId &&
                                pe.ProvisioningState == "Succeeded" &&
                                1 == pe.PrivateLinkServiceConnections.Count(
                                    connection =>
                                    connection.PrivateLinkServiceId == plServiceConnection.PrivateLinkServiceId &&
                                    connection.GroupIds.Count == 1 &&
                                    connection.PrivateLinkServiceConnectionState.Status == "Approved" &&
                                    connection.PrivateLinkServiceConnectionState.Description == privateEndpointRequestDescription &&
                                    connection.Name == plServiceConnection.Name &&
                                    connection.GroupIds.Contains(privateLinkResourceName)));

                // verify that the private endpoint connection returned from GET is correct
                createdPrivateEndpoint = await testBase.networkClient.PrivateEndpoints.GetAsync(testBase.rgName, privateEndpointName);

                Assert.Single(createdPrivateEndpoint.PrivateLinkServiceConnections);
                Assert.Equal(privateEndpointName, createdPrivateEndpoint.Name);
                Assert.Equal(subnetId, createdPrivateEndpoint.Subnet.Id);
                Assert.Equal("Succeeded", createdPrivateEndpoint.ProvisioningState);
                Assert.Contains(createdPrivateEndpoint.PrivateLinkServiceConnections,
                                connection =>
                                connection.PrivateLinkServiceId == plServiceConnection.PrivateLinkServiceId &&
                                connection.GroupIds.Count == 1 &&
                                connection.PrivateLinkServiceConnectionState.Status == "Approved" &&
                                connection.PrivateLinkServiceConnectionState.Description == privateEndpointRequestDescription &&
                                connection.Name == plServiceConnection.Name &&
                                connection.GroupIds.Contains(privateLinkResourceName));

                // verify that the private endpoint connection returned from LIST is correct
                var privateEndpointList = await testBase.networkClient.PrivateEndpoints.ListBySubscriptionAsync();

                Assert.Contains(privateEndpointList,
                                endpoint =>
                                endpoint.Name == privateEndpointName &&
                                endpoint.Subnet.Id == subnetId &&
                                1 == endpoint.PrivateLinkServiceConnections.Count(
                                    connection =>
                                    connection.PrivateLinkServiceId == plServiceConnection.PrivateLinkServiceId &&
                                    connection.GroupIds.Count == 1 &&
                                    connection.PrivateLinkServiceConnectionState.Status == "Approved" &&
                                    connection.PrivateLinkServiceConnectionState.Description == privateEndpointRequestDescription &&
                                    connection.Name == plServiceConnection.Name &&
                                    connection.GroupIds.Contains(privateLinkResourceName)));

                // verfity that the private endpoint connection returned from GET api service container is correct
                // NOTE: currently connection.Name is returning internal name, need to verify after it is fixed
                var apiService = await testBase.client.ApiManagementService.GetAsync(testBase.rgName, testBase.serviceName);

                Assert.Contains(apiService.PrivateEndpointConnections,
                                connection =>
                                //connection.Name == privateEndpointName &&
                                connection.ProvisioningState == "Succeeded" &&
                                connection.PrivateLinkServiceConnectionState.Status == "Approved" &&
                                connection.PrivateLinkServiceConnectionState.Description == privateEndpointRequestDescription &&
                                connection.Id == apimPrivateEndpointConnectionId &&
                                connection.GroupIds.Contains(privateLinkResourceName) &&
                                connection.PrivateEndpoint.Id == apimPrivateEndpointId);

                // run only on live testing because generic HttpClient is not supported in recording
                if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Live")
                {
                    // verify that the service is reachable
                    var httpStatusCode = await CallApiServiceEchoApi(testBase);

                    Assert.True(IsSuccessStatusCode((int)httpStatusCode));
                }

                // disable public network access for the api service and confirm the container is updated with GET
                apiService.PublicNetworkAccess = "Disabled";
                await testBase.client.ApiManagementService.CreateOrUpdateAsync(testBase.rgName, testBase.serviceName, apiService);

                apiService = await testBase.client.ApiManagementService.GetAsync(testBase.rgName, testBase.serviceName);

                Assert.Contains(apiService.PrivateEndpointConnections,
                                connection =>
                                //connection.Name == privateEndpointName &&
                                connection.ProvisioningState == "Succeeded" &&
                                connection.PrivateLinkServiceConnectionState.Status == "Approved" &&
                                connection.PrivateLinkServiceConnectionState.Description == privateEndpointRequestDescription &&
                                connection.Id == apimPrivateEndpointConnectionId &&
                                connection.GroupIds.Contains(privateLinkResourceName) &&
                                connection.PrivateEndpoint.Id == apimPrivateEndpointId);
                Assert.True(apiService.PublicNetworkAccess == "Disabled");

                // run only on live testing because generic HttpClient is not supported in recording
                if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Live")
                {
                    // verify that the service is not reachable
                    var httpStatusCode = await CallApiServiceEchoApi(testBase);

                    Assert.False(IsSuccessStatusCode((int)httpStatusCode));
                }

                // reject private endpoint and verify
                // NOTE:wait for the fix
                var requestProperty = new PrivateEndpointConnectionRequestProperties(new PrivateLinkServiceConnectionState("Rejected", privateEndpointRejectDescription));
                var request         = new PrivateEndpointConnectionRequest(apimPrivateEndpointConnectionId, requestProperty);
                var updatedPrivateEndpointConnection = await testBase.client.PrivateEndpointConnection.CreateOrUpdateAsync(testBase.rgName, testBase.serviceName, privateEndpointConnectionName, request);

                Assert.Equal(privateEndpointConnectionName, updatedPrivateEndpointConnection.Name);
                Assert.Equal("Succeeded", updatedPrivateEndpointConnection.ProvisioningState);
                Assert.Equal("Rejected", updatedPrivateEndpointConnection.PrivateLinkServiceConnectionState.Status);
                //Assert.Equal(privateEndpointRejectDescription, updatedPrivateEndpointConnection.PrivateLinkServiceConnectionState.Description);
                Assert.Equal(apimPrivateEndpointConnectionId, updatedPrivateEndpointConnection.Id);
                Assert.Equal(apimPrivateEndpointId, updatedPrivateEndpointConnection.PrivateEndpoint.Id);
                Console.WriteLine(updatedPrivateEndpointConnection.Type);

                // delete private endpoint and verify
                testBase.networkClient.PrivateEndpoints.Delete(testBase.rgName, privateEndpointName);
                Assert.Throws <Microsoft.Azure.Management.Network.Models.ErrorException>(() =>
                {
                    testBase.networkClient.PrivateEndpoints.Get(testBase.rgName, privateEndpointName);
                });

                // delete created service and verify
                testBase.client.ApiManagementService.Delete(testBase.rgName, testBase.serviceName);
                Assert.Throws <Microsoft.Azure.Management.ApiManagement.Models.ErrorResponseException>(() =>
                {
                    testBase.client.ApiManagementService.Get(testBase.rgName, testBase.serviceName);
                });
            }
        }