File tree Expand file tree Collapse file tree 3 files changed +24
-6
lines changed
src/ResourceManager/Network
Commands.Network.Test/ScenarioTests Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -150,16 +150,29 @@ function Test-subnetCRUD
150
150
Assert-AreEqual $subnetName $vnetExpected.Subnets [0 ].Name
151
151
Assert-AreEqual $subnet2Name $vnetExpected.Subnets [1 ].Name
152
152
Assert-AreEqual " 10.0.3.0/24" $vnetExpected.Subnets [1 ].AddressPrefix
153
-
153
+
154
154
# Get subnet
155
155
$subnet2 = Get-AzureRmvirtualNetwork - Name $vnetName - ResourceGroupName $rgname | Get-AzureRmVirtualNetworkSubnetConfig - Name $subnet2Name
156
156
$subnetAll = Get-AzureRmvirtualNetwork - Name $vnetName - ResourceGroupName $rgname | Get-AzureRmVirtualNetworkSubnetConfig
157
-
157
+
158
158
Assert-AreEqual 2 @ ($subnetAll ).Count
159
159
Assert-AreEqual $subnetName $subnetAll [0 ].Name
160
160
Assert-AreEqual $subnet2Name $subnetAll [1 ].Name
161
161
Assert-AreEqual $subnet2Name $subnet2.Name
162
162
163
+ # Get non-existing subnet
164
+ try
165
+ {
166
+ $subnetNotExists = $vnetExpected | Get-AzureRmVirtualNetworkSubnetConfig - Name " Subnet-DoesNotExist"
167
+ }
168
+ catch
169
+ {
170
+ if ($_.Exception.GetType () -ne [System.ArgumentException ])
171
+ {
172
+ throw ;
173
+ }
174
+ }
175
+
163
176
# Remove a subnet
164
177
Get-AzureRmvirtualNetwork - Name $vnetName - ResourceGroupName $rgname | Remove-AzureRmVirtualNetworkSubnetConfig - Name $subnet2Name | Set-AzureRmVirtualNetwork
165
178
Original file line number Diff line number Diff line change 26
26
* Added example for Set-AzureRmVirtualNetworkGatewayConnectionSharedKey
27
27
* Added example for Set-AzureRmVirtualNetworkGatewayConnection
28
28
* Re-generated cmdlets for ApplicationSecurityGroup, RouteTable and Usage using latest code generator
29
+ * Clarified error message for Get-AzureRmVirtualNetworkSubnetConfig when attempting to get a subnet that does not exitc
29
30
30
31
## Version 6.4.1
31
32
* Updated all help files to include full parameter types and correct input/output types.
Original file line number Diff line number Diff line change 13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using Microsoft . Azure . Commands . Network . Models ;
16
+ using System ;
16
17
using System . Linq ;
17
18
using System . Management . Automation ;
18
19
@@ -34,14 +35,18 @@ public class GetAzureVirtualNetworkSubnetConfigCommand : NetworkBaseCmdlet
34
35
35
36
public override void Execute ( )
36
37
{
37
-
38
38
base . Execute ( ) ;
39
39
if ( ! string . IsNullOrEmpty ( this . Name ) )
40
40
{
41
41
var subnet =
42
- this . VirtualNetwork . Subnets . First (
42
+ this . VirtualNetwork . Subnets . FirstOrDefault (
43
43
resource =>
44
- string . Equals ( resource . Name , this . Name , System . StringComparison . CurrentCultureIgnoreCase ) ) ;
44
+ string . Equals ( resource . Name , this . Name , StringComparison . CurrentCultureIgnoreCase ) ) ;
45
+
46
+ if ( subnet == null )
47
+ {
48
+ throw new ArgumentException ( string . Format ( Properties . Resources . ResourceNotFound , this . Name ) ) ;
49
+ }
45
50
46
51
WriteObject ( subnet ) ;
47
52
}
@@ -50,7 +55,6 @@ public override void Execute()
50
55
var subnets = this . VirtualNetwork . Subnets ;
51
56
WriteObject ( subnets , true ) ;
52
57
}
53
-
54
58
}
55
59
}
56
60
}
You can’t perform that action at this time.
0 commit comments