14
14
15
15
<#
16
16
. SYNOPSIS
17
- List billing periods
17
+ Test common SignalR cmdlets.
18
18
#>
19
- function Test-NewAzureRmSignalR
20
- {
21
- $rgName = getAssetName
22
- try
23
- {
24
- $signalR = New-AzureRmSignalR - Name $rgName
25
- }
26
- finally
27
- {
28
- Remove-AzureRmResourceGroup - Name $rgname - Force
29
- }
30
- }
19
+ function Test-AzureRmSignalR {
20
+ # Setup
21
+ $resourceGroupName = Get-RandomResourceGroupName
22
+ $signalrName = Get-RandomSignalRName
23
+ $freeSignalRName = Get-RandomSignalRName " signalr-free-test-"
24
+ $location = Get-ProviderLocation " Microsoft.SignalRService/SignalR"
25
+
26
+ try {
27
+ New-AzureRmResourceGroup - Name $resourceGroupName - Location $location
28
+
29
+ # New Standard SignalR
30
+ $signalr = New-AzureRmSignalR - ResourceGroupName $resourceGroupName - Name $signalrName - Sku " Standard_S1"
31
+ Verify- SignalR $signalr $signalrName $location " Standard_S1" 1
32
+
33
+ # List the SignalR instances by resource group, should return a single SignalR instance
34
+ $signalrs = Get-AzureRmSignalR - ResourceGroupName $resourceGroupName
35
+ Assert-NotNull $signalrs
36
+ Assert-AreEqual " PSSignalRResource" $signalrs.GetType ().Name
37
+ Verify- SignalR $signalrs $signalrName $location " Standard_S1" 1
38
+
39
+ # Get the SignalR instance by name
40
+ $retrievedSignalR = Get-AzureRmSignalR - ResourceGroupName $resourceGroupName - Name $signalrName
41
+ Verify- SignalR $retrievedSignalR $signalrName $location " Standard_S1" 1
42
+
43
+ # create another free instance in the same resource group
44
+ $freeSignalR = New-AzureRmSignalR - ResourceGroupName $resourceGroupName - Name $freeSignalRName - Sku " Free_F1"
45
+ Verify- SignalR $freeSignalR $freeSignalRName $location " Free_F1" 1
46
+
47
+ # List all the SignalR instances in the resource group
48
+ $signalrs = Get-AzureRmSignalR - ResourceGroupName $resourceGroupName
49
+ Assert-NotNull $signalrs
50
+ Assert-AreEqual " Object[]" $signalrs.GetType ().Name
51
+ Assert-AreEqual 2 $signalrs.Length
52
+ $freeSignalR = $signalrs | Where-Object - FilterScript {$_.Sku.Name -eq " Free_F1" }
53
+ $standardSignalR = $signalrs | Where-Object - FilterScript {$_.Sku.Name -eq " Standard_S1" }
54
+ Assert-NotNull $freeSignalR
55
+ Assert-NotNull $standardSignalR
56
+ Verify- SignalR $freeSignalR $freeSignalRName $location " Free_F1" 1
31
57
32
- function Get-Context
33
- {
34
- return [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider ]::Instance.Profile.DefaultContext
58
+ # Get the SignalR instance keys
59
+ $keys = Get-AzureRmSignalRKey - ResourceGroupName $resourceGroupName - Name $signalrName
60
+ Assert-NotNull $keys
61
+ Assert-NotNull $keys.PrimaryKey
62
+ Assert-NotNull $keys.PrimaryConnectionString
63
+ Assert-NotNull $keys.SecondaryKey
64
+ Assert-NotNull $keys.SecondaryConnectionString
65
+
66
+ # regenerate the primary key
67
+ $ret = New-AzureRmSignalRKey - ResourceGroupName $resourceGroupName - Name $signalrName - KeyType Primary - PassThru
68
+ Assert-True { $ret }
69
+ $newKeys1 = Get-AzureRmSignalRKey - ResourceGroupName $resourceGroupName - Name $signalrName
70
+ Assert-NotNull $newKeys1
71
+ Assert-AreNotEqual $keys.PrimaryKey $newKeys1.PrimaryKey
72
+ Assert-AreNotEqual $keys.PrimaryConnectionString $newKeys1.PrimaryConnectionString
73
+ Assert-AreEqual $keys.SecondaryKey $newKeys1.SecondaryKey
74
+ Assert-AreEqual $keys.SecondaryConnectionString $newKeys1.SecondaryConnectionString
75
+
76
+ # regenerate the secondary key
77
+ $ret = New-AzureRmSignalRKey - ResourceGroupName $resourceGroupName - Name $signalrName - KeyType Secondary
78
+ Assert-Null $ret
79
+ $newKeys2 = Get-AzureRmSignalRKey - ResourceGroupName $resourceGroupName - Name $signalrName
80
+ Assert-NotNull $newKeys2
81
+ Assert-AreEqual $newKeys1.PrimaryKey $newKeys2.PrimaryKey
82
+ Assert-AreEqual $newKeys1.PrimaryConnectionString $newKeys2.PrimaryConnectionString
83
+ Assert-AreNotEqual $newKeys1.SecondaryKey $newKeys2.SecondaryKey
84
+ Assert-AreNotEqual $newKeys1.SecondaryConnectionString $newKeys2.SecondaryConnectionString
85
+
86
+ Remove-AzureRmSignalR - ResourceGroupName $resourceGroupName - Name $signalrName
87
+
88
+ Get-AzureRmSignalR - ResourceGroupName $resourceGroupName | Remove-AzureRmSignalR
89
+ }
90
+ finally {
91
+ Remove-AzureRmResourceGroup - Name $resourceGroupName - Force
92
+ }
35
93
}
36
94
37
- function Get-ResourcesClient
38
- {
39
- param ([Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext ] $context )
40
- $factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession ]::Instance.ClientFactory
41
- [System.Type []]$types = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext ],
42
- [string ]
43
- $method = [Microsoft.Azure.Commands.Common.Authentication.IHyakClientFactory ].GetMethod(" CreateClient" , $types )
44
- $closedMethod = $method.MakeGenericMethod ([Microsoft.Azure.Management.Resources.ResourceManagementClient ])
45
- $arguments = $context , [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureEnvironment + Endpoint ]::ResourceManager
46
- $client = $closedMethod.Invoke ($factory , $arguments )
47
- return $client
95
+ <#
96
+ . SYNOPSIS
97
+ Test SignalR cmdlets using default arguments.
98
+ #>
99
+ function Test-AzureRmSignalRWithDefaultArgs {
100
+ $resourceGroupName = Get-RandomResourceGroupName
101
+ $signalrName = Get-RandomSignalRName
102
+ $freeSignalRName = Get-RandomSignalRName " signalr-free-test-"
103
+ $location = Get-ProviderLocation " Microsoft.SignalRService/SignalR"
104
+
105
+ try {
106
+ # New without SignalR resource group, use the SignalR instance name as the resource group
107
+ $signalr = New-AzureRmSignalR - Name $resourceGroupName
108
+ Verify- SignalR $signalr $resourceGroupName $location " Standard_S1" 1
109
+
110
+ $signalrs = Get-AzureRmSignalR - ResourceGroupName $resourceGroupName
111
+ Assert-NotNull $signalrs
112
+ Assert-AreEqual " PSSignalRResource" $signalrs.GetType ().Name
113
+ Verify- SignalR $signalrs $resourceGroupName $location " Standard_S1" 1
114
+
115
+ # Set AzureRm default resource group name, and subsequent calls will use this as the resource group if missing.
116
+ Set-AzureRmDefault - ResourceGroupName $resourceGroupName
117
+ $signalr = New-AzureRmSignalR - Name $signalrName - Sku " Free_F1"
118
+
119
+ # List all the SignalR instances in the resource group
120
+ $signalrs = Get-AzureRmSignalR - ResourceGroupName $resourceGroupName
121
+ Assert-NotNull $signalrs
122
+ Assert-AreEqual " Object[]" $signalrs.GetType ().Name
123
+ Assert-AreEqual 2 $signalrs.Length
124
+ $freeSignalR = $signalrs | Where-Object - FilterScript {$_.Sku.Name -eq " Free_F1" }
125
+ $standardSignalR = $signalrs | Where-Object - FilterScript {$_.Sku.Name -eq " Standard_S1" }
126
+ Assert-NotNull $freeSignalR
127
+ Assert-NotNull $standardSignalR
128
+ Verify- SignalR $freeSignalR $signalrName $location " Free_F1" 1
129
+
130
+ # Get keys from the SignalR instance in the default resource group
131
+ $keys = Get-AzureRmSignalRKey - Name $signalrName
132
+ Assert-NotNull $keys
133
+ Assert-NotNull $keys.PrimaryKey
134
+ Assert-NotNull $keys.PrimaryConnectionString
135
+ Assert-NotNull $keys.SecondaryKey
136
+ Assert-NotNull $keys.SecondaryConnectionString
137
+
138
+ # Regenerate keys for the SignalR instance in the default resource group
139
+ $ret = New-AzureRmSignalRKey - Name $signalrName - KeyType Primary - PassThru
140
+ Assert-True { $ret }
141
+ $newKeys1 = Get-AzureRmSignalRKey - Name $signalrName
142
+ Assert-NotNull $newKeys1
143
+ Assert-AreNotEqual $keys.PrimaryKey $newKeys1.PrimaryKey
144
+ Assert-AreNotEqual $keys.PrimaryConnectionString $newKeys1.PrimaryConnectionString
145
+ Assert-AreEqual $keys.SecondaryKey $newKeys1.SecondaryKey
146
+ Assert-AreEqual $keys.SecondaryConnectionString $newKeys1.SecondaryConnectionString
147
+
148
+ # Remove the SignalR instance with the given name in the default resource group
149
+ Remove-AzureRmSignalR - Name $signalrName
150
+
151
+ # Get the SignalR instance with the given name in the default resource group and remove
152
+ Get-AzureRmSignalR - Name $resourceGroupName | Remove-AzureRmSignalR
153
+ }
154
+ finally {
155
+ Remove-AzureRmResourceGroup - Name $resourceGroupName - Force
156
+ }
48
157
}
49
158
50
- function Remove-AzureRmResourceGroup
51
- {
52
- [CmdletBinding ()]
53
- param (
54
- [string ] [Parameter (Position = 0 , ValueFromPipelineByPropertyName = $true )] [alias (" ResourceGroupName" )] $Name ,
55
- [switch ] $Force )
56
- BEGIN {
57
- $context = Get-Context
58
- $client = Get-ResourcesClient $context
59
- }
60
- PROCESS {
61
- $deleteTask = $client.ResourceGroups.DeleteAsync ($Name , [System.Threading.CancellationToken ]::None)
62
- $rg = $deleteTask.Result
63
- }
64
- END {}
65
- }
159
+ <#
160
+ . SYNOPSIS
161
+ Verify basic SignalR object properties.
162
+ #>
163
+ function Verify-SignalR {
164
+ param (
165
+ [Microsoft.Azure.Commands.SignalR.Models.PSSignalRResource ] $signalr ,
166
+ [string ] $signalrName ,
167
+ [string ] $location ,
168
+ [string ] $sku ,
169
+ [int ] $unitCount
170
+ )
171
+ Assert-NotNull $signalr
172
+ Assert-NotNull $signalr.Id
173
+ Assert-NotNull $signalr.Type
174
+ Assert-AreEqual $signalrName $signalr.Name
175
+ Assert-LocationEqual $location $signalr.Location
176
+
177
+ Assert-NotNull $signalr.Sku
178
+ Assert-AreEqual ([Microsoft.Azure.Commands.SignalR.Models.PSResourceSku ]) $signalr.Sku.GetType ()
179
+ Assert-AreEqual $sku $signalr.Sku.Name
180
+ Assert-AreEqual $unitCount $signalr.Sku.Capacity
181
+ Assert-AreEqual " Succeeded" $signalr.ProvisioningState
182
+ Assert-AreEqual " $signalrName .service.signalr.net" $signalr.HostName
183
+ Assert-NotNull $signalr.ExternalIP
184
+ Assert-NotNull $signalr.PublicPort
185
+ Assert-NotNull $signalr.ServerPort
186
+ Assert-NotNull $signalr.Version
187
+ }
0 commit comments