diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightAutoscaleTests.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightAutoscaleTests.cs index 10aa095c119c..3100b53bc9eb 100644 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightAutoscaleTests.cs +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightAutoscaleTests.cs @@ -12,31 +12,24 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.Azure.Commands.HDInsight.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using System.Collections.Generic; -using System.Text; using Xunit; using Xunit.Abstractions; namespace Commands.HDInsight.Test.ScenarioTests { - public class HDInsightAutoscaleTests : TestController + public class HDInsightAutoscaleTests : HDInsightTestRunner { - public XunitTracingInterceptor _logger; - - public HDInsightAutoscaleTests(ITestOutputHelper output) + public HDInsightAutoscaleTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAutoscaleRelatedCommands() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-AutoscaleRelatedCommands"); + TestRunner.RunTestScript("Test-AutoscaleRelatedCommands"); } } } diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightAzureMonitorTests.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightAzureMonitorTests.cs index fc6c992ae877..e99001ff3ddf 100644 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightAzureMonitorTests.cs +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightAzureMonitorTests.cs @@ -12,24 +12,17 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.Azure.Commands.HDInsight.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using System.Collections.Generic; -using System.Text; using Xunit; using Xunit.Abstractions; namespace Commands.HDInsight.Test.ScenarioTests { - public class HDInsightAzureMonitorTests + public class HDInsightAzureMonitorTests : HDInsightTestRunner { - public XunitTracingInterceptor _logger; - - public HDInsightAzureMonitorTests(ITestOutputHelper output) + public HDInsightAzureMonitorTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } //[Fact(Skip = "test case cannot be re-recorded properly, need help from service team")] @@ -37,7 +30,7 @@ public HDInsightAzureMonitorTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAzureMonitorRelatedCommands() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureMonitorRelatedCommands"); + TestRunner.RunTestScript("Test-AzureMonitorRelatedCommands"); } } } diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightClusterTests.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightClusterTests.cs index 72ec10e3d664..cca8515411b5 100644 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightClusterTests.cs +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightClusterTests.cs @@ -12,105 +12,101 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.Azure.Commands.HDInsight.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; namespace Commands.HDInsight.Test.ScenarioTests { - public class HDInsightClusterTests : TestController + public class HDInsightClusterTests : HDInsightTestRunner { - public XunitTracingInterceptor _logger; - - public HDInsightClusterTests(ITestOutputHelper output) + public HDInsightClusterTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestClusterRelatedCommands() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-ClusterRelatedCommands"); + TestRunner.RunTestScript("Test-ClusterRelatedCommands"); } [Fact(Skip = "Sikp this")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCmkClusterRelatedCommands() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CmkClusterRelatedCommands"); + TestRunner.RunTestScript("Test-CmkClusterRelatedCommands"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithEncryptionInTransit() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithEncryptionInTransit"); + TestRunner.RunTestScript("Test-CreateClusterWithEncryptionInTransit"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithEncryptionAtHost() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithEncryptionAtHost"); + TestRunner.RunTestScript("Test-CreateClusterWithEncryptionAtHost"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithLoadBasedAutoscale() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithLoadBasedAutoscale"); + TestRunner.RunTestScript("Test-CreateClusterWithLoadBasedAutoscale"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithScheduleBasedAutoscale() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithScheduleBasedAutoscale"); + TestRunner.RunTestScript("Test-CreateClusterWithScheduleBasedAutoscale"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithKafkaRestProxy() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithKafkaRestProxy"); + TestRunner.RunTestScript("Test-CreateClusterWithKafkaRestProxy"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithRelayOutoundAndPrivateLink() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithRelayOutoundAndPrivateLink"); + TestRunner.RunTestScript("Test-CreateClusterWithRelayOutoundAndPrivateLink"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithCustomAmbariDatabase() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithCustomAmbariDatabase"); + TestRunner.RunTestScript("Test-CreateClusterWithCustomAmbariDatabase"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithComputeIsolation() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithComputeIsolation"); + TestRunner.RunTestScript("Test-CreateClusterWithComputeIsolation"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithAvailabilityZones() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithAvailabilityZones"); + TestRunner.RunTestScript("Test-CreateClusterWithAvailabilityZones"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateClusterWithPrivateLinkConfiguration() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateClusterWithPrivateLinkConfiguration"); + TestRunner.RunTestScript("Test-CreateClusterWithPrivateLinkConfiguration"); } } } diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightConfigurationTests.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightConfigurationTests.cs index 791d5d09ae2c..59c2bf1b5b90 100644 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightConfigurationTests.cs +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightConfigurationTests.cs @@ -12,29 +12,24 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Commands.HDInsight.Test.ScenarioTests; -using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.Azure.Commands.HDInsight.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; namespace Commands.HDInsight.Test.ScenarioTests { - public class HDInsightConfigurationTests + public class HDInsightConfigurationTests : HDInsightTestRunner { - public XunitTracingInterceptor _logger; - - public HDInsightConfigurationTests(ITestOutputHelper output) + public HDInsightConfigurationTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact(Skip = "Test requires setting env variable, TODO remove that constraint")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestConfigurationPipelining() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-ConfigurationPipelining"); + TestRunner.RunTestScript("Test-ConfigurationPipelining"); } } } diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightHostTests.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightHostTests.cs index 2c3afb855eb5..a6f4cda40f9f 100644 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightHostTests.cs +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightHostTests.cs @@ -12,28 +12,24 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.Azure.Commands.HDInsight.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; namespace Commands.HDInsight.Test.ScenarioTests { - public class HDInsightHostTests : TestController + public class HDInsightHostTests : HDInsightTestRunner { - public XunitTracingInterceptor _logger; - - public HDInsightHostTests(ITestOutputHelper output) + public HDInsightHostTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestHostRelatedCommands() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-HostRelatedCommands"); + TestRunner.RunTestScript("Test-HostRelatedCommands"); } } } diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightMonitoringTests.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightMonitoringTests.cs index 32c62d1932be..2ba80b534112 100644 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightMonitoringTests.cs +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightMonitoringTests.cs @@ -12,31 +12,24 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.Azure.Commands.HDInsight.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using System.Collections.Generic; -using System.Text; using Xunit; using Xunit.Abstractions; namespace Commands.HDInsight.Test.ScenarioTests { - public class HDInsightMonitoringTests + public class HDInsightMonitoringTests : HDInsightTestRunner { - public XunitTracingInterceptor _logger; - - public HDInsightMonitoringTests(ITestOutputHelper output) + public HDInsightMonitoringTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact(Skip = "test case cannot be re-recorded properly, need help from service team")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestMonitoringRelatedCommands() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-MonitoringRelatedCommands"); + TestRunner.RunTestScript("Test-MonitoringRelatedCommands"); } } } diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightScriptActionTests.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightScriptActionTests.cs index 898873bf331c..64e4f4568c8c 100644 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightScriptActionTests.cs +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightScriptActionTests.cs @@ -12,31 +12,24 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.Azure.Commands.HDInsight.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using System.Collections.Generic; -using System.Text; using Xunit; using Xunit.Abstractions; namespace Commands.HDInsight.Test.ScenarioTests { - public class HDInsightScriptActionTests + public class HDInsightScriptActionTests : HDInsightTestRunner { - public XunitTracingInterceptor _logger; - - public HDInsightScriptActionTests(ITestOutputHelper output) + public HDInsightScriptActionTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact(Skip="test case cannot be re-recorded properly, need help from service team")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestScriptActionRelatedCommands() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-ScriptActionRelatedCommands"); + TestRunner.RunTestScript("Test-ScriptActionRelatedCommands"); } } } diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightSetGatewayCredentialTest.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightSetGatewayCredentialTest.cs index 441b99edee92..97b7f39c47f7 100644 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightSetGatewayCredentialTest.cs +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightSetGatewayCredentialTest.cs @@ -12,28 +12,24 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.Azure.Commands.HDInsight.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; namespace Commands.HDInsight.Test.ScenarioTests { - public class HDInsightSetGatewayCredentialTest + public class HDInsightSetGatewayCredentialTest : HDInsightTestRunner { - public XunitTracingInterceptor _logger; - - public HDInsightSetGatewayCredentialTest(ITestOutputHelper output) + public HDInsightSetGatewayCredentialTest(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetGatewayCredential() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-SetGatewayCredential"); + TestRunner.RunTestScript("Test-SetGatewayCredential"); } } } diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightTestRunner.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightTestRunner.cs new file mode 100644 index 000000000000..6b7197b8e337 --- /dev/null +++ b/src/HDInsight/HDInsight.Test/ScenarioTests/HDInsightTestRunner.cs @@ -0,0 +1,60 @@ +// ---------------------------------------------------------------------------------- +// +// 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.HDInsight.Test.ScenarioTests +{ + public class HDInsightTestRunner + { + protected readonly ITestRunner TestRunner; + + protected HDInsightTestRunner(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.HDInsight.psd1"), + helper.GetRMModulePath("Az.OperationalInsights.psd1"), + helper.GetRMModulePath("Az.ManagedServiceIdentity.psd1") + }) + .WithNewRecordMatcherArguments( + userAgentsToIgnore: new Dictionary + { + {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"} + }, + resourceProviders: new Dictionary + { + {"Microsoft.Resources", null}, + {"Microsoft.Features", null}, + {"Microsoft.Network", null}, + {"Microsoft.Authorization", null}, + {"Microsoft.OperationalInsights", null} + } + ) + .Build(); + } + } +} \ No newline at end of file diff --git a/src/HDInsight/HDInsight.Test/ScenarioTests/TestController.cs b/src/HDInsight/HDInsight.Test/ScenarioTests/TestController.cs deleted file mode 100644 index 7d7a3f3745b9..000000000000 --- a/src/HDInsight/HDInsight.Test/ScenarioTests/TestController.cs +++ /dev/null @@ -1,194 +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.HDInsight; -using Microsoft.Azure.Management.Internal.Resources; -using Microsoft.Azure.Management.OperationalInsights; -using Microsoft.Azure.Management.ManagedServiceIdentity; -using Microsoft.Azure.Management.KeyVault; -using Microsoft.Azure.Management.Storage.Version2017_10_01; -using Microsoft.Azure.ServiceManagement.Common.Models; -using Microsoft.Azure.Test.HttpRecorder; -using Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; -using Microsoft.Azure.KeyVault; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Microsoft.Azure.Management.Network; -using Microsoft.Azure.Commands.Common.MSGraph.Version1_0; - -namespace Commands.HDInsight.Test.ScenarioTests -{ - public class TestController : RMTestBase - { - private readonly EnvironmentSetupHelper _helper; - - public ResourceManagementClient ResourceManagementClient { get; private set; } - public HDInsightManagementClient HDInsightManagementClient { get; private set; } - public StorageManagementClient StorageManagementClient { get; private set; } - public OperationalInsightsManagementClient OperationalInsightsManagementClient { get; private set; } - public KeyVaultManagementClient KeyVaultManagementClient { get; private set; } - public KeyVaultClient KeyVaultClient { get; private set; } - public ManagedServiceIdentityClient ManagedServiceIdentityClient { get; private set; } - public NetworkManagementClient NetworkManagementClient { get; private set; } - - public MicrosoftGraphClient GraphManagementClient { get; private set; } - - public static TestHelper TestHelper { get; private set; } - public static TestController NewInstance => new TestController(); - - protected TestController() - { - _helper = new EnvironmentSetupHelper(); - } - - protected void SetupManagementClient(MockContext context) - { - ResourceManagementClient = GetResourceManagementClient(context); - HDInsightManagementClient = GetHDInsightManagementClient(context); - StorageManagementClient = GetStorageManagementClient(context); - OperationalInsightsManagementClient = GetOperationalInsightsManagementClient(context); - KeyVaultManagementClient = GetKeyVaultManagementClient(context); - ManagedServiceIdentityClient = GetManagedServiceIdentityClient(context); - NetworkManagementClient = GetNetworkManagementClient(context); - GraphManagementClient = GetGraphManagementClient(context); - _helper.SetupManagementClients(ResourceManagementClient, HDInsightManagementClient, StorageManagementClient, OperationalInsightsManagementClient, KeyVaultManagementClient, ManagedServiceIdentityClient, NetworkManagementClient, GraphManagementClient); - } - - public void RunPowerShellTest(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); - } - - public void RunPsTestWorkFlow(Func scriptBuilder, System.Action cleanup, string callingClassType, string mockName) - { - var d = new Dictionary - { - {"Microsoft.Resources", null}, - {"Microsoft.Features", null}, - {"Microsoft.Network", null}, - {"Microsoft.Authorization", null}, - {"Microsoft.OperationalInsights", null} - }; - - var providerToIgnore = new Dictionary - { - {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"} - }; - - HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providerToIgnore); - HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords"); - - using (var context = MockContext.Start(callingClassType, mockName)) - { - SetupManagementClient(context); - _helper.SetupEnvironment(AzureModule.AzureResourceManager); - KeyVaultClient = GetKeyVaultClient(); - TestHelper = GetTestHelper(); - - var callingClassName = callingClassType.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last(); - - _helper.SetupModules(AzureModule.AzureResourceManager, - "ScenarioTests\\Common.ps1", - "ScenarioTests\\" + callingClassName + ".ps1", - _helper.RMProfileModule, - _helper.GetRMModulePath(@"AzureRM.HDInsight.psd1"), - _helper.GetRMModulePath("AzureRM.OperationalInsights.psd1"), - _helper.GetRMModulePath("AzureRM.ManagedServiceIdentity.psd1"), - _helper.RMKeyVaultModule, - "AzureRM.Storage.ps1", - "AzureRM.Resources.ps1"); - try - { - var psScripts = scriptBuilder?.Invoke(); - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - finally - { - cleanup?.Invoke(); - } - } - } - - protected ResourceManagementClient GetResourceManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static HDInsightManagementClient GetHDInsightManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static StorageManagementClient GetStorageManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static OperationalInsightsManagementClient GetOperationalInsightsManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static KeyVaultManagementClient GetKeyVaultManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static KeyVaultClient GetKeyVaultClient() - { - return new KeyVaultClient(TestHelper.GetAccessToken, TestHelper.GetHandlers()); - } - - private static ManagedServiceIdentityClient GetManagedServiceIdentityClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static NetworkManagementClient GetNetworkManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static MicrosoftGraphClient GetGraphManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private TestHelper GetTestHelper() - { - return new TestHelper(KeyVaultManagementClient, KeyVaultClient, NetworkManagementClient); - } - } -}