public async Task TestSetUp()
        {
            if (Mode == RecordedTestMode.Record || Mode == RecordedTestMode.Playback)
            {
                Initialize();
                string groupName    = Recording.GenerateAssetName(ResourceGroupPrefix);
                string VnetName     = Recording.GenerateAssetName("vnetname");
                string SubnetName   = Recording.GenerateAssetName("subnetname");
                string EndpointName = Recording.GenerateAssetName("endpointxyz");
                ResGroup = await(await ArmClient.GetDefaultSubscriptionAsync().Result.GetResourceGroups().CreateOrUpdateAsync(groupName, new ResourceGroupData(Location))).WaitForCompletionAsync();
                string configurationStoreName = Recording.GenerateAssetName("testapp-");
                ConfigurationStoreData configurationStoreData = new ConfigurationStoreData(Location, new Models.Sku("Standard"))
                {
                    PublicNetworkAccess = PublicNetworkAccess.Disabled
                };
                ConfigStore = await(await ResGroup.GetConfigurationStores().CreateOrUpdateAsync(configurationStoreName, configurationStoreData)).WaitForCompletionAsync();
                // Prepare VNet and Private Endpoint
                VirtualNetworkData vnetData = new VirtualNetworkData()
                {
                    Location     = "eastus",
                    AddressSpace = new AddressSpace()
                    {
                        AddressPrefixes = { "10.0.0.0/16", }
                    },
                    DhcpOptions = new DhcpOptions()
                    {
                        DnsServers = { "10.1.1.1", "10.1.2.4" }
                    },
                    Subnets = { new SubnetData()
                                {
                                    Name = SubnetName, AddressPrefix = "10.0.0.0/24", PrivateEndpointNetworkPolicies = "Disabled"
                                } }
                };
                VirtualNetwork      vnet = await(await ResGroup.GetVirtualNetworks().CreateOrUpdateAsync(VnetName, vnetData)).WaitForCompletionAsync();
                PrivateEndpointData privateEndpointData = new PrivateEndpointData()
                {
                    Location = "eastus",
                    PrivateLinkServiceConnections = { new PrivateLinkServiceConnection()
                                                      {
                                                          Name = "myconnection",
                                                          PrivateLinkServiceId = ConfigStore.Data.Id,
                                                          GroupIds             = { "configurationStores" },
                                                          RequestMessage       = "Please approve my connection",
                                                      } },
                    Subnet = new SubnetData()
                    {
                        Id = "/subscriptions/" + TestEnvironment.SubscriptionId + "/resourceGroups/" + groupName + "/providers/Microsoft.Network/virtualNetworks/" + VnetName + "/subnets/" + SubnetName
                    }
                };
                PrivateEndpoint = await(await ResGroup.GetPrivateEndpoints().CreateOrUpdateAsync(EndpointName, privateEndpointData)).WaitForCompletionAsync();
                List <PrivateEndpointConnection> connections = await ConfigStore.GetPrivateEndpointConnections().GetAllAsync().ToEnumerableAsync();

                Connection = connections.FirstOrDefault();
            }
        }
Beispiel #2
0
 public async Task TestSetUp()
 {
     if (Mode == RecordedTestMode.Record || Mode == RecordedTestMode.Playback)
     {
         Initialize();
         string groupName    = Recording.GenerateAssetName(ResourceGroupPrefix);
         string VnetName     = Recording.GenerateAssetName("vnetname");
         string SubnetName   = Recording.GenerateAssetName("subnetname");
         string EndpointName = Recording.GenerateAssetName("endpointxyz");
         ResGroup = (await ArmClient.GetDefaultSubscriptionAsync().Result.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, groupName, new ResourceGroupData(Location))).Value;
         string configurationStoreName = Recording.GenerateAssetName("testapp-");
         ConfigurationStoreData configurationStoreData = new ConfigurationStoreData(Location, new AppConfigurationSku("Standard"))
         {
             PublicNetworkAccess = PublicNetworkAccess.Disabled
         };
         ConfigStore = (await ResGroup.GetConfigurationStores().CreateOrUpdateAsync(WaitUntil.Completed, configurationStoreName, configurationStoreData)).Value;
         // Prepare VNet and Private Endpoint
         VirtualNetworkData vnetData = new VirtualNetworkData()
         {
             Location = "eastus",
             Subnets  = { new SubnetData()
                          {
                              Name = SubnetName, AddressPrefix = "10.0.0.0/24", PrivateEndpointNetworkPolicies = "Disabled"
                          } }
         };
         vnetData.AddressPrefixes.Add("10.0.0.0/16");
         vnetData.DhcpOptionsDnsServers.Add("10.1.1.1");
         vnetData.DhcpOptionsDnsServers.Add("10.1.2.4");
         VirtualNetworkResource vnet = (await ResGroup.GetVirtualNetworks().CreateOrUpdateAsync(WaitUntil.Completed, VnetName, vnetData)).Value;
         PrivateEndpointData    privateEndpointData = new PrivateEndpointData()
         {
             Location = "eastus",
             PrivateLinkServiceConnections = { new PrivateLinkServiceConnection()
                                               {
                                                   Name = "myconnection",
                                                   PrivateLinkServiceId = ConfigStore.Data.Id,
                                                   GroupIds             = { "configurationStores" },
                                                   RequestMessage       = "Please approve my connection",
                                               } },
             Subnet = new SubnetData()
             {
                 Id = "/subscriptions/" + TestEnvironment.SubscriptionId + "/resourceGroups/" + groupName + "/providers/Microsoft.Network/virtualNetworks/" + VnetName + "/subnets/" + SubnetName
             }
         };
         PrivateEndpointResource = (await ResGroup.GetPrivateEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, EndpointName, privateEndpointData)).Value;
     }
 }