1
+ # <auto-generated>
2
+ # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ #
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ #
17
+ # Warning: This code was generated by a tool.
18
+ #
19
+ # Changes to this file may cause incorrect behavior and will be lost if the
20
+ # code is regenerated.
21
+ #
22
+ # For documentation on code generator please visit
23
+ # https://aka.ms/nrp-code-generation
24
+ # Please contact [email protected] if you need to make changes to this file.
25
+ # </auto-generated>
26
+
27
+ function Check-CmdletReturnType
28
+ {
29
+ param ($cmdletName , $cmdletReturn )
30
+
31
+ $cmdletData = Get-Command $cmdletName ;
32
+ Assert-NotNull $cmdletData ;
33
+ [array ]$cmdletReturnTypes = $cmdletData.OutputType.Name | Foreach-Object { return ($_ -replace " Microsoft.Azure.Commands.Network.Models." , " " ) };
34
+ [array ]$cmdletReturnTypes = $cmdletReturnTypes | Foreach-Object { return ($_ -replace " System." , " " ) };
35
+ $realReturnType = $cmdletReturn.GetType ().Name -replace " Microsoft.Azure.Commands.Network.Models." , " " ;
36
+ return $cmdletReturnTypes -contains $realReturnType ;
37
+ }
38
+
39
+ <#
40
+ . SYNOPSIS
41
+ Test creating new NatGateway using minimal set of parameters
42
+ #>
43
+ function Test-NatGatewayCRUDMinimalParameters
44
+ {
45
+ # Setup
46
+ $rgname = Get-ResourceGroupName ;
47
+ $rglocation = Get-ProviderLocation ResourceManagement;
48
+ $rname = Get-ResourceName ;
49
+ $location = " eastus2" ;
50
+
51
+ try
52
+ {
53
+ $resourceGroup = New-AzResourceGroup - Name $rgname - Location $rglocation ;
54
+
55
+ # Create NatGateway
56
+ $vNatGateway = New-AzNatGateway - ResourceGroupName $rgname - Name $rname - Location $location - Sku Standard;
57
+ Assert-NotNull $vNatGateway ;
58
+ Assert-True { Check- CmdletReturnType " New-AzNatGateway" $vNatGateway };
59
+ Assert-AreEqual $rname $vNatGateway.Name ;
60
+
61
+ # Get NatGateway
62
+ $vNatGateway = Get-AzNatGateway - ResourceGroupName $rgname - Name $rname ;
63
+ Assert-NotNull $vNatGateway ;
64
+ Assert-True { Check- CmdletReturnType " Get-AzNatGateway" $vNatGateway };
65
+ Assert-AreEqual $rname $vNatGateway.Name ;
66
+
67
+ # Get all NatGateways in resource group
68
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName $rgname ;
69
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
70
+
71
+ # Get all NatGateways in subscription
72
+ $listNatGateway = Get-AzNatGateway ;
73
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
74
+
75
+ # Get all NatGateways in subscription wildcard for resource group
76
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName " *" ;
77
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
78
+
79
+ # Get all NatGateways in subscription wildcard for name
80
+ $listNatGateway = Get-AzNatGateway - Name " *" ;
81
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
82
+
83
+ # Get all NatGateways in subscription wildcard for both resource group and name
84
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName " *" - Name " *" ;
85
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
86
+
87
+ # Remove NatGateway
88
+ $job = Remove-AzNatGateway - ResourceGroupName $rgname - Name $rname - PassThru - Force - AsJob;
89
+ $job | Wait-Job ;
90
+ $removeNatGateway = $job | Receive-Job ;
91
+ Assert-AreEqual $true $removeNatGateway ;
92
+
93
+ # Get NatGateway should fail
94
+ Assert-ThrowsContains { Get-AzNatGateway - ResourceGroupName $rgname - Name $rname } " not found" ;
95
+ }
96
+ finally
97
+ {
98
+ # Cleanup
99
+ Clean - ResourceGroup $rgname ;
100
+ }
101
+ }
102
+
103
+ <#
104
+ . SYNOPSIS
105
+ Test creating new NatGateway using minimal set of parameters
106
+ #>
107
+ function Test-NatGatewayWithSubnet
108
+ {
109
+ # Setup
110
+ $rgname = Get-ResourceGroupName ;
111
+ $rglocation = Get-ProviderLocation ResourceManagement;
112
+ $rname = Get-ResourceName ;
113
+ $vnetName = Get-ResourceName
114
+ $subnetName = Get-ResourceName
115
+ $location = " eastus2" ;
116
+ $sku = " Standard"
117
+
118
+ try
119
+ {
120
+ $resourceGroup = New-AzResourceGroup - Name $rgname - Location $rglocation ;
121
+
122
+ # Create NatGateway
123
+ $vNatGateway = New-AzNatGateway - ResourceGroupName $rgname - Name $rname - Location $location - sku $sku ;
124
+ Assert-NotNull $vNatGateway ;
125
+ Assert-True { Check- CmdletReturnType " New-AzNatGateway" $vNatGateway };
126
+ Assert-AreEqual $rname $vNatGateway.Name ;
127
+
128
+ # Get NatGateway
129
+ $vNatGateway = Get-AzNatGateway - ResourceGroupName $rgname - Name $rname ;
130
+ Assert-NotNull $vNatGateway ;
131
+ Assert-True { Check- CmdletReturnType " Get-AzNatGateway" $vNatGateway };
132
+ Assert-AreEqual $rname $vNatGateway.Name ;
133
+
134
+ # Get all NatGateways in resource group
135
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName $rgname ;
136
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
137
+
138
+ # Get all NatGateways in subscription
139
+ $listNatGateway = Get-AzNatGateway ;
140
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
141
+
142
+ # Get all NatGateways in subscription wildcard for resource group
143
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName " *" ;
144
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
145
+
146
+ # Get all NatGateways in subscription wildcard for name
147
+ $listNatGateway = Get-AzNatGateway - Name " *" ;
148
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
149
+
150
+ # Get all NatGateways in subscription wildcard for both resource group and name
151
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName " *" - Name " *" ;
152
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
153
+
154
+ # Create Subnet
155
+ $subnet = New-AzVirtualNetworkSubnetConfig - Name $subnetName - AddressPrefix 10.0 .1.0 / 24 - NatGateway $vNatGateway
156
+ New-AzvirtualNetwork - Name $vnetName - ResourceGroupName $rgname - Location $location - AddressPrefix 10.0 .0.0 / 16 - Subnet $subnet
157
+ $vnet = Get-AzvirtualNetwork - Name $vnetName - ResourceGroupName $rgname
158
+
159
+ # Get Subnet
160
+ $subnet2 = Get-AzvirtualNetwork - Name $vnetName - ResourceGroupName $rgname | Get-AzVirtualNetworkSubnetConfig - Name $subnetName ;
161
+
162
+ # Remove NatGateway
163
+ $job = Remove-AzNatGateway - ResourceGroupName $rgname - Name $rname - PassThru - Force - AsJob;
164
+ $job | Wait-Job ;
165
+ $removeNatGateway = $job | Receive-Job ;
166
+ Assert-AreEqual $true $removeNatGateway ;
167
+
168
+ Assert-AreEqual $vNatGateway.Name @ ($subnet2.NatGateway.Name )
169
+
170
+ # Get NatGateway should fail
171
+ Assert-ThrowsContains { Get-AzNatGateway - ResourceGroupName $rgname - Name $rname } " not found" ;
172
+ }
173
+ finally
174
+ {
175
+ # Cleanup
176
+ Clean - ResourceGroup $rgname ;
177
+ }
178
+ }
179
+
180
+ <#
181
+ . SYNOPSIS
182
+ Test creating new NatGateway
183
+ #>
184
+ function Test-NatGatewayCRUDAllParameters
185
+ {
186
+ # Setup
187
+ $rgname = Get-ResourceGroupName ;
188
+ $rglocation = Get-ProviderLocation ResourceManagement;
189
+ $rname = Get-ResourceName ;
190
+ $location = " eastus2" ;
191
+ # Resource's parameters
192
+ $IdleTimeoutInMinutes = 5 ;
193
+ $Tag = @ {tag1 = ' test' };
194
+ # Resource's parameters for Set test
195
+ $IdleTimeoutInMinutesSet = 10 ;
196
+ $TagSet = @ {tag2 = ' testSet' };
197
+
198
+ try
199
+ {
200
+ $resourceGroup = New-AzResourceGroup - Name $rgname - Location $rglocation ;
201
+
202
+ # Create NatGateway
203
+ $vNatGateway = New-AzNatGateway - ResourceGroupName $rgname - Name $rname - Location $location - IdleTimeoutInMinutes $IdleTimeoutInMinutes - Tag $Tag - Sku Standard;
204
+ Assert-NotNull $vNatGateway ;
205
+ Assert-True { Check- CmdletReturnType " New-AzNatGateway" $vNatGateway };
206
+ Assert-AreEqual $rname $vNatGateway.Name ;
207
+ Assert-AreEqual $IdleTimeoutInMinutes $vNatGateway.IdleTimeoutInMinutes ;
208
+ Assert-AreEqualObjectProperties $Tag $vNatGateway.Tag ;
209
+
210
+ # Get NatGateway
211
+ $vNatGateway = Get-AzNatGateway - ResourceGroupName $rgname - Name $rname ;
212
+ Assert-NotNull $vNatGateway ;
213
+ Assert-True { Check- CmdletReturnType " Get-AzNatGateway" $vNatGateway };
214
+ Assert-AreEqual $rname $vNatGateway.Name ;
215
+ Assert-AreEqual $IdleTimeoutInMinutes $vNatGateway.IdleTimeoutInMinutes ;
216
+ Assert-AreEqualObjectProperties $Tag $vNatGateway.Tag ;
217
+
218
+ # Get all NatGateways in resource group
219
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName $rgname ;
220
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
221
+
222
+ # Get all NatGateways in subscription
223
+ $listNatGateway = Get-AzNatGateway ;
224
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
225
+
226
+ # Get all NatGateways in subscription wildcard for resource group
227
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName " *" ;
228
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
229
+
230
+ # Get all NatGateways in subscription wildcard for name
231
+ $listNatGateway = Get-AzNatGateway - Name " *" ;
232
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
233
+
234
+ # Get all NatGateways in subscription wildcard for both resource group and name
235
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName " *" - Name " *" ;
236
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
237
+
238
+ # Set NatGateway
239
+ $vNatGateway.IdleTimeoutInMinutes = $IdleTimeoutInMinutesSet ;
240
+ $vNatGateway.Tag = $TagSet ;
241
+ $vNatGateway = Set-AzNatGateway - NatGateway $vNatGateway ;
242
+ Assert-NotNull $vNatGateway ;
243
+ Assert-True { Check- CmdletReturnType " Set-AzNatGateway" $vNatGateway };
244
+ Assert-AreEqual $rname $vNatGateway.Name ;
245
+ Assert-AreEqual $IdleTimeoutInMinutesSet $vNatGateway.IdleTimeoutInMinutes ;
246
+ Assert-AreEqualObjectProperties $TagSet $vNatGateway.Tag ;
247
+
248
+ # Get NatGateway
249
+ $vNatGateway = Get-AzNatGateway - ResourceGroupName $rgname - Name $rname ;
250
+ Assert-NotNull $vNatGateway ;
251
+ Assert-True { Check- CmdletReturnType " Get-AzNatGateway" $vNatGateway };
252
+ Assert-AreEqual $rname $vNatGateway.Name ;
253
+ Assert-AreEqual $IdleTimeoutInMinutesSet $vNatGateway.IdleTimeoutInMinutes ;
254
+ Assert-AreEqualObjectProperties $TagSet $vNatGateway.Tag ;
255
+
256
+ # Get all NatGateways in resource group
257
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName $rgname ;
258
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
259
+
260
+ # Get all NatGateways in subscription
261
+ $listNatGateway = Get-AzNatGateway ;
262
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
263
+
264
+ # Get all NatGateways in subscription wildcard for resource group
265
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName " *" ;
266
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
267
+
268
+ # Get all NatGateways in subscription wildcard for name
269
+ $listNatGateway = Get-AzNatGateway - Name " *" ;
270
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
271
+
272
+ # Get all NatGateways in subscription wildcard for both resource group and name
273
+ $listNatGateway = Get-AzNatGateway - ResourceGroupName " *" - Name " *" ;
274
+ Assert-NotNull ($listNatGateway | Where-Object { $_.ResourceGroupName -eq $rgname -and $_.Name -eq $rname });
275
+
276
+ # Remove NatGateway
277
+ $job = Remove-AzNatGateway - ResourceGroupName $rgname - Name $rname - PassThru - Force - AsJob;
278
+ $job | Wait-Job ;
279
+ $removeNatGateway = $job | Receive-Job ;
280
+ Assert-AreEqual $true $removeNatGateway ;
281
+
282
+ # Get NatGateway should fail
283
+ Assert-ThrowsContains { Get-AzNatGateway - ResourceGroupName $rgname - Name $rname } " not found" ;
284
+
285
+ # Set NatGateway should fail
286
+ Assert-ThrowsContains { Set-AzNatGateway - NatGateway $vNatGateway } " not found" ;
287
+ }
288
+ finally
289
+ {
290
+ # Cleanup
291
+ Clean - ResourceGroup $rgname ;
292
+ }
293
+ }
0 commit comments