1
+ # ----------------------------------------------------------------------------------
2
+ #
3
+ # Copyright Microsoft Corporation
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
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # ----------------------------------------------------------------------------------
14
+
15
+
16
+ # ###################################
17
+ # # IotHub Configuration Cmdlets ##
18
+ # ###################################
19
+
20
+ <#
21
+ . SYNOPSIS
22
+ Test all iothub configuration cmdlets
23
+ #>
24
+ function Test-AzureRmIotHubConfigurationLifecycle
25
+ {
26
+ $Location = Get-Location " Microsoft.Devices" " IotHubs"
27
+ $IotHubName = getAssetName
28
+ $ResourceGroupName = getAssetName
29
+ $Sku = " S1"
30
+ $device1 = getAssetName
31
+ $config1 = getAssetName
32
+ $config2 = getAssetName
33
+
34
+ # Create Resource Group
35
+ $resourceGroup = New-AzResourceGroup - Name $ResourceGroupName - Location $Location
36
+
37
+ # Create Iot Hub
38
+ $iothub = New-AzIotHub - Name $IotHubName - ResourceGroupName $ResourceGroupName - Location $Location - SkuName $Sku - Units 1
39
+
40
+ # Add iot device
41
+ $newDevice1 = Add-AzIotHubDevice - ResourceGroupName $ResourceGroupName - IotHubName $IotHubName - DeviceId $device1 - AuthMethod ' shared_private_key'
42
+ Assert-True { $newDevice1.Id -eq $device1 }
43
+ Assert-False { $newDevice1.Capabilities.IotEdge }
44
+
45
+ # Assign device configuration parameters
46
+ $labels = @ {}
47
+ $labels.add (" key0" , " value0" )
48
+ $metrics = @ {}
49
+ $metrics.add (" query1" , " select deviceId from devices where tags.location='US'" )
50
+ $prop = @ {}
51
+ $prop.add (" Location" , " US" )
52
+ $content = @ {}
53
+ $content.add (" properties.desired.Region" , $prop )
54
+ $condition = " tags.location ='US'"
55
+ $priority = 10
56
+ $updatedPriority = 8
57
+
58
+ # Add device configuration
59
+ $newConfiguration = Add-AzIotHubConfiguration - ResourceGroupName $ResourceGroupName - IotHubName $IotHubName - Name $config1 - Priority $priority - TargetCondition $condition - Label $labels - Metric $metrics - DeviceContent $content
60
+ Assert-True { $newConfiguration.Id -eq $config1 }
61
+
62
+ # Get device configuration details
63
+ $configuration = Get-AzIotHubConfiguration - ResourceGroupName $ResourceGroupName - IotHubName $IotHubName - Name $config1
64
+ Assert-True { $configuration.Id -eq $config1 }
65
+ Assert-True { $configuration.TargetCondition -eq $condition }
66
+ Assert-True { $configuration.Priority -eq $priority }
67
+ Assert-True { $configuration.Labels.Count -eq 1 }
68
+ Assert-True { $configuration.Metrics.Count -eq 1 }
69
+
70
+ # Set device configuration
71
+ $updatedConfiguration = Set-AzIotHubConfiguration - ResourceGroupName $ResourceGroupName - IotHubName $IotHubName - Name $config1 - Priority $updatedPriority
72
+ Assert-True { $updatedConfiguration.Id -eq $config1 }
73
+ Assert-True { $updatedConfiguration.Priority -eq $updatedPriority }
74
+
75
+ # Delete all configuration
76
+ $result = Remove-AzIotHubConfiguration - ResourceGroupName $ResourceGroupName - IotHubName $IotHubName - Passthru
77
+ Assert-True { $result }
78
+
79
+ # Remove IotHub
80
+ Remove-AzIotHub - ResourceGroupName $ResourceGroupName - Name $IotHubName
81
+ }
0 commit comments