Skip to content

Commit a07b8fd

Browse files
committed
fixed cmdlet review comments
1 parent 5984519 commit a07b8fd

File tree

42 files changed

+974
-1172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+974
-1172
lines changed

src/ResourceManager/IotHub/Commands.IotHub.Test/ScenarioTests/IotHubRoutingTests.ps1

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ function Test-AzureRmIotHubRoutingLifecycle
3232
$endpointName = getAssetName
3333
$routeName = getAssetName
3434
$Sku = "S1"
35+
$EndpointTypeEventHub = [Microsoft.Azure.Commands.Management.IotHub.Models.PSEndpointType] "EventHub"
36+
$RoutingSourceTwinChangeEvents = [Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingSource] "TwinChangeEvents"
37+
$RoutingSourceDeviceMessages = [Microsoft.Azure.Commands.Management.IotHub.Models.PSRoutingSource] "DeviceMessages"
3538

3639
# Create or Update Resource Group
3740
$resourceGroup = New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
@@ -63,7 +66,7 @@ function Test-AzureRmIotHubRoutingLifecycle
6366
Assert-True { $routingEndpoints.Count -eq 0}
6467

6568
# Add event hub endpoint
66-
$newRoutingEndpoint = Add-AzureRmIotHubRoutingEndpoint -ResourceGroupName $ResourceGroupName -Name $IotHubName -EndpointName $endpointName -EndpointType EventHub -EndpointResourceGroup $eventHubResourceGroup -EndpointSubscriptionId $eventHubSubscriptionId -ConnectionString $ehConnectionString
69+
$newRoutingEndpoint = Add-AzureRmIotHubRoutingEndpoint -ResourceGroupName $ResourceGroupName -Name $IotHubName -EndpointName $endpointName -EndpointType $EndpointTypeEventHub -EndpointResourceGroup $eventHubResourceGroup -EndpointSubscriptionId $eventHubSubscriptionId -ConnectionString $ehConnectionString
6770
Assert-True { $newRoutingEndpoint.ResourceGroup -eq $eventHubResourceGroup}
6871
Assert-True { $newRoutingEndpoint.SubscriptionId -eq $eventHubSubscriptionId}
6972
Assert-True { $newRoutingEndpoint.Name -eq $endpointName}
@@ -80,34 +83,32 @@ function Test-AzureRmIotHubRoutingLifecycle
8083
Assert-True { $routingEndpoints.Count -eq 0}
8184

8285
# Add new route
83-
$routeDataSource = 'DeviceMessages'
84-
$newRoute = Add-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -RouteName $routeName -Source $routeDataSource -EndpointName $endpointName
86+
$newRoute = Add-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -RouteName $routeName -Source $RoutingSourceDeviceMessages -EndpointName $endpointName
8587
Assert-True { $newRoute.Name -eq $routeName}
86-
Assert-True { $newRoute.Source -eq $routeDataSource}
88+
Assert-True { $newRoute.Source -eq $RoutingSourceDeviceMessages}
8789
Assert-True { $newRoute.EndpointNames -eq $endpointName}
8890
Assert-False { $newRoute.IsEnabled }
8991

9092
# Get all routes
9193
$routes = Get-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName
9294
Assert-True { $routes.Count -eq 1}
9395
Assert-True { $routes[0].Name -eq $routeName}
94-
Assert-True { $routes[0].Source -eq $routeDataSource}
96+
Assert-True { $routes[0].Source -eq $RoutingSourceDeviceMessages}
9597
Assert-True { $routes[0].EndpointNames -eq $endpointName}
9698
Assert-False { $routes[0].IsEnabled }
9799

98-
# Update route
99-
$newRouteDataSource = 'TwinChangeEvents'
100-
$updatedRoute = Update-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -RouteName $routeName -Source $newRouteDataSource -Enabled
100+
# Set route
101+
$updatedRoute = Set-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -RouteName $routeName -Source $RoutingSourceTwinChangeEvents -Enabled
101102
Assert-True { $updatedRoute.Name -eq $routeName}
102-
Assert-True { $updatedRoute.Source -eq $newRouteDataSource}
103+
Assert-True { $updatedRoute.Source -eq $RoutingSourceTwinChangeEvents}
103104
Assert-True { $updatedRoute.EndpointNames -eq $endpointName}
104105
Assert-True { $updatedRoute.IsEnabled }
105106

