diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/ActionsTests.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/ActionsTests.cs index 66d8407540ac..6f0929371062 100644 --- a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/ActionsTests.cs +++ b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/ActionsTests.cs @@ -12,57 +12,50 @@ // 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.SecurityInsights.Test.ScenarioTests { - public class ActionsTests + public class ActionsTests : SecurityInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public ActionsTests(Xunit.Abstractions.ITestOutputHelper output) + public ActionsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ListByAlertRule() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelAlertRuleAction-ListByAlertRule"); + TestRunner.RunTestScript("Get-AzSentinelAlertRuleAction-ListByAlertRule"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void GetAction() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelAlertRuleAction-GetAction"); + TestRunner.RunTestScript("Get-AzSentinelAlertRuleAction-GetAction"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void CreateAction() { - TestController.NewInstance.RunPowerShellTest(_logger, "New-AzSentinelAlertRuleAction-Create"); + TestRunner.RunTestScript("New-AzSentinelAlertRuleAction-Create"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void UpdateAction() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelAlertRuleAction-Update"); + TestRunner.RunTestScript("Update-AzSentinelAlertRuleAction-Update"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void RemoveAction() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remove-AzSentinelAlertRuleAction-Delete"); + TestRunner.RunTestScript("Remove-AzSentinelAlertRuleAction-Delete"); } } } diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/AlertRuleTemplatesTests.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/AlertRuleTemplatesTests.cs index 8f82acd35807..b849adc2425a 100644 --- a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/AlertRuleTemplatesTests.cs +++ b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/AlertRuleTemplatesTests.cs @@ -12,36 +12,29 @@ // 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.SecurityInsights.Test.ScenarioTests { - public class AlertRuleTemplatesTests + public class AlertRuleTemplatesTests : SecurityInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public AlertRuleTemplatesTests(Xunit.Abstractions.ITestOutputHelper output) + public AlertRuleTemplatesTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void List() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelAlertRuleTemplate-List"); + TestRunner.RunTestScript("Get-AzSentinelAlertRuleTemplate-List"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Get() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelAlertRuleTemplate-Get"); + TestRunner.RunTestScript("Get-AzSentinelAlertRuleTemplate-Get"); } } } diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/AlertRulesTests.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/AlertRulesTests.cs index 3bf3cd5214bf..0cbe90cff353 100644 --- a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/AlertRulesTests.cs +++ b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/AlertRulesTests.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.SecurityInsights.Test.ScenarioTests { - public class AlertRulesTests + public class AlertRulesTests : SecurityInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public AlertRulesTests(Xunit.Abstractions.ITestOutputHelper output) + public AlertRulesTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ListAlertRules() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelAlertRule-List"); + TestRunner.RunTestScript("Get-AzSentinelAlertRule-List"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void GetAction() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelAlertRule-Get"); + TestRunner.RunTestScript("Get-AzSentinelAlertRule-Get"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void CreateAlertRuleFusion() { - TestController.NewInstance.RunPowerShellTest(_logger, "New-AzSentinelAlertRule-CreateFusion"); + TestRunner.RunTestScript("New-AzSentinelAlertRule-CreateFusion"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void CreateAlertRuleMSIC() { - TestController.NewInstance.RunPowerShellTest(_logger, "New-AzSentinelAlertRule-CreateMSIC"); + TestRunner.RunTestScript("New-AzSentinelAlertRule-CreateMSIC"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void CreateAlertRuleScheduled() { - TestController.NewInstance.RunPowerShellTest(_logger, "New-AzSentinelAlertRule-CreateScheduled"); + TestRunner.RunTestScript("New-AzSentinelAlertRule-CreateScheduled"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void UpdateAlertRule() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelAlertRule-Update"); + TestRunner.RunTestScript("Update-AzSentinelAlertRule-Update"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void InputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelAlertRule-InputObject"); + TestRunner.RunTestScript("Update-AzSentinelAlertRule-InputObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void RemoveAlertRule() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remove-AzSentinelAlertRule-Delete"); + TestRunner.RunTestScript("Remove-AzSentinelAlertRule-Delete"); } } } diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/BookmarksTests.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/BookmarksTests.cs index d18d1705fcda..b35e2ad8ac7d 100644 --- a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/BookmarksTests.cs +++ b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/BookmarksTests.cs @@ -12,64 +12,57 @@ // 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.SecurityInsights.Test.ScenarioTests { - public class BookmarksTests + public class BookmarksTests : SecurityInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public BookmarksTests(Xunit.Abstractions.ITestOutputHelper output) + public BookmarksTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void List() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelBookmark-List"); + TestRunner.RunTestScript("Get-AzSentinelBookmark-List"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Get() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelBookmark-Get"); + TestRunner.RunTestScript("Get-AzSentinelBookmark-Get"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Create() { - TestController.NewInstance.RunPowerShellTest(_logger, "New-AzSentinelBookmark-Create"); + TestRunner.RunTestScript("New-AzSentinelBookmark-Create"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Update() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelBookmark-Update"); + TestRunner.RunTestScript("Update-AzSentinelBookmark-Update"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void InputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelBookmark-InputObject"); + TestRunner.RunTestScript("Update-AzSentinelBookmark-InputObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Remove() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remove-AzSentinelBookmark-Remove"); + TestRunner.RunTestScript("Remove-AzSentinelBookmark-Remove"); } } } diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/DataConnectorsTests.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/DataConnectorsTests.cs index f2d6ecb2d2c6..227bdee39f88 100644 --- a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/DataConnectorsTests.cs +++ b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/DataConnectorsTests.cs @@ -12,64 +12,57 @@ // 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.SecurityInsights.Test.ScenarioTests { - public class DataConnectorsTests + public class DataConnectorsTests : SecurityInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public DataConnectorsTests(Xunit.Abstractions.ITestOutputHelper output) + public DataConnectorsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void List() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelDataConnector-List"); + TestRunner.RunTestScript("Get-AzSentinelDataConnector-List"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Get() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelDataConnector-Get"); + TestRunner.RunTestScript("Get-AzSentinelDataConnector-Get"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Create() { - TestController.NewInstance.RunPowerShellTest(_logger, "New-AzSentinelDataConnector-Create"); + TestRunner.RunTestScript("New-AzSentinelDataConnector-Create"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Update() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelDataConnector-Update"); + TestRunner.RunTestScript("Update-AzSentinelDataConnector-Update"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void InputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelDataConnector-InputObject"); + TestRunner.RunTestScript("Update-AzSentinelDataConnector-InputObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Delete() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remove-AzSentinelDataConnector-Delete"); + TestRunner.RunTestScript("Remove-AzSentinelDataConnector-Delete"); } } } diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/IncidentCommentsTests.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/IncidentCommentsTests.cs index 9750c1515693..5a6a187a87fb 100644 --- a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/IncidentCommentsTests.cs +++ b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/IncidentCommentsTests.cs @@ -12,43 +12,36 @@ // 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.SecurityInsights.Test.ScenarioTests { - public class IncidentCommentsTests + public class IncidentCommentsTests : SecurityInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public IncidentCommentsTests(Xunit.Abstractions.ITestOutputHelper output) + public IncidentCommentsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void List() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelIncidentComment-ListByIncident"); + TestRunner.RunTestScript("Get-AzSentinelIncidentComment-ListByIncident"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Get() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelIncidentComment-Get"); + TestRunner.RunTestScript("Get-AzSentinelIncidentComment-Get"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Create() { - TestController.NewInstance.RunPowerShellTest(_logger, "New-AzSentinelIncidentComment-Create"); + TestRunner.RunTestScript("New-AzSentinelIncidentComment-Create"); } } } diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/IncidentsTests.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/IncidentsTests.cs index 65a51efe42dc..fcc811d8a01d 100644 --- a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/IncidentsTests.cs +++ b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/IncidentsTests.cs @@ -12,64 +12,57 @@ // 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.SecurityInsights.Test.ScenarioTests { - public class IncidentsTests + public class IncidentsTests : SecurityInsightsTestRunner { - private readonly XunitTracingInterceptor _logger; - - public IncidentsTests(Xunit.Abstractions.ITestOutputHelper output) + public IncidentsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - TestExecutionHelpers.SetUpSessionAndProfile(); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void List() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelIncident-List"); + TestRunner.RunTestScript("Get-AzSentinelIncident-List"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Get() { - TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSentinelIncident-Get"); + TestRunner.RunTestScript("Get-AzSentinelIncident-Get"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Create() { - TestController.NewInstance.RunPowerShellTest(_logger, "New-AzSentinelIncident-Create"); + TestRunner.RunTestScript("New-AzSentinelIncident-Create"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Update() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelIncident-Update"); + TestRunner.RunTestScript("Update-AzSentinelIncident-Update"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void InputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSentinelIncident-InputObject"); + TestRunner.RunTestScript("Update-AzSentinelIncident-InputObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void Remove() { - TestController.NewInstance.RunPowerShellTest(_logger, "Remove-AzSentinelIncident-Delete"); + TestRunner.RunTestScript("Remove-AzSentinelIncident-Delete"); } } } diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/SecurityInsightsTestRunner.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/SecurityInsightsTestRunner.cs new file mode 100644 index 000000000000..86672ec7d243 --- /dev/null +++ b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/SecurityInsightsTestRunner.cs @@ -0,0 +1,57 @@ +// ---------------------------------------------------------------------------------- +// +// 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.SecurityInsights.Test.ScenarioTests +{ + public class SecurityInsightsTestRunner + { + protected readonly ITestRunner TestRunner; + + protected SecurityInsightsTestRunner(ITestOutputHelper output) + { + TestRunner = TestManager.CreateInstance(output) + .WithNewPsScriptFilename($"{GetType().Name}.ps1") + .WithProjectSubfolderForTests("ScenarioTests") + .WithCommonPsScripts(new[] + { + @"Common.ps1", + @"../AzureRM.Resources.ps1", + @"../AzureRM.Storage.ps1" + }) + .WithNewRmModules(helper => new[] + { + helper.RMProfileModule, + helper.GetRMModulePath("Az.SecurityInsights.psd1") + }) + .WithNewRecordMatcherArguments( + userAgentsToIgnore: new Dictionary + { + {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"} + }, + resourceProviders: new Dictionary + { + {"Microsoft.Resources", null}, + {"Microsoft.Features", null}, + {"Microsoft.Authorization", null}, + {"Microsoft.Compute", null} + } + ) + .Build(); + } + } +} \ No newline at end of file diff --git a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/TestController.cs b/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/TestController.cs deleted file mode 100644 index 20d001a7e242..000000000000 --- a/src/SecurityInsights/SecurityInsights.Test/ScenarioTests/TestController.cs +++ /dev/null @@ -1,136 +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 System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Microsoft.Azure.Commands.Common.Authentication; -using Microsoft.Azure.Management.SecurityInsights; -using Microsoft.Azure.Management.Storage.Version2017_10_01; -using Microsoft.Azure.Test.HttpRecorder; -using Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; -using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory; -using Microsoft.Azure.Management.Internal.Resources; -using Microsoft.Azure.Commands.TestFx; - -namespace Microsoft.Azure.Commands.SecurityInsights.Test.ScenarioTests -{ - /// - /// Setup for Scenario Tests - /// - public class TestController : RMTestBase - { - private readonly EnvironmentSetupHelper _helper; - - public ResourceManagementClient ResourceManagementClient { get; private set; } - - public SecurityInsightsClient SecurityInsightsClient { get; private set; } - - public StorageManagementClient StorageManagementClient { get; private set; } - - public static TestController NewInstance => new TestController(); - - protected TestController() - { - _helper = new EnvironmentSetupHelper(); - } - - protected void SetupManagementClients(MockContext context) - { - ResourceManagementClient = context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - SecurityInsightsClient = context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - StorageManagementClient = context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - - _helper.SetupManagementClients( - ResourceManagementClient, - StorageManagementClient, - SecurityInsightsClient); - } - - /// - /// Methods for invoking PowerShell scripts - /// - /// - /// - 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; - RunPsTestWorkflow( - () => scripts, - // no custom cleanup - null, - callingClassType, - mockName); - } - - private void RunPsTestWorkflow( - Func scriptBuilder, - Action cleanup, - string callingClassType, - string mockName) - { - - var d = new Dictionary - { - {"Microsoft.Resources", null}, - {"Microsoft.Features", null}, - {"Microsoft.Authorization", null}, - {"Microsoft.Compute", null} - }; - var providersToIgnore = new Dictionary - { - {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"} - }; - HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, 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, - "ScenarioTests\\Common.ps1", - "ScenarioTests\\" + callingClassName + ".ps1", - _helper.RMProfileModule, - _helper.GetRMModulePath("AzureRM.SecurityInsights.psd1"), - "AzureRM.Resources.ps1", - "AzureRM.Storage.ps1"); - try - { - var psScripts = scriptBuilder?.Invoke(); - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - finally - { - cleanup?.Invoke(); - } - } - } - } -} \ No newline at end of file