diff --git a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricApplicationTests.cs b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricApplicationTests.cs index 30597c583537..a02d7a95331b 100644 --- a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricApplicationTests.cs +++ b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricApplicationTests.cs @@ -13,24 +13,17 @@ // ---------------------------------------------------------------------------------- using Microsoft.Azure.Commands.ServiceFabric.Commands; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; using Xunit.Abstractions; namespace Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests { - public class ServiceFabricApplicationTests : RMTestBase + public class ServiceFabricApplicationTests : ServiceFabricTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceFabricApplicationTests(ITestOutputHelper output) + public ServiceFabricApplicationTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - - ServiceFabricManagedCmdletBase.WriteVerboseIntervalInSec = 0; + ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0; ServiceFabricCmdletBase.RunningTest = true; } @@ -38,28 +31,28 @@ public ServiceFabricApplicationTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAppType() { - TestController.NewInstance.RunPsTest(_logger, "Test-AppType"); + TestRunner.RunTestScript("Test-AppType"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAppTypeVersion() { - TestController.NewInstance.RunPsTest(_logger, "Test-AppTypeVersion"); + TestRunner.RunTestScript("Test-AppTypeVersion"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestApp() { - TestController.NewInstance.RunPsTest(_logger, "Test-App"); + TestRunner.RunTestScript("Test-App"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestService() { - TestController.NewInstance.RunPsTest(_logger, "Test-Service"); + TestRunner.RunTestScript("Test-Service"); } } } diff --git a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersApplicationTests.cs b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersApplicationTests.cs index d932963b7ca0..ceecaacedc46 100644 --- a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersApplicationTests.cs +++ b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersApplicationTests.cs @@ -13,23 +13,16 @@ // ---------------------------------------------------------------------------------- using Microsoft.Azure.Commands.ServiceFabric.Commands; -using Microsoft.Azure.ServiceManagement.Common.Models; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; +using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; namespace Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests { - public class ServiceFabricManagedClustersApplicationTests : RMTestBase + public class ServiceFabricManagedClustersApplicationTests : ServiceFabricTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceFabricManagedClustersApplicationTests(ITestOutputHelper output) + public ServiceFabricManagedClustersApplicationTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0; ServiceFabricCmdletBase.RunningTest = true; } @@ -38,28 +31,28 @@ public ServiceFabricManagedClustersApplicationTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestManagedAppType() { - TestController.NewInstance.RunPsTest(_logger, "Test-ManagedAppType"); + TestRunner.RunTestScript("Test-ManagedAppType"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestManagedAppTypeVersion() { - TestController.NewInstance.RunPsTest(_logger, "Test-ManagedAppTypeVersion"); + TestRunner.RunTestScript("Test-ManagedAppTypeVersion"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestManagedApp() { - TestController.NewInstance.RunPsTest(_logger, "Test-ManagedApp"); + TestRunner.RunTestScript("Test-ManagedApp"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestManagedService() { - TestController.NewInstance.RunPsTest(_logger, "Test-ManagedService"); + TestRunner.RunTestScript("Test-ManagedService"); } } } diff --git a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersTests.cs b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersTests.cs index 5ca351f0b601..6f210c8f4754 100644 --- a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersTests.cs +++ b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricManagedClustersTests.cs @@ -13,23 +13,16 @@ // ---------------------------------------------------------------------------------- using Microsoft.Azure.Commands.ServiceFabric.Commands; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; using Xunit.Abstractions; namespace Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests { - public class ServiceFabricManagedClustersTests : RMTestBase + public class ServiceFabricManagedClustersTests : ServiceFabricTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceFabricManagedClustersTests(ITestOutputHelper output) + public ServiceFabricManagedClustersTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0; ServiceFabricCmdletBase.RunningTest = true; } @@ -38,21 +31,21 @@ public ServiceFabricManagedClustersTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCreateBasicCluster() { - TestController.NewInstance.RunPsTest(_logger, "Test-CreateBasicCluster"); + TestRunner.RunTestScript("Test-CreateBasicCluster"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNodeTypeOperations() { - TestController.NewInstance.RunPsTest(_logger, "Test-NodeTypeOperations"); + TestRunner.RunTestScript("Test-NodeTypeOperations"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCertAndExtension() { - TestController.NewInstance.RunPsTest(_logger, "Test-CertAndExtension"); + TestRunner.RunTestScript("Test-CertAndExtension"); } } } diff --git a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricTestRunner.cs b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricTestRunner.cs new file mode 100644 index 000000000000..17104687332f --- /dev/null +++ b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/ServiceFabricTestRunner.cs @@ -0,0 +1,56 @@ +// ---------------------------------------------------------------------------------- +// +// 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.ServiceFabric.Test.ScenarioTests +{ + public class ServiceFabricTestRunner + { + protected readonly ITestRunner TestRunner; + + protected ServiceFabricTestRunner(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.ServiceFabric.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.KeyVault", null} + } + ) + .Build(); + } + } +} \ No newline at end of file diff --git a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestController.cs b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestController.cs deleted file mode 100644 index 70d74e968d30..000000000000 --- a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestController.cs +++ /dev/null @@ -1,193 +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.Test.HttpRecorder; -using Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Microsoft.Azure.Commands.Common.Compute.Version_2018_04; -using Microsoft.Azure.Commands.Common.KeyVault.Version2016_10_1; -using Microsoft.Azure.Commands.ServiceFabric.Commands; -using Microsoft.Azure.Management.Internal.Network.Version2017_10_01; -using Microsoft.Azure.Management.Internal.Resources; -using Microsoft.Azure.Management.ServiceFabric; -using Microsoft.Azure.Management.ServiceFabricManagedClusters; -using Microsoft.Azure.Management.Storage.Version2017_10_01; -using Microsoft.Azure.ServiceManagement.Common.Models; - -namespace Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests -{ - public class TestController - { - private readonly EnvironmentSetupHelper _helper; - - public ResourceManagementClient NewResourceManagementClient { get; private set; } - - public ServiceFabricManagementClient ServiceFabricClient { get; private set; } - - public ServiceFabricManagedClustersManagementClient ServiceFabricManagedClustersClient { get; private set; } - - public ComputeManagementClient ComputeManagementClient { get; private set; } - - public KeyVaultManagementClient KeyVaultManagementClient { get; private set; } - - public StorageManagementClient StorageManagementClient { get; private set; } - - public NetworkManagementClient NetworkManagementClient { get; private set; } - - public static TestController NewInstance => new TestController(); - - public TestController() - { - _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}, - {"Microsoft.KeyVault", 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, - _helper.RMProfileModule, - "ScenarioTests\\Common.ps1", - "ScenarioTests\\" + callingClassName + ".ps1", - "AzureRM.Resources.ps1", - _helper.GetRMModulePath("AzureRM.ServiceFabric.psd1")); - - try - { - var psScripts = scriptBuilder?.Invoke(); - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - finally - { - ServiceFabricCmdletBase.TestAppCert = false; - cleanup?.Invoke(); - } - } - } - - private void SetupManagementClients(MockContext context) - { - ServiceFabricClient = GetServiceFabricManagementClient(context); - if (HttpMockServer.Mode == HttpRecorderMode.Record) - { - ServiceFabricClient.LongRunningOperationRetryTimeout = 20; - } - - ServiceFabricManagedClustersClient = GetServiceFabricManagedClustersManagementClient(context); - if (HttpMockServer.Mode == HttpRecorderMode.Record) - { - ServiceFabricManagedClustersClient.LongRunningOperationRetryTimeout = 20; - } - - ComputeManagementClient = GetComputeManagementClient(context); - KeyVaultManagementClient = GetKeyVaultManagementClient(context); - StorageManagementClient = GetStorageManagementClient(context); - NetworkManagementClient = GetNetworkManagementClient(context); - NewResourceManagementClient = GetNewResourceManagementClient(context); - - _helper.SetupManagementClients( - ServiceFabricClient, - ServiceFabricManagedClustersClient, - ComputeManagementClient, - KeyVaultManagementClient, - StorageManagementClient, - NetworkManagementClient, - NewResourceManagementClient); - } - - private static ServiceFabricManagementClient GetServiceFabricManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static ServiceFabricManagedClustersManagementClient GetServiceFabricManagedClustersManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static ComputeManagementClient GetComputeManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static KeyVaultManagementClient GetKeyVaultManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static StorageManagementClient GetStorageManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static NetworkManagementClient GetNetworkManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static ResourceManagementClient GetNewResourceManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - } -} \ No newline at end of file diff --git a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestServiceFabric.cs b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestServiceFabric.cs index 2f38c388de67..5f12bcc27130 100644 --- a/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestServiceFabric.cs +++ b/src/ServiceFabric/ServiceFabric.Test/ScenarioTests/TestServiceFabric.cs @@ -16,25 +16,17 @@ using System.IO; using Microsoft.Azure.Commands.ServiceFabric.Commands; using Microsoft.Azure.Commands.ServiceFabric.Common; -using Microsoft.Azure.ServiceManagement.Common.Models; -using Microsoft.WindowsAzure.Commands.Common; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; using Xunit.Abstractions; namespace Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests { [TestCaseOrderer("Microsoft.Azure.Commands.ServiceFabric.Test.ScenarioTests.PriorityOrderer", "Microsoft.Azure.Commands.ServiceFabric.Test")] - public class TestServiceFabric : RMTestBase + public class TestServiceFabric : ServiceFabricTestRunner { - public XunitTracingInterceptor _logger; - - public TestServiceFabric(ITestOutputHelper output) + public TestServiceFabric(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); - AddAzureRmServiceFabricNodeType.dontRandom = true; ServiceFabricCommonCmdletBase.WriteVerboseIntervalInSec = 0; ServiceFabricCmdletBase.RunningTest = true; @@ -51,84 +43,84 @@ public TestServiceFabric(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestUpdateAzureRmServiceFabricDurability() { - TestController.NewInstance.RunPsTest(_logger, "Test-UpdateAzureRmServiceFabricDurability"); + TestRunner.RunTestScript("Test-UpdateAzureRmServiceFabricDurability"); } [Fact, TestPriority(0)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestUpdateAzureRmServiceFabricReliability() { - TestController.NewInstance.RunPsTest(_logger, "Test-UpdateAzureRmServiceFabricReliability"); + TestRunner.RunTestScript("Test-UpdateAzureRmServiceFabricReliability"); } [Fact, TestPriority(0)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmServiceFabricUpgradeType() { - TestController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmServiceFabricUpgradeType"); + TestRunner.RunTestScript("Test-SetAzureRmServiceFabricUpgradeType"); } [Fact, TestPriority(0)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmServiceFabricSettings() { - TestController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmServiceFabricSettings"); + TestRunner.RunTestScript("Test-SetAzureRmServiceFabricSettings"); } [Fact, TestPriority(1)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveAzureRmServiceFabricSettings() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveAzureRmServiceFabricSettings"); + TestRunner.RunTestScript("Test-RemoveAzureRmServiceFabricSettings"); } [Fact, TestPriority(0)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmServiceFabricClientCertificate() { - TestController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmServiceFabricClientCertificate"); + TestRunner.RunTestScript("Test-AddAzureRmServiceFabricClientCertificate"); } [Fact, TestPriority(1)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveAzureRmServiceFabricClientCertificate() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveAzureRmServiceFabricClientCertificate"); + TestRunner.RunTestScript("Test-RemoveAzureRmServiceFabricClientCertificate"); } [Fact, TestPriority(0)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewAzureRmServiceFabricCluster() { - TestController.NewInstance.RunPsTest(_logger, "Test-NewAzureRmServiceFabricCluster"); + TestRunner.RunTestScript("Test-NewAzureRmServiceFabricCluster"); } [Fact, TestPriority(0)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewAzureRmServiceFabricClusterCNCert() { - TestController.NewInstance.RunPsTest(_logger, "Test-NewAzureRmServiceFabricClusterCNCert"); + TestRunner.RunTestScript("Test-NewAzureRmServiceFabricClusterCNCert"); } [Fact, TestPriority(4)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmServiceFabricNode() { - TestController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmServiceFabricNode"); + TestRunner.RunTestScript("Test-AddAzureRmServiceFabricNode"); } [Fact, TestPriority(5)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveAzureRmServiceFabricNode() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveAzureRmServiceFabricNode"); + TestRunner.RunTestScript("Test-RemoveAzureRmServiceFabricNode"); } [Fact, TestPriority(2)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmServiceFabricNodeType() { - TestController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmServiceFabricNodeType"); + TestRunner.RunTestScript("Test-AddAzureRmServiceFabricNodeType"); } [Fact, TestPriority(6)] @@ -136,14 +128,14 @@ public void TestAddAzureRmServiceFabricNodeType() [Trait("Re-record", "ClientRuntime changes")] public void TestRemoveAzureRmServiceFabricNodeType() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveAzureRmServiceFabricNodeType"); + TestRunner.RunTestScript("Test-RemoveAzureRmServiceFabricNodeType"); } [Fact, TestPriority(0)] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestUpdateAzureRmServiceFabricVmImage() { - TestController.NewInstance.RunPsTest(_logger, "Test-UpdateAzureRmServiceFabricVmImage"); + TestRunner.RunTestScript("Test-UpdateAzureRmServiceFabricVmImage"); } [Fact, TestPriority(0)]