diff --git a/src/AnalysisServices/AnalysisServices.Test/InMemoryTests/DataPlaneCommandTests.cs b/src/AnalysisServices/AnalysisServices.Test/InMemoryTests/DataPlaneCommandTests.cs index e9777b2745d8..493f5b704571 100644 --- a/src/AnalysisServices/AnalysisServices.Test/InMemoryTests/DataPlaneCommandTests.cs +++ b/src/AnalysisServices/AnalysisServices.Test/InMemoryTests/DataPlaneCommandTests.cs @@ -21,7 +21,6 @@ using System.Threading.Tasks; using Microsoft.Azure.Commands.AnalysisServices.Dataplane; using Microsoft.Azure.Commands.AnalysisServices.Dataplane.Models; -using Microsoft.Azure.Commands.AnalysisServices.Test.ScenarioTests; using Microsoft.Azure.Commands.Profile.Models.Core; using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; @@ -31,12 +30,12 @@ using Xunit.Abstractions; using System.Collections.Generic; using System.Net.Http.Headers; -using Newtonsoft.Json; using Microsoft.Azure.Commands.Common.Authentication.Abstractions; +using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; namespace Microsoft.Azure.Commands.AnalysisServices.Test.InMemoryTests { - public class DataPlaneCommandTests : AsTestsBase + public class DataPlaneCommandTests : RMTestBase { private const string testInstance = "asazure://westcentralus.asazure.windows.net/testserver"; diff --git a/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AnalysisServicesTestRunner.cs b/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AnalysisServicesTestRunner.cs new file mode 100644 index 000000000000..cc7d9d2dacfb --- /dev/null +++ b/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AnalysisServicesTestRunner.cs @@ -0,0 +1,55 @@ +// ---------------------------------------------------------------------------------- +// +// 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.AnalysisServices.Test.ScenarioTests +{ + public class AnalysisServicesTestRunner + { + protected readonly ITestRunner TestRunner; + + protected AnalysisServicesTestRunner(ITestOutputHelper output) + { + TestRunner = TestManager.CreateInstance(output) + .WithNewPsScriptFilename($"{GetType().Name}.ps1") + .WithProjectSubfolderForTests("ScenarioTests") + .WithCommonPsScripts(new[] + { + @"Common.ps1", + @"../AzureRM.Resources.ps1" + }) + .WithNewRmModules(helper => new[] + { + helper.RMProfileModule, + helper.GetRMModulePath("Az.AnalysisServices.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(); + } + } +} diff --git a/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AsTests.cs b/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AsTests.cs index 808606968270..e35a624abfb8 100644 --- a/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AsTests.cs +++ b/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AsTests.cs @@ -18,91 +18,87 @@ namespace Microsoft.Azure.Commands.AnalysisServices.Test.ScenarioTests using ServiceManagement.Common.Models; using Xunit; - public class AsTests : AsTestsBase + public class AsTests : AnalysisServicesTestRunner { - public XunitTracingInterceptor _logger; - - public AsTests(Xunit.Abstractions.ITestOutputHelper output) + public AsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAnalysisServicesServer() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServer"); + TestRunner.RunTestScript("Test-AnalysisServicesServer"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAnalysisServicesServerScaleUpDown() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerScaleUpDown"); + TestRunner.RunTestScript("Test-AnalysisServicesServerScaleUpDown"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAnalysisServicesServerScaleOutIn() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerScaleOutIn"); + TestRunner.RunTestScript("Test-AnalysisServicesServerScaleOutIn"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAnalysisServicesServerFirewall() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerFirewall"); + TestRunner.RunTestScript("Test-AnalysisServicesServerFirewall"); } [Fact] [Trait(Category.RunType, Category.LiveOnly)] public void TestAnalysisServicesServerDisableBackup() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerDisableBackup"); + TestRunner.RunTestScript("Test-AnalysisServicesServerDisableBackup"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNegativeAnalysisServicesServer() { - NewInstance.RunPsTest(_logger, "Test-NegativeAnalysisServicesServer"); + TestRunner.RunTestScript("Test-NegativeAnalysisServicesServer"); } [Fact] [Trait(Category.RunType, Category.LiveOnly)] public void TestAnalysisServicesServerLogExport() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerLogExport"); + TestRunner.RunTestScript("Test-AnalysisServicesServerLogExport"); } [Fact] [Trait(Category.RunType, Category.LiveOnly)] public void TestAnalysisServicesServerRestart() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerRestart"); + TestRunner.RunTestScript("Test-AnalysisServicesServerRestart"); } [Fact] [Trait(Category.RunType, Category.LiveOnly)] public void TestAnalysisServicesServerSynchronizeSingle() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerSynchronizeSingle"); + TestRunner.RunTestScript("Test-AnalysisServicesServerSynchronizeSingle"); } [Fact] [Trait(Category.RunType, Category.LiveOnly)] public void TestAnalysisServicesServerLoginWithSPN() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerLoginWithSPN"); + TestRunner.RunTestScript("Test-AnalysisServicesServerLoginWithSPN"); } [Fact] [Trait(Category.RunType, Category.LiveOnly)] public void TestAnalysisServicesServerGateway() { - NewInstance.RunPsTest(_logger, "Test-AnalysisServicesServerGateway"); + TestRunner.RunTestScript("Test-AnalysisServicesServerGateway"); } } diff --git a/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AsTestsBase.cs b/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AsTestsBase.cs deleted file mode 100644 index c959ebe2f661..000000000000 --- a/src/AnalysisServices/AnalysisServices.Test/ScenarioTests/AsTestsBase.cs +++ /dev/null @@ -1,141 +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.Analysis; -using Microsoft.Azure.Test.HttpRecorder; -using Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory; -using NewResourceManagementClient = Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; -using System.IO; -using Microsoft.Azure.ServiceManagement.Common.Models; - -namespace Microsoft.Azure.Commands.AnalysisServices.Test.ScenarioTests -{ - public class AsTestsBase : RMTestBase - { - private readonly EnvironmentSetupHelper _helper; - - public NewResourceManagementClient NewResourceManagementClient { get; private set; } - - public AnalysisServicesManagementClient AnalysisServicesManagementClient { get; private set; } - - public static AsTestsBase NewInstance => new AsTestsBase(); - - - public AsTestsBase() - { - _helper = new EnvironmentSetupHelper(); - } - - public void RunPsTest(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, - 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 = 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.AnalysisServices.psd1"), -#if !NETSTANDARD - _helper.GetRMModulePath(@"Azure.AnalysisServices.psd1"), -#endif - "AzureRM.Resources.ps1"); - - try - { - var psScripts = scriptBuilder?.Invoke(); - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - finally - { - cleanup?.Invoke(); - } - } - } - - private void SetupManagementClients(MockContext context) - { - AnalysisServicesManagementClient = GetAnalysisServicesManagementClient(context); - NewResourceManagementClient = GetNewResourceManagementClient(context); - _helper.SetupManagementClients(NewResourceManagementClient, - AnalysisServicesManagementClient); - } - - private static NewResourceManagementClient GetNewResourceManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static AnalysisServicesManagementClient GetAnalysisServicesManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static void ThrowIfTrue(bool condition, string message) - { - if (condition) - { - throw new Exception(message); - } - } - } -}