diff --git a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyEventTests.cs b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyEventTests.cs index f1bed299b772..c45322d9a299 100644 --- a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyEventTests.cs +++ b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyEventTests.cs @@ -12,92 +12,85 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.ScenarioTest; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests { - public class PolicyEventTests + public class PolicyEventTests : PolicyInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public PolicyEventTests(Xunit.Abstractions.ITestOutputHelper output) + public PolicyEventTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ManagementGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ManagementGroupScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ManagementGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ManagementGroupScope_Paging() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ManagementGroupScope-Paging"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ManagementGroupScope-Paging"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void SubscriptionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-SubscriptionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-SubscriptionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void SubscriptionScope_Paging() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-SubscriptionScope-Paging"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-SubscriptionScope-Paging"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ResourceGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ResourceGroupScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ResourceGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ResourceScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ResourceScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ResourceScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void PolicySetDefinitionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-PolicySetDefinitionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-PolicySetDefinitionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void PolicyDefinitionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-PolicyDefinitionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-PolicyDefinitionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void SubscriptionLevelPolicyAssignmentScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-SubscriptionLevelPolicyAssignmentScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-SubscriptionLevelPolicyAssignmentScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ResourceGroupLevelPolicyAssignmentScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyEvent-ResourceGroupLevelPolicyAssignmentScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyEvent-ResourceGroupLevelPolicyAssignmentScope"); } } } diff --git a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyInsightsTestRunner.cs b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyInsightsTestRunner.cs new file mode 100644 index 000000000000..13d8854c8254 --- /dev/null +++ b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyInsightsTestRunner.cs @@ -0,0 +1,51 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections.Generic; +using Microsoft.Azure.Commands.TestFx; +using Xunit.Abstractions; + +namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests +{ + public class PolicyInsightsTestRunner + { + protected readonly ITestRunner TestRunner; + + protected PolicyInsightsTestRunner(ITestOutputHelper output) + { + TestRunner = TestManager.CreateInstance(output) + .WithNewPsScriptFilename($"{GetType().Name}.ps1") + .WithProjectSubfolderForTests("ScenarioTests") + .WithCommonPsScripts(new[] + { + @"Common.ps1" + }) + .WithNewRmModules(helper => new[] + { + helper.RMProfileModule, + helper.GetRMModulePath("Az.PolicyInsights.psd1") + }) + .WithNewRecordMatcherArguments( + userAgentsToIgnore: new Dictionary<string, string>(), + resourceProviders: new Dictionary<string, string> + { + { "Microsoft.Resources", null }, + { "Microsoft.Features", null }, + { "Microsoft.Authorization", null } + } + ) + .Build(); + } + } +} \ No newline at end of file diff --git a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyMetadataTests.cs b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyMetadataTests.cs index 28ee462dde72..e841ff4f8636 100644 --- a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyMetadataTests.cs +++ b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyMetadataTests.cs @@ -12,8 +12,6 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.ScenarioTest; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; @@ -22,36 +20,31 @@ namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests /// <summary> /// Policy metadata scenario tests. /// </summary> - public class PolicyMetadataTests + public class PolicyMetadataTests : PolicyInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public PolicyMetadataTests(Xunit.Abstractions.ITestOutputHelper output) + public PolicyMetadataTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ListAll() { - TestController.NewInstance.RunPowerShellTest(_logger, "PolicyMetadata-ListAll"); + TestRunner.RunTestScript("PolicyMetadata-ListAll"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ListTop() { - TestController.NewInstance.RunPowerShellTest(_logger, "PolicyMetadata-ListTop"); + TestRunner.RunTestScript("PolicyMetadata-ListTop"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void GetNamedResource() { - TestController.NewInstance.RunPowerShellTest(_logger, "PolicyMetadata-GetNamedResource"); + TestRunner.RunTestScript("PolicyMetadata-GetNamedResource"); } } } diff --git a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateSummaryTests.cs b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateSummaryTests.cs index 51c5d9e2fcdc..bbea4e285dec 100644 --- a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateSummaryTests.cs +++ b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateSummaryTests.cs @@ -12,78 +12,71 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.ScenarioTest; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests { - public class PolicyStateSummaryTests + public class PolicyStateSummaryTests : PolicyInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public PolicyStateSummaryTests(Xunit.Abstractions.ITestOutputHelper output) + public PolicyStateSummaryTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ManagementGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-ManagementGroupScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-ManagementGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void SubscriptionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-SubscriptionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-SubscriptionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ResourceGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-ResourceGroupScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-ResourceGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ResourceScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-ResourceScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-ResourceScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void PolicySetDefinitionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-PolicySetDefinitionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-PolicySetDefinitionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void PolicyDefinitionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-PolicyDefinitionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-PolicyDefinitionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void SubscriptionLevelPolicyAssignmentScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-SubscriptionLevelPolicyAssignmentScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-SubscriptionLevelPolicyAssignmentScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ResourceGroupLevelPolicyAssignmentScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyStateSummary-ResourceGroupLevelPolicyAssignmentScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyStateSummary-ResourceGroupLevelPolicyAssignmentScope"); } } } diff --git a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateTests.cs b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateTests.cs index 0fa8d2ea15d2..e0aedc46ecf6 100644 --- a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateTests.cs +++ b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/PolicyStateTests.cs @@ -12,22 +12,15 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.ScenarioTest; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests { - public class PolicyStateTests + public class PolicyStateTests : PolicyInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public PolicyStateTests(Xunit.Abstractions.ITestOutputHelper output) + public PolicyStateTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } #region Policy States Latest - Scopes @@ -36,56 +29,56 @@ public PolicyStateTests(Xunit.Abstractions.ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void LatestManagementGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-LatestManagementGroupScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-LatestManagementGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void LatestSubscriptionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-LatestSubscriptionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-LatestSubscriptionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void LatestResourceGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-LatestResourceGroupScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-LatestResourceGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void LatestResourceScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-LatestResourceScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-LatestResourceScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void LatestPolicySetDefinitionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-LatestPolicySetDefinitionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-LatestPolicySetDefinitionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void LatestPolicyDefinitionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-LatestPolicyDefinitionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-LatestPolicyDefinitionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void LatestSubscriptionLevelPolicyAssignmentScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-LatestSubscriptionLevelPolicyAssignmentScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-LatestSubscriptionLevelPolicyAssignmentScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void LatestResourceGroupLevelPolicyAssignmentScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-LatestResourceGroupLevelPolicyAssignmentScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-LatestResourceGroupLevelPolicyAssignmentScope"); } #endregion @@ -96,56 +89,56 @@ public void LatestResourceGroupLevelPolicyAssignmentScope() [Trait(Category.AcceptanceType, Category.CheckIn)] public void AllManagementGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-AllManagementGroupScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-AllManagementGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void AllSubscriptionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-AllSubscriptionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-AllSubscriptionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void AllResourceGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-AllResourceGroupScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-AllResourceGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void AllResourceScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-AllResourceScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-AllResourceScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void AllPolicySetDefinitionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-AllPolicySetDefinitionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-AllPolicySetDefinitionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void AllPolicyDefinitionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-AllPolicyDefinitionScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-AllPolicyDefinitionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void AllSubscriptionLevelPolicyAssignmentScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-AllSubscriptionLevelPolicyAssignmentScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-AllSubscriptionLevelPolicyAssignmentScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void AllResourceGroupLevelPolicyAssignmentScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-AllResourceGroupLevelPolicyAssignmentScope"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-AllResourceGroupLevelPolicyAssignmentScope"); } #endregion @@ -157,35 +150,35 @@ public void AllResourceGroupLevelPolicyAssignmentScope() [Trait(Category.AcceptanceType, Category.CheckIn)] public void ManagementGroupScope_Paging() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-ManagementGroupScope-Paging"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-ManagementGroupScope-Paging"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void SubscriptionScope_Paging() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-SubscriptionScope-Paging"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-SubscriptionScope-Paging"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void PolicyDefinitionScope_Paging() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-PolicyDefinitionScope-Paging"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-PolicyDefinitionScope-Paging"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void PolicySetDefinitionScope_Paging() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-PolicySetDefinitionScope-Paging"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-PolicySetDefinitionScope-Paging"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void PolicyAssignmentScope_Paging() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmPolicyState-PolicyAssignmentScope-Paging"); + TestRunner.RunTestScript("Get-AzureRmPolicyState-PolicyAssignmentScope-Paging"); } #endregion @@ -196,21 +189,21 @@ public void PolicyAssignmentScope_Paging() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TriggerEvaluationSubscriptionScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Start-AzPolicyComplianceScan-SubscriptionScope"); + TestRunner.RunTestScript("Start-AzPolicyComplianceScan-SubscriptionScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TriggerEvaluationResourceGroupScope() { - TestController.NewInstance.RunPowerShellTest(_logger, "Start-AzPolicyComplianceScan-ResourceGroupScope"); + TestRunner.RunTestScript("Start-AzPolicyComplianceScan-ResourceGroupScope"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TriggerEvaluationSubscriptionScope_AsJob() { - TestController.NewInstance.RunPowerShellTest(_logger, "Start-AzPolicyComplianceScan-SubscriptionScope-AsJob"); + TestRunner.RunTestScript("Start-AzPolicyComplianceScan-SubscriptionScope-AsJob"); } #endregion diff --git a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/QueryOptionTests.cs b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/QueryOptionTests.cs index b671590ab6c9..f4fa2cd648f0 100644 --- a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/QueryOptionTests.cs +++ b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/QueryOptionTests.cs @@ -12,78 +12,71 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.ScenarioTest; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests { - public class QueryOptionTests + public class QueryOptionTests : PolicyInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public QueryOptionTests(Xunit.Abstractions.ITestOutputHelper output) + public QueryOptionTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void QueryResultsWithFrom() { - TestController.NewInstance.RunPowerShellTest(_logger, "QueryOptions-QueryResultsWithFrom"); + TestRunner.RunTestScript("QueryOptions-QueryResultsWithFrom"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void QueryResultsWithTo() { - TestController.NewInstance.RunPowerShellTest(_logger, "QueryOptions-QueryResultsWithTo"); + TestRunner.RunTestScript("QueryOptions-QueryResultsWithTo"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void QueryResultsWithTop() { - TestController.NewInstance.RunPowerShellTest(_logger, "QueryOptions-QueryResultsWithTop"); + TestRunner.RunTestScript("QueryOptions-QueryResultsWithTop"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void QueryResultsWithOrderBy() { - TestController.NewInstance.RunPowerShellTest(_logger, "QueryOptions-QueryResultsWithOrderBy"); + TestRunner.RunTestScript("QueryOptions-QueryResultsWithOrderBy"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void QueryResultsWithSelect() { - TestController.NewInstance.RunPowerShellTest(_logger, "QueryOptions-QueryResultsWithSelect"); + TestRunner.RunTestScript("QueryOptions-QueryResultsWithSelect"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void QueryResultsWithFilter() { - TestController.NewInstance.RunPowerShellTest(_logger, "QueryOptions-QueryResultsWithFilter"); + TestRunner.RunTestScript("QueryOptions-QueryResultsWithFilter"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void QueryResultsWithApply() { - TestController.NewInstance.RunPowerShellTest(_logger, "QueryOptions-QueryResultsWithApply"); + TestRunner.RunTestScript("QueryOptions-QueryResultsWithApply"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void QueryResultsWithExpandPolicyEvaluationDetails() { - TestController.NewInstance.RunPowerShellTest(_logger, "QueryOptions-QueryResultsWithExpandPolicyEvaluationDetails"); + TestRunner.RunTestScript("QueryOptions-QueryResultsWithExpandPolicyEvaluationDetails"); } } } diff --git a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/RemediationTests.cs b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/RemediationTests.cs index 6573347fa3bb..425891b33821 100644 --- a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/RemediationTests.cs +++ b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/RemediationTests.cs @@ -12,8 +12,6 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.Commands.ScenarioTest; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; @@ -27,71 +25,66 @@ namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests /// TEST_CSM_ORGID_AUTHENTICATION=SubscriptionId=f67cc918-f64f-4c3f-aa24-a855465f9d41;ServicePrincipal=20f84e2b-2ca6-4035-a118-6105027fce93;ServicePrincipalSecret=****;AADTenant=72f988bf-86f1-41af-91ab-2d7cd011db47;Environment=Prod; /// See ../EnvSetup/RemediationSetup.ps1 for a helper script to get the appropriate policies and resources created in your subscription /// </remarks> - public class RemediationTests + public class RemediationTests : PolicyInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public RemediationTests(Xunit.Abstractions.ITestOutputHelper output) + public RemediationTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void SubscriptionScopeCrud() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remediation-SubscriptionScope-Crud"); + TestRunner.RunTestScript("Remediation-SubscriptionScope-Crud"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ResourceGroupScopeCrud() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remediation-ResourceGroupScope-Crud"); + TestRunner.RunTestScript("Remediation-ResourceGroupScope-Crud"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ResourceScopeCrud() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remediation-ResourceScope-Crud"); + TestRunner.RunTestScript("Remediation-ResourceScope-Crud"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ManagementGroupScopeCrud() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remediation-ManagementGroupScope-Crud"); + TestRunner.RunTestScript("Remediation-ManagementGroupScope-Crud"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void BackgroundJobs() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remediation-BackgroundJobs"); + TestRunner.RunTestScript("Remediation-BackgroundJobs"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ReEvaluateCompliance() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remediation-ReEvaluateCompliance"); + TestRunner.RunTestScript("Remediation-ReEvaluateCompliance"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void LargeRemediation() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remediation-LargeRemediation"); + TestRunner.RunTestScript("Remediation-LargeRemediation"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ErrorHandling() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remediation-ErrorHandling"); + TestRunner.RunTestScript("Remediation-ErrorHandling"); } } } diff --git a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/TestController.cs b/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/TestController.cs deleted file mode 100644 index cf16e7086bd6..000000000000 --- a/src/PolicyInsights/PolicyInsights.Test/ScenarioTests/TestController.cs +++ /dev/null @@ -1,89 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -using Microsoft.Azure.Commands.Common.Authentication; -using Microsoft.Azure.Management.PolicyInsights; -using Microsoft.Azure.Test.HttpRecorder; -using Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory; - -namespace Microsoft.Azure.Commands.PolicyInsights.Test.ScenarioTests -{ - public class TestController : RMTestBase - { - private readonly EnvironmentSetupHelper _helper; - - public PolicyInsightsClient PolicyInsightsClient { get; private set; } - - public static TestController NewInstance => new TestController(); - - protected TestController() - { - _helper = new EnvironmentSetupHelper(); - } - - public void RunPowerShellTest(ServiceManagement.Common.Models.XunitTracingInterceptor logger, params string[] scripts) - { - var sf = new StackTrace().GetFrame(1); - var callingClassType = sf.GetMethod().ReflectedType?.ToString(); - var mockName = sf.GetMethod().Name; - - _helper.TracingInterceptor = logger; - var providers = new Dictionary<string, string> - { - { "Microsoft.Resources", null }, - { "Microsoft.Features", null }, - { "Microsoft.Authorization", null } - }; - var providersToIgnore = new Dictionary<string, string>(); - HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, providers, providersToIgnore); - HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords"); - - using (var context = MockContext.Start(callingClassType, mockName)) - { - SetupManagementClients(context); - - _helper.SetupEnvironment(AzureModule.AzureResourceManager); - - var callingClassName = callingClassType?.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last(); - _helper.SetupModules( - AzureModule.AzureResourceManager, - _helper.RMProfileModule, - _helper.GetRMModulePath(@"AzureRM.PolicyInsights.psd1"), - "ScenarioTests\\Common.ps1", - "ScenarioTests\\" + callingClassName + ".ps1"); - - _helper.RunPowerShellTest(scripts); - } - } - - protected void SetupManagementClients(MockContext context) - { - PolicyInsightsClient = GetPolicyInsightsClient(context); - _helper.SetupManagementClients(PolicyInsightsClient); - } - - private static PolicyInsightsClient GetPolicyInsightsClient(MockContext context) - { - return context.GetServiceClient<PolicyInsightsClient>(TestEnvironmentFactory.GetTestEnvironment()); - } - } -}