Skip to content

Commit fbaa9e8

Browse files
Add PolicyInsightsTestRunner and replace TestController (#18198)
1 parent bc6a5f6 commit fbaa9e8

File tree

8 files changed

+124
-204
lines changed

8 files changed

+124
-204
lines changed

src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyEventTests.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,92 +12,85 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1816
using Xunit;
1917

2018
namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests
2119
{
22-
public class PolicyEventTests
20+
public class PolicyEventTests : PolicyInsightsTestRunner
2321
{
24-
private readonly XunitTracingInterceptor _logger;
25-
26-
public PolicyEventTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public PolicyEventTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2723
{
28-
_logger = new XunitTracingInterceptor(output);
29-
XunitTracingInterceptor.AddToContext(_logger);
30-
TestExecutionHelpers.SetUpSessionAndProfile();
3124
}
3225

3326
[Fact]
3427
[Trait(Category.AcceptanceType, Category.CheckIn)]
3528
public void ManagementGroupScope()
3629
{
37-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ManagementGroupScope");
30+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ManagementGroupScope");
3831
}
3932

4033
[Fact]
4134
[Trait(Category.AcceptanceType, Category.CheckIn)]
4235
public void ManagementGroupScope_Paging()
4336
{
44-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ManagementGroupScope-Paging");
37+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ManagementGroupScope-Paging");
4538
}
4639

4740
[Fact]
4841
[Trait(Category.AcceptanceType, Category.CheckIn)]
4942
public void SubscriptionScope()
5043
{
51-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-SubscriptionScope");
44+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-SubscriptionScope");
5245
}
5346

5447
[Fact]
5548
[Trait(Category.AcceptanceType, Category.CheckIn)]
5649
public void SubscriptionScope_Paging()
5750
{
58-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-SubscriptionScope-Paging");
51+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-SubscriptionScope-Paging");
5952
}
6053

6154
[Fact]
6255
[Trait(Category.AcceptanceType, Category.CheckIn)]
6356
public void ResourceGroupScope()
6457
{
65-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ResourceGroupScope");
58+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ResourceGroupScope");
6659
}
6760

6861
[Fact]
6962
[Trait(Category.AcceptanceType, Category.CheckIn)]
7063
public void ResourceScope()
7164
{
72-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ResourceScope");
65+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ResourceScope");
7366
}
7467

7568
[Fact]
7669
[Trait(Category.AcceptanceType, Category.CheckIn)]
7770
public void PolicySetDefinitionScope()
7871
{
79-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-PolicySetDefinitionScope");
72+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-PolicySetDefinitionScope");
8073
}
8174

8275
[Fact]
8376
[Trait(Category.AcceptanceType, Category.CheckIn)]
8477
public void PolicyDefinitionScope()
8578
{
86-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-PolicyDefinitionScope");
79+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-PolicyDefinitionScope");
8780
}
8881

8982
[Fact]
9083
[Trait(Category.AcceptanceType, Category.CheckIn)]
9184
public void SubscriptionLevelPolicyAssignmentScope()
9285
{
93-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-SubscriptionLevelPolicyAssignmentScope");
86+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-SubscriptionLevelPolicyAssignmentScope");
9487
}
9588

9689
[Fact]
9790
[Trait(Category.AcceptanceType, Category.CheckIn)]
9891
public void ResourceGroupLevelPolicyAssignmentScope()
9992
{
100-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ResourceGroupLevelPolicyAssignmentScope");
93+
TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ResourceGroupLevelPolicyAssignmentScope");
10194
}
10295
}
10396
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.PolicyInsights.Test.ScenarioTests
20+
{
21+
public class PolicyInsightsTestRunner
22+
{
23+
protected readonly ITestRunner TestRunner;
24+
25+
protected PolicyInsightsTestRunner(ITestOutputHelper output)
26+
{
27+
TestRunner = TestManager.CreateInstance(output)
28+
.WithNewPsScriptFilename($"{GetType().Name}.ps1")
29+
.WithProjectSubfolderForTests("ScenarioTests")
30+
.WithCommonPsScripts(new[]
31+
{
32+
@"Common.ps1"
33+
})
34+
.WithNewRmModules(helper => new[]
35+
{
36+
helper.RMProfileModule,
37+
helper.GetRMModulePath("Az.PolicyInsights.psd1")
38+
})
39+
.WithNewRecordMatcherArguments(
40+
userAgentsToIgnore: new Dictionary<string, string>(),
41+
resourceProviders: new Dictionary<string, string>
42+
{
43+
{ "Microsoft.Resources", null },
44+
{ "Microsoft.Features", null },
45+
{ "Microsoft.Authorization", null }
46+
}
47+
)
48+
.Build();
49+
}
50+
}
51+
}

src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyMetadataTests.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1816
using Xunit;
1917

@@ -22,36 +20,31 @@ namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests
2220
/// <summary>
2321
/// Policy metadata scenario tests.
2422
/// </summary>
25-
public class PolicyMetadataTests
23+
public class PolicyMetadataTests : PolicyInsightsTestRunner
2624
{
27-
private readonly XunitTracingInterceptor _logger;
28-
29-
public PolicyMetadataTests(Xunit.Abstractions.ITestOutputHelper output)
25+
public PolicyMetadataTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
3026
{
31-
_logger = new XunitTracingInterceptor(output);
32-
XunitTracingInterceptor.AddToContext(_logger);
33-
TestExecutionHelpers.SetUpSessionAndProfile();
3427
}
3528

3629
[Fact]
3730
[Trait(Category.AcceptanceType, Category.CheckIn)]
3831
public void ListAll()
3932
{
40-
TestController.NewInstance.RunPowerShellTest(_logger, "PolicyMetadata-ListAll");
33+
TestRunner.RunTestScript("PolicyMetadata-ListAll");
4134
}
4235

4336
[Fact]
4437
[Trait(Category.AcceptanceType, Category.CheckIn)]
4538
public void ListTop()
4639
{
47-
TestController.NewInstance.RunPowerShellTest(_logger, "PolicyMetadata-ListTop");
40+
TestRunner.RunTestScript("PolicyMetadata-ListTop");
4841
}
4942

5043
[Fact]
5144
[Trait(Category.AcceptanceType, Category.CheckIn)]
5245
public void GetNamedResource()
5346
{
54-
TestController.NewInstance.RunPowerShellTest(_logger, "PolicyMetadata-GetNamedResource");
47+
TestRunner.RunTestScript("PolicyMetadata-GetNamedResource");
5548
}
5649
}
5750
}

src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateSummaryTests.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,71 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1816
using Xunit;
1917

2018
namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests
2119
{
22-
public class PolicyStateSummaryTests
20+
public class PolicyStateSummaryTests : PolicyInsightsTestRunner
2321
{
24-
private readonly XunitTracingInterceptor _logger;
25-
26-
public PolicyStateSummaryTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public PolicyStateSummaryTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2723
{
28-
_logger = new XunitTracingInterceptor(output);
29-
XunitTracingInterceptor.AddToContext(_logger);
30-
TestExecutionHelpers.SetUpSessionAndProfile();
3124
}
3225

3326
[Fact]
3427
[Trait(Category.AcceptanceType, Category.CheckIn)]
3528
public void ManagementGroupScope()
3629
{
37-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-ManagementGroupScope");
30+
TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-ManagementGroupScope");
3831
}
3932

4033
[Fact]
4134
[Trait(Category.AcceptanceType, Category.CheckIn)]
4235
public void SubscriptionScope()
4336
{
44-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-SubscriptionScope");
37+
TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-SubscriptionScope");
4538
}
4639

4740
[Fact]
4841
[Trait(Category.AcceptanceType, Category.CheckIn)]
4942
public void ResourceGroupScope()
5043
{
51-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-ResourceGroupScope");
44+
TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-ResourceGroupScope");
5245
}
5346

5447
[Fact]
5548
[Trait(Category.AcceptanceType, Category.CheckIn)]
5649
public void ResourceScope()
5750
{
58-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-ResourceScope");
51+
TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-ResourceScope");
5952
}
6053

6154
[Fact]
6255
[Trait(Category.AcceptanceType, Category.CheckIn)]
6356
public void PolicySetDefinitionScope()
6457
{
65-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-PolicySetDefinitionScope");
58+
TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-PolicySetDefinitionScope");
6659
}
6760

6861
[Fact]
6962
[Trait(Category.AcceptanceType, Category.CheckIn)]
7063
public void PolicyDefinitionScope()
7164
{
72-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-PolicyDefinitionScope");
65+
TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-PolicyDefinitionScope");
7366
}
7467

7568
[Fact]
7669
[Trait(Category.AcceptanceType, Category.CheckIn)]
7770
public void SubscriptionLevelPolicyAssignmentScope()
7871
{
79-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-SubscriptionLevelPolicyAssignmentScope");
72+
TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-SubscriptionLevelPolicyAssignmentScope");
8073
}
8174

8275
[Fact]
8376
[Trait(Category.AcceptanceType, Category.CheckIn)]
8477
public void ResourceGroupLevelPolicyAssignmentScope()
8578
{
86-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-ResourceGroupLevelPolicyAssignmentScope");
79+
TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-ResourceGroupLevelPolicyAssignmentScope");
8780
}
8881
}
8982
}

0 commit comments

Comments
 (0)