Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Blueprint/Blueprint.Test/Blueprint.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<None Remove="UnitTests\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.14.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.20.6-preview" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Blueprint\Blueprint.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
{
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;

public class ManagementGroupAssignmentTests
{
private XunitTracingInterceptor logger;

public ManagementGroupAssignmentTests(ITestOutputHelper output)
{

this.logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(this.logger);
TestExecutionHelpers.SetUpSessionAndProfile();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetAssignmentsInManagementGroup()
{
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-GetAssignmentsInManagementGroup");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetSingleAssignmentInManagementGroup()
{
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-GetSingleAssignmentInManagementGroup");
}

[Fact(Skip = "Investigate auto-registration for RP")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCreateAssignmentInManagementGroup()
{
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-CreateAssignmentInManagementGroup");
}

[Fact(Skip = "Investigate auto-registration for RP")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestUpdateAssignmentInManagementGroup()
{
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-UpdateAssignmentInManagementGroup");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestRemoveAssignmentInManagementGroup()
{
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-RemoveAssignmentInManagementGroup");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
$managementGroupId = "AzBlueprintAssignTest"
$subscriptionId = "a1bfa635-f2bf-42f1-86b5-848c674fc321"
$location = "West US"
$blueprintName = "shenglol-ps-test-bp"
$permanentAssignmentName = "shenglol-ps-test-permanent-assignment"
$transientAssignmentName = "shenglol-ps-test-transient-assignment"

<#
.SYNOPSIS
Test getting Blueprint assignments in a management group.
#>
function Test-GetAssignmentsInManagementGroup
{
$assignments = Get-AzBlueprintAssignment -ManagementGroupId $managementGroupId
Assert-True { $assignments.Count -ge 1 }

$assignment = $assignments | where { $_.Name -eq $permanentAssignmentName }
Assert-NotNull $assignment
}

<#
.SYNOPSIS
Test getting single Blueprint assignment in a management group.
#>
function Test-GetSingleAssignmentInManagementGroup
{
$assignment = Get-AzBlueprintAssignment -Name $permanentAssignmentName -ManagementGroupId $managementGroupId
Assert-NotNull $assignment
Assert-AreEqual $permanentAssignmentName $assignment.Name
}

<#
.SYNOPSIS
Test creating a Blueprint assignment in a management group.
#>
function Test-CreateAssignmentInManagementGroup
{
$blueprint = $blueprint = Get-AzBlueprint -Name $blueprintName -ManagementGroupId $managementGroupId
$rgParameters = @{ProdRG=@{name='shenglol-ps-test-02';location='westus'}}

$assignment = New-AzBlueprintAssignment `
-Name $transientAssignmentName `
-Location $location `
-Blueprint $blueprint `
-ResourceGroupParameter $rgParameters `
-ManagementGroupId $managementGroupId `
-SubscriptionId $subscriptionId

Assert-NotNull $assignment
Assert-AreEqual "Creating" $assignment.ProvisioningState

$timeout = New-TimeSpan -Minutes 4
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()

while ($assignment.ProvisioningState -ne "Succeeded" -and $assignment.ProvisioningState -ne "Failed" -and $stopwatch.elapsed -lt $timeout)
{
Wait-Seconds 10
$assignment = Get-AzBlueprintAssignment -Name $transientAssignmentName -ManagementGroupId $managementGroupId
}

Assert-AreEqual "Succeeded" $assignment.ProvisioningState
}

<#
.SYNOPSIS
Test updating a Blueprint assignment in a management group.
#>
function Test-updateAssignmentInManagementGroup
{
$blueprint = $blueprint = Get-AzBlueprint -Name $blueprintName -ManagementGroupId $managementGroupId
# Update resource group name.
$rgParameters = @{ProdRG=@{name='shenglol-ps-test-03';location='westus'}}

$assignment = Set-AzBlueprintAssignment `
-Name $transientAssignmentName `
-Location $location `
-Blueprint $blueprint `
-ResourceGroupParameter $rgParameters `
-ManagementGroupId $managementGroupId `
-SubscriptionId $subscriptionId

Assert-NotNull $assignment
Assert-AreEqual "Creating" $assignment.ProvisioningState

$timeout = New-TimeSpan -Minutes 4
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()

while ($assignment.ProvisioningState -ne "Succeeded" -and $assignment.ProvisioningState -ne "Failed" -and $stopwatch.elapsed -lt $timeout)
{
Wait-Seconds 10
$assignment = Get-AzBlueprintAssignment -Name $transientAssignmentName -ManagementGroupId $managementGroupId
}

Assert-AreEqual "Succeeded" $assignment.ProvisioningState
}

<#
.SYNOPSIS
Test removing a Blueprint assignment in a management group.
#>
function Test-RemoveAssignmentInManagementGroup
{
$assignment = Remove-AzBlueprintAssignment `
-Name $transientAssignmentName `
-ManagementGroupId $managementGroupId `
-PassThru

Assert-NotNull $assignment
Assert-AreEqual "Deleting" $assignment.ProvisioningState
}
Loading