Skip to content

Commit 1ed6933

Browse files
Add BlueprintTestRunner and replace TestController (#18069)
1 parent 4b8c4e7 commit 1ed6933

File tree

5 files changed

+114
-189
lines changed

5 files changed

+114
-189
lines changed

src/Blueprint/Blueprint.Test/ScenarioTests/BlueprintAssignmentTests.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,61 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Microsoft.Azure.Commands.ScenarioTest;
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+
715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
816
using Xunit;
917

1018
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
1119
{
12-
public class BlueprintAssignmentTests
20+
public class BlueprintAssignmentTests : BlueprintTestRunner
1321
{
14-
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
15-
16-
public BlueprintAssignmentTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public BlueprintAssignmentTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
1723
{
18-
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
19-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
20-
TestExecutionHelpers.SetUpSessionAndProfile();
2124
}
2225

2326
[Fact]
2427
[Trait(Category.AcceptanceType, Category.CheckIn)]
2528
public void TestGetBlueprintAssignment()
2629
{
27-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetBlueprintAssignment");
30+
TestRunner.RunTestScript("Test-GetBlueprintAssignment");
2831
}
2932

3033
[Fact(Skip = "Investigate auto-registration for RP")]
3134
[Trait(Category.AcceptanceType, Category.CheckIn)]
3235
public void TestNewBlueprintAssignmentWithSystemAssignedIdentity()
3336
{
34-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewBlueprintAssignmentWithSystemAssignedIdentity");
37+
TestRunner.RunTestScript("Test-NewBlueprintAssignmentWithSystemAssignedIdentity");
3538
}
3639

3740
[Fact(Skip="Investigate auto-registration for RP")]
3841
[Trait(Category.AcceptanceType, Category.CheckIn)]
3942
public void TestNewBlueprintAssignment()
4043
{
41-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewBlueprintAssignment");
44+
TestRunner.RunTestScript("Test-NewBlueprintAssignment");
4245
}
4346

4447
[Fact(Skip = "Investigate auto-registration for RP")]
4548
[Trait(Category.AcceptanceType, Category.CheckIn)]
4649
public void TestSetBlueprintAssignment()
4750
{
48-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SetBlueprintAssignment");
51+
TestRunner.RunTestScript("Test-SetBlueprintAssignment");
4952
}
5053

5154
[Fact(Skip = "Investigate auto-registration for RP")]
5255
[Trait(Category.AcceptanceType, Category.CheckIn)]
5356
public void TestRemoveBlueprintAssignment()
5457
{
55-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-RemoveBlueprintAssignment");
58+
TestRunner.RunTestScript("Test-RemoveBlueprintAssignment");
5659
}
5760

5861
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
using System.Collections.Generic;
16+
using Microsoft.Azure.Commands.TestFx;
17+
using Xunit.Abstractions;
18+
19+
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
20+
{
21+
public class BlueprintTestRunner
22+
{
23+
protected readonly ITestRunner TestRunner;
24+
25+
protected BlueprintTestRunner(ITestOutputHelper output)
26+
{
27+
TestRunner = TestManager.CreateInstance(output)
28+
.WithNewPsScriptFilename($"{GetType().Name}.ps1")
29+
.WithProjectSubfolderForTests("ScenarioTests")
30+
.WithNewRmModules(helper => new[]
31+
{
32+
helper.RMProfileModule,
33+
helper.GetRMModulePath("Az.Blueprint.psd1"),
34+
helper.GetRMModulePath("Az.Resources.psd1")
35+
})
36+
.WithNewRecordMatcherArguments(
37+
userAgentsToIgnore: new Dictionary<string, string>
38+
{
39+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"},
40+
},
41+
resourceProviders: new Dictionary<string, string>
42+
{
43+
{"Microsoft.Resources", null},
44+
{"Microsoft.Features", null},
45+
{"Microsoft.Authorization", null},
46+
{"Microsoft.Compute", null}
47+
}
48+
)
49+
.Build();
50+
}
51+
}
52+
}
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests;
7-
using Microsoft.Azure.Commands.ScenarioTest;
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+
815
using Microsoft.WindowsAzure.Commands.ScenarioTest;
916
using Xunit;
1017

1118
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
1219
{
13-
public class BlueprintTests
20+
public class BlueprintTests : BlueprintTestRunner
1421
{
15-
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
16-
17-
18-
public BlueprintTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public BlueprintTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
1923
{
20-
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
21-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
22-
TestExecutionHelpers.SetUpSessionAndProfile();
2324
}
2425

2526
[Fact(Skip = "There is a framework issue where HttpClient calls are not recorded in session records causing tests to fail in playback mode")]
2627
[Trait(Category.AcceptanceType, Category.CheckIn)]
2728
public void TestGetBlueprint()
2829
{
29-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetBlueprint");
30+
TestRunner.RunTestScript("Test-GetBlueprint");
3031
}
3132

3233
[Fact]
3334
[Trait(Category.AcceptanceType, Category.CheckIn)]
3435
public void TestGetBlueprintWithDefinitionLocationNameAndVersion()
3536
{
36-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetBlueprintWithDefinitionLocationNameAndVersion");
37+
TestRunner.RunTestScript("Test-GetBlueprintWithDefinitionLocationNameAndVersion");
3738
}
3839

3940
[Fact]
4041
[Trait(Category.AcceptanceType, Category.CheckIn)]
4142
public void TestGetBlueprintWithDefinitionLocationNameAndLatestPublished()
4243
{
43-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetBlueprintWithDefinitionLocationNameAndLatestPublished");
44+
TestRunner.RunTestScript("Test-GetBlueprintWithDefinitionLocationNameAndLatestPublished");
4445
}
4546
}
4647
}
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,62 @@
1-
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
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+
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
216
{
3-
using Microsoft.Azure.Commands.ScenarioTest;
4-
using Microsoft.Azure.ServiceManagement.Common.Models;
517
using Microsoft.WindowsAzure.Commands.ScenarioTest;
618
using Xunit;
719
using Xunit.Abstractions;
820

9-
public class ManagementGroupAssignmentTests
21+
public class ManagementGroupAssignmentTests : BlueprintTestRunner
1022
{
11-
private XunitTracingInterceptor logger;
12-
13-
public ManagementGroupAssignmentTests(ITestOutputHelper output)
23+
public ManagementGroupAssignmentTests(ITestOutputHelper output) : base(output)
1424
{
15-
16-
this.logger = new XunitTracingInterceptor(output);
17-
XunitTracingInterceptor.AddToContext(this.logger);
18-
TestExecutionHelpers.SetUpSessionAndProfile();
1925
}
2026

2127
[Fact]
2228
[Trait(Category.AcceptanceType, Category.CheckIn)]
2329
public void TestGetAssignmentsInManagementGroup()
2430
{
25-
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-GetAssignmentsInManagementGroup");
31+
TestRunner.RunTestScript("Test-GetAssignmentsInManagementGroup");
2632
}
2733

2834
[Fact]
2935
[Trait(Category.AcceptanceType, Category.CheckIn)]
3036
public void TestGetSingleAssignmentInManagementGroup()
3137
{
32-
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-GetSingleAssignmentInManagementGroup");
38+
TestRunner.RunTestScript("Test-GetSingleAssignmentInManagementGroup");
3339
}
3440

3541
[Fact(Skip = "Investigate auto-registration for RP")]
3642
[Trait(Category.AcceptanceType, Category.CheckIn)]
3743
public void TestCreateAssignmentInManagementGroup()
3844
{
39-
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-CreateAssignmentInManagementGroup");
45+
TestRunner.RunTestScript("Test-CreateAssignmentInManagementGroup");
4046
}
4147

4248
[Fact(Skip = "Investigate auto-registration for RP")]
4349
[Trait(Category.AcceptanceType, Category.CheckIn)]
4450
public void TestUpdateAssignmentInManagementGroup()
4551
{
46-
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-UpdateAssignmentInManagementGroup");
52+
TestRunner.RunTestScript("Test-UpdateAssignmentInManagementGroup");
4753
}
4854

4955
[Fact]
5056
[Trait(Category.AcceptanceType, Category.CheckIn)]
5157
public void TestRemoveAssignmentInManagementGroup()
5258
{
53-
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-RemoveAssignmentInManagementGroup");
59+
TestRunner.RunTestScript("Test-RemoveAssignmentInManagementGroup");
5460
}
5561
}
5662
}

0 commit comments

Comments
 (0)