106107
# Test All Routes
107-
$testRouteOutput = Test-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -Source $newRouteDataSource
108+
$testRouteOutput = Test-AzureRmIotHubRoute -ResourceGroupName $ResourceGroupName -Name $IotHubName -Source $RoutingSourceTwinChangeEvents
108109
Assert-True { $testRouteOutput.Count -eq 1}
109110
Assert-True { $testRouteOutput[0].Name -eq $routeName}
110-
Assert-True { $testRouteOutput[0].Source -eq $newRouteDataSource}
111+
Assert-True { $testRouteOutput[0].Source -eq $RoutingSourceTwinChangeEvents}
111112
Assert-True { $testRouteOutput[0].EndpointNames -eq $endpointName}
112113
Assert-True { $testRouteOutput[0].IsEnabled }
113114

src/ResourceManager/IotHub/Commands.IotHub.Test/SessionRecords/Microsoft.Azure.Commands.IotHub.Test.ScenarioTests.IotHubRoutingTests/TestAzureIotHubRoutingLifeCycle.json

Lines changed: 510 additions & 681 deletions
Large diffs are not rendered by default.

src/ResourceManager/IotHub/Commands.IotHub/AzureRM.IotHub.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CmdletsToExport = 'Add-AzureRmIotHubKey', 'Get-AzureRmIotHubEventHubConsumerGrou
8888
'Remove-AzureRmIotHubCertificate', 'Get-AzureRmIotHubRoutingEndpoint',
8989
'Add-AzureRmIotHubRoutingEndpoint','Remove-AzureRmIotHubRoutingEndpoint',
9090
'Get-AzureRmIotHubRoute', 'Add-AzureRmIotHubRoute','Remove-AzureRmIotHubRoute',
91-
'Update-AzureRmIotHubRoute','Test-AzureRmIotHubRoute'
91+
'Set-AzureRmIotHubRoute','Test-AzureRmIotHubRoute'
9292

9393
# Variables to export from this module
9494
# VariablesToExport = @()

src/ResourceManager/IotHub/Commands.IotHub/Commands.IotHub.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<Compile Include="IotHub\Routing\RemoveAzureRmIotHubRoute.cs" />
6565
<Compile Include="IotHub\Routing\RemoveAzureRmIotHubRoutingEndpoint.cs" />
6666
<Compile Include="IotHub\Routing\TestAzureRmIotHubRoute.cs" />
67-
<Compile Include="IotHub\Routing\UpdateAzureRmIotHubRoute.cs" />
67+
<Compile Include="IotHub\Routing\SetAzureRmIotHubRoute.cs" />
6868
<Compile Include="IotHub\SetAzureRmIotHub.cs" />
6969
<Compile Include="IotHub\SetAzureRmIotHubVerifiedCertificate.cs" />
7070
<Compile Include="IotHub\UpdateAzureRmIotHub.cs" />
@@ -155,10 +155,10 @@
155155
<None Include="help\Remove-AzureRmIotHubRoute.md" />
156156
<None Include="help\Remove-AzureRmIotHubRoutingEndpoint.md" />
157157
<None Include="help\Set-AzureRmIotHub.md" />
158+
<None Include="help\Set-AzureRmIotHubRoute.md" />
158159
<None Include="help\Set-AzureRmIotHubVerifiedCertificate.md" />
159160
<None Include="help\Test-AzureRmIotHubRoute.md" />
160161
<None Include="help\Update-AzureRmIotHub.md" />
161-
<None Include="help\Update-AzureRmIotHubRoute.md" />
162162
<Content Include="Microsoft.Azure.Commands.IotHub.format.ps1xml">
163163
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
164164
<SubType>Designer</SubType>

src/ResourceManager/IotHub/Commands.IotHub/IotHub/Routing/AddAzureRmIotHubRoute.cs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class AddAzureRmIotHubRoute : IotHubBaseCmdlet
3232
private const string ResourceParameterSet = "ResourceSet";
3333
private const string InputObjectParameterSet = "InputObjectSet";
3434

35-
[Parameter(Position = 0, Mandatory = true, ParameterSetName = InputObjectParameterSet, ValueFromPipeline = true, HelpMessage = "IotHub Object")]
35+
[Parameter(Position = 0, Mandatory = true, ParameterSetName = InputObjectParameterSet, ValueFromPipeline = true, HelpMessage = "IotHub object")]
3636
[ValidateNotNullOrEmpty]
3737
public PSIotHub InputObject { get; set; }
3838

