Skip to content

Commit e1d5ab1

Browse files
author
Maddie Clayton
authored
Merge pull request Azure#7217 from LGDoor/signalr-ga
SignalR - Add extra fields to the PS objects returned from cmdlets
2 parents cbd6dee + 0106148 commit e1d5ab1

23 files changed

+5145
-1210
lines changed

src/ResourceManager/SignalR/Commands.SignalR.Test/Commands.SignalR.Test.csproj

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
<ErrorReport>prompt</ErrorReport>
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
35-
<ItemGroup>
36-
<Reference Include="Microsoft.Azure.Management.SignalR, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
37-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.SignalR.0.9.0-preview\lib\net452\Microsoft.Azure.Management.SignalR.dll</HintPath>
38-
<Private>True</Private>
39-
</Reference>
40-
</ItemGroup>
4135
<ItemGroup>
4236
<Compile Include="Properties\AssemblyInfo.cs" />
4337
<Compile Include="ScenarioTests\AzureRmSignalRTests.cs" />
@@ -48,6 +42,9 @@
4842
<None Include="ScenarioTests\AzureRmSignalRTests.ps1">
4943
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5044
</None>
45+
<None Include="ScenarioTests\Common.ps1">
46+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
47+
</None>
5148
<None Include="SessionRecords\**\*.json">
5249
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5350
</None>
@@ -61,5 +58,10 @@
6158
<Name>Commands.SignalR</Name>
6259
</ProjectReference>
6360
</ItemGroup>
61+
<ItemGroup>
62+
<Reference Include="Microsoft.Azure.Management.SignalR, Version=0.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
63+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.SignalR.0.10.0-preview\lib\net452\Microsoft.Azure.Management.SignalR.dll</HintPath>
64+
</Reference>
65+
</ItemGroup>
6466
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
65-
</Project>
67+
</Project>

src/ResourceManager/SignalR/Commands.SignalR.Test/ScenarioTests/AzureRmSignalRTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
using Microsoft.Azure.Commands.ScenarioTest;
1616
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1718
using Xunit;
1819

1920
namespace Microsoft.Azure.Commands.SignalR.Test.ScenarioTests
2021
{
21-
public class AzureRmSignalRTests
22+
public class AzureRmSignalRTests : RMTestBase
2223
{
2324
private readonly ServiceManagemenet.Common.Models.XunitTracingInterceptor _logger;
2425

@@ -31,7 +32,12 @@ public AzureRmSignalRTests(Xunit.Abstractions.ITestOutputHelper output)
3132

3233
[Fact]
3334
[Trait(Category.AcceptanceType, Category.CheckIn)]
34-
public void TestNewAzureRmSignalR()
35-
=> TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewAzureRmSignalR");
35+
public void TestAzureRmSignalR() =>
36+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureRmSignalR");
37+
38+
[Fact]
39+
[Trait(Category.AcceptanceType, Category.CheckIn)]
40+
public void TestAzureRmSignalRWithDefaultArgs() =>
41+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureRmSignalRWithDefaultArgs");
3642
}
3743
}

src/ResourceManager/SignalR/Commands.SignalR.Test/ScenarioTests/AzureRmSignalRTests.ps1

Lines changed: 165 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,174 @@
1414

1515
<#
1616
.SYNOPSIS
17-
List billing periods
17+
Test common SignalR cmdlets.
1818
#>
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
3157

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+
}
3593
}
3694

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+
}
48157
}
49158

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+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
.SYNOPSIS
17+
Gets a SignalR service name
18+
#>
19+
function Get-RandomSignalRName
20+
{
21+
param([string]$prefix = "signalr-test-")
22+
return $prefix + (getAssetName)
23+
}
24+
25+
<#
26+
.SYNOPSIS
27+
Gets a resource group name
28+
#>
29+
function Get-RandomResourceGroupName
30+
{
31+
param([string]$prefix = "signalr-test-rg-")
32+
return $prefix + (getAssetName)
33+
}
34+
35+
<#
36+
.SYNOPSIS
37+
Assert if two locations refer to the same region (lowercased, space removed)
38+
#>
39+
function Assert-LocationEqual
40+
{
41+
param([string]$loc1, [string]$loc2)
42+
43+
$loc1 = $loc1.ToLower().Replace(" ", "")
44+
$loc2 = $loc2.ToLower().Replace(" ", "")
45+
Assert-AreEqual $loc1 $loc2
46+
}
47+
48+
<#
49+
.SYNOPSIS
50+
Gets the default location for a provider
51+
#>
52+
function Get-ProviderLocation([string]$provider)
53+
{
54+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
55+
{
56+
$namespace = $provider.Split("/")[0]
57+
if($provider.Contains("/"))
58+
{
59+
$type = $provider.Substring($namespace.Length + 1)
60+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
61+
62+
if ($location -eq $null)
63+
{
64+
return "East US"
65+
}
66+
else
67+
{
68+
return $location.Locations[0].ToLower() -replace '\s',''
69+
}
70+
}
71+
72+
return "East US"
73+
}
74+
75+
return "East US"
76+
}

0 commit comments

Comments
 (0)