diff --git a/src/ManagementPartner/ManagementPartner.Test/ScenarioTests/ManagementPartnerTestRunner.cs b/src/ManagementPartner/ManagementPartner.Test/ScenarioTests/ManagementPartnerTestRunner.cs new file mode 100644 index 000000000000..5d88f9bf5915 --- /dev/null +++ b/src/ManagementPartner/ManagementPartner.Test/ScenarioTests/ManagementPartnerTestRunner.cs @@ -0,0 +1,50 @@ +// ---------------------------------------------------------------------------------- +// +// 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.ManagementPartner.Test.ScenarioTests +{ + public class ManagementPartnerTestRunner + { + protected readonly ITestRunner TestRunner; + + protected ManagementPartnerTestRunner(ITestOutputHelper output) + { + TestRunner = TestManager.CreateInstance(output) + .WithNewPsScriptFilename($"{GetType().Name}.ps1") + .WithProjectSubfolderForTests("ScenarioTests") + .WithNewRmModules(helper => new[] + { + helper.RMProfileModule, + helper.GetRMModulePath("Az.ManagementPartner.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} + } + ) + .Build(); + } + } +} \ No newline at end of file diff --git a/src/ManagementPartner/ManagementPartner.Test/ScenarioTests/ManagementPartnerTests.cs b/src/ManagementPartner/ManagementPartner.Test/ScenarioTests/ManagementPartnerTests.cs index 06e9b455c0cd..6afa50fa744b 100644 --- a/src/ManagementPartner/ManagementPartner.Test/ScenarioTests/ManagementPartnerTests.cs +++ b/src/ManagementPartner/ManagementPartner.Test/ScenarioTests/ManagementPartnerTests.cs @@ -12,58 +12,51 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; -using Microsoft.Azure.Commands.ManagementPartner; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; using Xunit.Abstractions; namespace Microsoft.Azure.Commands.ManagementPartner.Test.ScenarioTests { - public class ManagementPartnerTests : RMTestBase + public class ManagementPartnerTests : ManagementPartnerTestRunner { - public XunitTracingInterceptor _logger; - - public ManagementPartnerTests(Xunit.Abstractions.ITestOutputHelper output) + public ManagementPartnerTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetPartner() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetPartner"); + TestRunner.RunTestScript("Test-GetPartner"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetPartnerNoParnterId() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetPartnerNoPartnerId"); + TestRunner.RunTestScript("Test-GetPartnerNoPartnerId"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewParnter() { - TestController.NewInstance.RunPsTest(_logger, "Test-NewPartner"); + TestRunner.RunTestScript("Test-NewPartner"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestUpdateParnter() { - TestController.NewInstance.RunPsTest(_logger, "Test-UpdatePartner"); + TestRunner.RunTestScript("Test-UpdatePartner"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveParnter() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemovePartner"); + TestRunner.RunTestScript("Test-RemovePartner"); } } } diff --git a/src/ManagementPartner/ManagementPartner.Test/TestController.cs b/src/ManagementPartner/ManagementPartner.Test/TestController.cs deleted file mode 100644 index 16c172ac4f6e..000000000000 --- a/src/ManagementPartner/ManagementPartner.Test/TestController.cs +++ /dev/null @@ -1,116 +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.ManagementPartner; -using Microsoft.Azure.Test.HttpRecorder; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.IO; -using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.Azure.ServiceManagement.Common.Models; - -namespace Microsoft.Azure.Commands.ManagementPartner.Test.ScenarioTests -{ - public class TestController - { - private readonly EnvironmentSetupHelper _helper; - - public ACEProvisioningManagementPartnerAPIClient ACEProvisioningManagementPartnerAPIClient { get; private set; } - - public static TestController NewInstance => new TestController(); - - public TestController() - { - _helper = new EnvironmentSetupHelper(); - } - - public void RunPsTest(XunitTracingInterceptor traceInterceptor, params string[] scripts) - { - _helper.TracingInterceptor = traceInterceptor; - var sf = new StackTrace().GetFrame(1); - var callingClassType = sf.GetMethod().ReflectedType?.ToString(); - var mockName = sf.GetMethod().Name; - - RunPsTestWorkflow( - () => scripts, - // no custom cleanup - null, - callingClassType, - mockName); - } - - public void RunPsTestWorkflow( - Func scriptBuilder, - Action cleanup, - string callingClassType, - string mockName) - { - var d = new Dictionary - { - {"Microsoft.Resources", null}, - {"Microsoft.Features", null}, - {"Microsoft.Authorization", 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 = RestTestFramework.MockContext.Start(callingClassType, mockName)) - { - SetupManagementClients(context); - - _helper.SetupEnvironment(AzureModule.AzureResourceManager); - - var callingClassName = callingClassType.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last(); - _helper.SetupModules(AzureModule.AzureResourceManager, - "ScenarioTests\\" + callingClassName + ".ps1", - _helper.RMProfileModule, - _helper.GetRMModulePath("AzureRM.ManagementPartner.psd1") - ); - - try - { - var psScripts = scriptBuilder?.Invoke(); - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - finally - { - cleanup?.Invoke(); - } - } - } - - private void SetupManagementClients(RestTestFramework.MockContext context) - { - ACEProvisioningManagementPartnerAPIClient = GetACEProvisioningGSMAPIClient(context); - - _helper.SetupManagementClients(ACEProvisioningManagementPartnerAPIClient); - } - - private static ACEProvisioningManagementPartnerAPIClient GetACEProvisioningGSMAPIClient(RestTestFramework.MockContext context) - { - return context.GetServiceClient(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment()); - } - } -}