@@ -55,16 +55,15 @@ public class AddAzureRmIotHubRoute : IotHubBaseCmdlet
5555
[ValidateNotNullOrEmpty]
5656
public string RouteName { get; set; }
5757

58-
[Parameter(Position = 2, Mandatory = true, ParameterSetName = InputObjectParameterSet, HelpMessage = "Source of the route")]
59-
[Parameter(Position = 2, Mandatory = true, ParameterSetName = ResourceIdParameterSet, HelpMessage = "Source of the route")]
60-
[Parameter(Position = 3, Mandatory = true, ParameterSetName = ResourceParameterSet, HelpMessage = "Source of the route")]
58+
[Parameter(Mandatory = true, ParameterSetName = InputObjectParameterSet, HelpMessage = "Source of the route")]
59+
[Parameter(Mandatory = true, ParameterSetName = ResourceIdParameterSet, HelpMessage = "Source of the route")]
60+
[Parameter(Mandatory = true, ParameterSetName = ResourceParameterSet, HelpMessage = "Source of the route")]
6161
[ValidateNotNullOrEmpty]
62-
[ValidateSet(new string[] { "Invalid", "DeviceMessages", "TwinChangeEvents", "DeviceLifecycleEvents", "DeviceJobLifecycleEvents" }, IgnoreCase = true)]
63-
public string Source { get; set; }
62+
public PSRoutingSource Source { get; set; }
6463

65-
[Parameter(Position = 3, Mandatory = true, ParameterSetName = InputObjectParameterSet, HelpMessage = "Name of the routing endpoint")]
66-
[Parameter(Position = 3, Mandatory = true, ParameterSetName = ResourceIdParameterSet, HelpMessage = "Name of the routing endpoint")]
67-
[Parameter(Position = 4, Mandatory = true, ParameterSetName = ResourceParameterSet, HelpMessage = "Name of the routing endpoint")]
64+
[Parameter(Mandatory = true, ParameterSetName = InputObjectParameterSet, HelpMessage = "Name of the routing endpoint")]
65+
[Parameter(Mandatory = true, ParameterSetName = ResourceIdParameterSet, HelpMessage = "Name of the routing endpoint")]
66+
[Parameter(Mandatory = true, ParameterSetName = ResourceParameterSet, HelpMessage = "Name of the routing endpoint")]
6867
[ValidateNotNullOrEmpty]
6968
public string EndpointName { get; set; }
7069

@@ -96,26 +95,18 @@ public override void ExecuteCmdlet()
9695
iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name);
9796
}
9897

99-
PSRoutingSource psRoutingSource;
100-
if (Enum.TryParse<PSRoutingSource>(this.Source, true, out psRoutingSource))
101-
{
102-
iotHubDescription.Properties.Routing.Routes.Add(
103-
new RouteProperties(
104-
this.RouteName,
105-
psRoutingSource.ToString(),
106-
new List<string>() { this.EndpointName },
107-
this.Enabled.IsPresent,
108-
string.IsNullOrEmpty(this.Condition) ? null : this.Condition
109-
));
98+
iotHubDescription.Properties.Routing.Routes.Add(
99+
new RouteProperties(
100+
this.RouteName,
101+
this.Source.ToString(),
102+
new List<string>() { this.EndpointName },
103+
this.Enabled.IsPresent,
104+
string.IsNullOrEmpty(this.Condition) ? null : this.Condition
105+
));
110106

111-
this.IotHubClient.IotHubResource.CreateOrUpdate(this.ResourceGroupName, this.Name, iotHubDescription);
112-
IotHubDescription updatedIotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name);
113-
this.WriteObject(IotHubUtils.ToPSRouteMetadata(updatedIotHubDescription.Properties.Routing.Routes.FirstOrDefault(x => x.Name.Equals(this.RouteName, StringComparison.OrdinalIgnoreCase))), false);
114-
}
115-
else
116-
{
117-
throw new ArgumentException("Invalid Routing Source");
118-
}
107+
this.IotHubClient.IotHubResource.CreateOrUpdate(this.ResourceGroupName, this.Name, iotHubDescription);
108+
IotHubDescription updatedIotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name);
109+
this.WriteObject(IotHubUtils.ToPSRouteMetadata(updatedIotHubDescription.Properties.Routing.Routes.FirstOrDefault(x => x.Name.Equals(this.RouteName, StringComparison.OrdinalIgnoreCase))), false);
119110
}
120111
}
121112
}

0 commit comments

Comments
 (0)