66using Azure . ResourceManager . Resources ;
77using Azure . ResourceManager . TestFramework ;
88using NUnit . Framework ;
9+ using System ;
10+ using System . Collections . Generic ;
11+ using System . Linq ;
912using System . Threading . Tasks ;
1013
1114namespace Azure . ResourceManager . ComputeFleet . Tests
@@ -15,6 +18,11 @@ public class ComputeFleetManagementTestBase : ManagementRecordedTestBase<Compute
1518 protected ArmClient Client { get ; private set ; }
1619 protected SubscriptionResource DefaultSubscription { get ; private set ; }
1720
21+ protected AzureLocation DefaultLocation => AzureLocation . EastUS2 ;
22+
23+ protected ResourceGroupResource _resourceGroup ;
24+ protected GenericResourceCollection _genericResourceCollection ;
25+
1826 protected ComputeFleetManagementTestBase ( bool isAsync , RecordedTestMode mode )
1927 : base ( isAsync , mode )
2028 {
@@ -32,12 +40,110 @@ public async Task CreateCommonClient()
3240 DefaultSubscription = await Client . GetDefaultSubscriptionAsync ( ) . ConfigureAwait ( false ) ;
3341 }
3442
35- protected async Task < ResourceGroupResource > CreateResourceGroup ( SubscriptionResource subscription , string rgNamePrefix , AzureLocation location )
43+ protected async Task < ResourceGroupResource > CreateResourceGroup ( SubscriptionResource subscription )
3644 {
37- string rgName = Recording . GenerateAssetName ( rgNamePrefix ) ;
38- ResourceGroupData input = new ResourceGroupData ( location ) ;
45+ string rgName = Recording . GenerateAssetName ( "testFleetRG-" ) ;
46+ ResourceGroupData input = new ResourceGroupData ( DefaultLocation ) ;
3947 var lro = await subscription . GetResourceGroups ( ) . CreateOrUpdateAsync ( WaitUntil . Completed , rgName , input ) ;
4048 return lro . Value ;
4149 }
50+
51+ protected async Task < GenericResource > CreateVirtualNetwork ( )
52+ {
53+ var ip = await CreatePublicIPAddress ( ) ;
54+ var nat = await CreateNatGateway ( ip . Data . Id ) ;
55+ var nsg = await CreateNetworkSecurityGroups ( ) ;
56+ var vnetName = Recording . GenerateAssetName ( "testVNet-" ) ;
57+ var subnetName = Recording . GenerateAssetName ( "testSubnet-" ) ;
58+ ResourceIdentifier vnetId = new ResourceIdentifier ( $ "{ _resourceGroup . Id } /providers/Microsoft.Network/virtualNetworks/{ vnetName } ") ;
59+ var addressSpaces = new Dictionary < string , object > ( )
60+ {
61+ { "addressPrefixes" , new List < string > ( ) { "10.0.0.0/16" } }
62+ } ;
63+ var subnet = new Dictionary < string , object > ( )
64+ {
65+ { "name" , subnetName } ,
66+ { "properties" , new Dictionary < string , object > ( )
67+ {
68+ { "addressPrefix" , "10.0.2.0/24" } ,
69+ { "networkSecurityGroup" , new Dictionary < string , object > ( )
70+ {
71+ { "id" , nsg . Data . Id . ToString ( ) }
72+ }
73+ } ,
74+ { "natGateway" , new Dictionary < string , object > ( )
75+ {
76+ { "id" , nat . Data . Id . ToString ( ) }
77+ }
78+ }
79+ } }
80+ } ;
81+ var subnets = new List < object > ( ) { subnet } ;
82+ var input = new GenericResourceData ( DefaultLocation )
83+ {
84+ Properties = BinaryData . FromObjectAsJson ( new Dictionary < string , object > ( )
85+ {
86+ { "addressSpace" , addressSpaces } ,
87+ { "subnets" , subnets }
88+ } )
89+ } ;
90+ var operation = await _genericResourceCollection . CreateOrUpdateAsync ( WaitUntil . Completed , vnetId , input ) ;
91+ return operation . Value ;
92+ }
93+
94+ protected ResourceIdentifier GetSubnetId ( GenericResource vnet )
95+ {
96+ var properties = vnet . Data . Properties . ToObjectFromJson ( ) as Dictionary < string , object > ;
97+ var subnets = properties [ "subnets" ] as IEnumerable < object > ;
98+ var subnet = subnets . First ( ) as IDictionary < string , object > ;
99+ return new ResourceIdentifier ( subnet [ "id" ] as string ) ;
100+ }
101+
102+ protected async Task < GenericResource > CreateNetworkSecurityGroups ( )
103+ {
104+ var networkSecurityGroups = Recording . GenerateAssetName ( "testVNetSecurityGroups-" ) ;
105+ ResourceIdentifier networkSecurityGroupsId = new ResourceIdentifier ( $ "{ _resourceGroup . Id } /providers/Microsoft.Network/networkSecurityGroups/{ networkSecurityGroups } ") ;
106+ var input = new GenericResourceData ( DefaultLocation ) { } ;
107+ var operation = await _genericResourceCollection . CreateOrUpdateAsync ( WaitUntil . Completed , networkSecurityGroupsId , input ) ;
108+ return operation . Value ;
109+ }
110+
111+ protected async Task < GenericResource > CreatePublicIPAddress ( )
112+ {
113+ var publicIPAddressName = Recording . GenerateAssetName ( "testPublicIP-" ) ;
114+ ResourceIdentifier publicIPAddress = new ResourceIdentifier ( $ "{ _resourceGroup . Id } /providers/Microsoft.Network/publicIPAddresses/{ publicIPAddressName } ") ;
115+ var input = new GenericResourceData ( DefaultLocation ) {
116+ Sku = new ( ) { Name = "Standard" } ,
117+ Properties = BinaryData . FromObjectAsJson ( new Dictionary < string , object > ( )
118+ {
119+ { "publicIPAllocationMethod" , "Static" }
120+ } )
121+ } ;
122+ var operation = await _genericResourceCollection . CreateOrUpdateAsync ( WaitUntil . Completed , publicIPAddress , input ) ;
123+ return operation . Value ;
124+ }
125+
126+ protected async Task < GenericResource > CreateNatGateway ( ResourceIdentifier publicIp )
127+ {
128+ var natName = Recording . GenerateAssetName ( "testNatGateway-" ) ;
129+ ResourceIdentifier nat = new ResourceIdentifier ( $ "{ _resourceGroup . Id } /providers/Microsoft.Network/natGateways/{ natName } ") ;
130+ var input = new GenericResourceData ( DefaultLocation )
131+ {
132+ Sku = new ( ) { Name = "Standard" } ,
133+ Properties = BinaryData . FromObjectAsJson ( new Dictionary < string , object > ( )
134+ {
135+ { "publicIpAddresses" , new List < object > ( )
136+ {
137+ new Dictionary < string , object > ( )
138+ {
139+ { "id" , publicIp . ToString ( ) }
140+ }
141+ }
142+ }
143+ } )
144+ } ;
145+ var operation = await _genericResourceCollection . CreateOrUpdateAsync ( WaitUntil . Completed , nat , input ) ;
146+ return operation . Value ;
147+ }
42148 }
43149}
0 commit comments