From 31cb35a88a365b3f09418481c351e0d83de8d5e3 Mon Sep 17 00:00:00 2001 From: Yufan Yang <95342181+CaptainFanZzz@users.noreply.github.com> Date: Tue, 7 Jun 2022 19:22:38 +0800 Subject: [PATCH] Edit ServiceBusTestRunner and remove TestController (#18404) * Edit ServiceBusTestRunner and remove TestController * remove RecordMatcher * Remove unnecessary module Co-authored-by: Ziyue Zheng --- .../ScenarioTests/NetworkRuleSet.cs | 13 +- .../ScenarioTests/ServiceBusController.cs | 131 ------------------ .../ServiceBusDRConfigurations.cs | 14 +- .../ServiceBusMigrationConfigurationTests.cs | 12 +- .../ServiceBusPaginationTests.cs | 13 +- .../ScenarioTests/ServiceBusQueueTests.cs | 15 +- .../ScenarioTests/ServiceBusRuleTests.cs | 13 +- .../ScenarioTests/ServiceBusServiceTests.cs | 3 - .../ServiceBusSubscriptionTests.cs | 13 +- .../ScenarioTests/ServiceBusTestRunner.cs | 23 +-- .../ScenarioTests/ServiceBusTopicTests.cs | 15 +- 11 files changed, 40 insertions(+), 225 deletions(-) delete mode 100644 src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusController.cs diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/NetworkRuleSet.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/NetworkRuleSet.cs index 01e5e3666ccc..cd445b45cdf8 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/NetworkRuleSet.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/NetworkRuleSet.cs @@ -14,26 +14,21 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { + using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; - public class NetworkRuleSetTests : RMTestBase + public class NetworkRuleSetTests : ServiceBusTestRunner { - public XunitTracingInterceptor _logger; - - public NetworkRuleSetTests(ITestOutputHelper output) + public NetworkRuleSetTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void NetworkRuleSetCRUD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "NetworkRuleSetTests"); + TestRunner.RunTestScript("NetworkRuleSetTests"); } } } diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusController.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusController.cs deleted file mode 100644 index a1bb21c1e445..000000000000 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusController.cs +++ /dev/null @@ -1,131 +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.ServiceBus; -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.Management.Internal.Resources; -using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory; -using Microsoft.Azure.ServiceManagement.Common.Models; - -namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests -{ - public class ServiceBusController - { - private readonly EnvironmentSetupHelper _helper; - - public ResourceManagementClient ResourceManagementClient { get; private set; } - - public ServiceBusManagementClient ServiceBusManagementClient { get; private set; } - - public string UserDomain { get; private set; } - - public static ServiceBusController NewInstance => new ServiceBusController(); - - - public ServiceBusController() - { - _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, - "ScenarioTests\\" + callingClassName + ".ps1", - _helper.RMProfileModule, - _helper.GetRMModulePath(@"AzureRM.ServiceBus.psd1"), - _helper.GetRMModulePath(@"AzureRM.KeyVault.psd1"), - _helper.GetRMModulePath(@"AzureRM.ManagedServiceIdentity.psd1"), - "AzureRM.Resources.ps1"); - try - { - var psScripts = scriptBuilder?.Invoke(); - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - finally - { - cleanup?.Invoke(); - } - } - } - - private void SetupManagementClients(MockContext context) - { - ResourceManagementClient = GetResourceManagementClient(context); - ServiceBusManagementClient = GetServiceBusManagementClient(context); - _helper.SetupManagementClients(ResourceManagementClient, ServiceBusManagementClient); - } - - private static ResourceManagementClient GetResourceManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static ServiceBusManagementClient GetServiceBusManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - } -} diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusDRConfigurations.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusDRConfigurations.cs index 3563de8c4759..aee1fe128351 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusDRConfigurations.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusDRConfigurations.cs @@ -14,27 +14,21 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { + using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceBus; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; - public class ServiceBusDRConfigurationTests : RMTestBase + public class ServiceBusDRConfigurationTests : ServiceBusTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceBusDRConfigurationTests(ITestOutputHelper output) + public ServiceBusDRConfigurationTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusDRConfigurationsCURD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusDRConfigurationTests"); + TestRunner.RunTestScript("ServiceBusDRConfigurationTests"); } } } diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusMigrationConfigurationTests.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusMigrationConfigurationTests.cs index fe2ca0026728..f77f3ac841a1 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusMigrationConfigurationTests.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusMigrationConfigurationTests.cs @@ -14,26 +14,22 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { + using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; - public class ServiceBusMigrationConfigurationTests : RMTestBase + public class ServiceBusMigrationConfigurationTests : ServiceBusTestRunner { - public XunitTracingInterceptor _logger; - public ServiceBusMigrationConfigurationTests(ITestOutputHelper output) + public ServiceBusMigrationConfigurationTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusMigrationConfigurationsCURD() { - ServiceBusController.NewInstance.RunPsTest(_logger,"ServiceBusMigrationConfigurationTests"); + TestRunner.RunTestScript("ServiceBusMigrationConfigurationTests"); } } } diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusPaginationTests.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusPaginationTests.cs index 99b54b5600d1..74b254952384 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusPaginationTests.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusPaginationTests.cs @@ -14,26 +14,21 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { + using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; - public class ServiceBusPaginationTests : RMTestBase + public class ServiceBusPaginationTests : ServiceBusTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceBusPaginationTests(ITestOutputHelper output) + public ServiceBusPaginationTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusPaginationTests_CURD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusPaginationTests"); + TestRunner.RunTestScript("ServiceBusPaginationTests"); } } } diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusQueueTests.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusQueueTests.cs index 5d2930b66eab..c7878105b2e5 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusQueueTests.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusQueueTests.cs @@ -14,33 +14,28 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { + using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; - public class ServiceBusQueueTests : RMTestBase + public class ServiceBusQueueTests : ServiceBusTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceBusQueueTests(ITestOutputHelper output) + public ServiceBusQueueTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusQueue_CURD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusQueueTests"); + TestRunner.RunTestScript("ServiceBusQueueTests"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusQueueAuth_CURD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusQueueAuthTests"); + TestRunner.RunTestScript("ServiceBusQueueAuthTests"); } } } diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusRuleTests.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusRuleTests.cs index b63d458540bd..b3ea20d1fb2b 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusRuleTests.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusRuleTests.cs @@ -14,26 +14,21 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { + using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; - public class ServiceBusRuleTests : RMTestBase + public class ServiceBusRuleTests : ServiceBusTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceBusRuleTests(ITestOutputHelper output) + public ServiceBusRuleTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusRule_CURD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusRuleTests"); + TestRunner.RunTestScript("ServiceBusRuleTests"); } } } diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.cs index 155e79318d7e..8400a28bf31f 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.cs @@ -16,15 +16,12 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; public class ServiceBusServiceTests : ServiceBusTestRunner { public ServiceBusServiceTests(ITestOutputHelper output) : base(output) { - } [Fact] diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusSubscriptionTests.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusSubscriptionTests.cs index ec6c3c1bc703..7ffeffd8a018 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusSubscriptionTests.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusSubscriptionTests.cs @@ -14,26 +14,21 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { + using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; - public class ServiceBusSubscriptionTests : RMTestBase + public class ServiceBusSubscriptionTests : ServiceBusTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceBusSubscriptionTests(ITestOutputHelper output) + public ServiceBusSubscriptionTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusSubscription_CURD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusSubscriptionTests"); + TestRunner.RunTestScript("ServiceBusSubscriptionTests"); } } } diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTestRunner.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTestRunner.cs index 21472690db2d..b065c645d149 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTestRunner.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTestRunner.cs @@ -30,36 +30,25 @@ protected ServiceBusTestRunner(ITestOutputHelper output) .WithProjectSubfolderForTests("ScenarioTests") .WithCommonPsScripts(new[] { - @"../AzureRM.Resources.ps1", - @"../AzureRM.Storage.ps1" + @"../AzureRM.Resources.ps1" }) .WithNewRmModules(helper => new[] - { + { helper.RMProfileModule, - helper.GetRMModulePath("AzureRM.ServiceBus.psd1"), - helper.GetRMModulePath("AzureRM.KeyVault.psd1"), - helper.GetRMModulePath("AzureRM.ManagedServiceIdentity.psd1"), - + helper.GetRMModulePath("Az.ServiceBus.psd1"), + helper.GetRMModulePath("Az.KeyVault.psd1") }) - .WithRecordMatcher( - (ignoreResourcesClient, resourceProviders, userAgentsToIgnore) => - new PermissiveRecordMatcherWithApiExclusion(ignoreResourcesClient, resourceProviders, userAgentsToIgnore) - ) .WithNewRecordMatcherArguments( userAgentsToIgnore: new Dictionary { - {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"}, - {"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2017-05-10"}, - {"Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient", "2016-09-01"}, + {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"} }, resourceProviders: new Dictionary { {"Microsoft.Resources", null}, {"Microsoft.Features", null}, {"Microsoft.Authorization", null}, - {"Microsoft.ServiceBus", null}, - {"Microsoft.KeyVault", null}, - {"Microsoft.ManagedServiceIdentity", null}, + {"Microsoft.KeyVault", null} } ) .Build(); diff --git a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTopicTests.cs b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTopicTests.cs index de57006bbee9..189949d25918 100644 --- a/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTopicTests.cs +++ b/src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusTopicTests.cs @@ -14,33 +14,28 @@ namespace Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests { + using Microsoft.Azure.Commands.EventHub.Test.ScenarioTests; using Microsoft.WindowsAzure.Commands.ScenarioTest; - using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; - using ServiceManagement.Common.Models; using Xunit; using Xunit.Abstractions; - public class ServiceBusTopicTests : RMTestBase + public class ServiceBusTopicTests : ServiceBusTestRunner { - public XunitTracingInterceptor _logger; - - public ServiceBusTopicTests(ITestOutputHelper output) + public ServiceBusTopicTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusTopic_CURD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusTopicTests"); + TestRunner.RunTestScript("ServiceBusTopicTests"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void ServiceBusTopicAuth_CURD() { - ServiceBusController.NewInstance.RunPsTest(_logger, "ServiceBusTopicAuthTests"); + TestRunner.RunTestScript("ServiceBusTopicAuthTests"); } } }