From 5c48e524e0c9d9ce5a23efd59aab8201cffe6605 Mon Sep 17 00:00:00 2001 From: Ziyue Zheng Date: Thu, 26 May 2022 13:01:53 +0800 Subject: [PATCH 1/2] Add StorageSyncTestRunner to replace TestController --- .../ScenarioTests/CloudEndpointTests.cs | 30 +-- .../ScenarioTests/RegisteredServerTests.cs | 37 ++-- .../ScenarioTests/ServerEndpointTests.cs | 13 +- .../ScenarioTests/StorageSyncServiceTests.cs | 25 +-- .../StorageSyncTestRunner.cs} | 189 ++++++++---------- .../ScenarioTests/StorageSyncTests.cs | 14 +- .../ScenarioTests/SyncGroupTests.cs | 29 +-- 7 files changed, 138 insertions(+), 199 deletions(-) rename src/StorageSync/StorageSync.Test/{TestController.cs => ScenarioTests/StorageSyncTestRunner.cs} (53%) diff --git a/src/StorageSync/StorageSync.Test/ScenarioTests/CloudEndpointTests.cs b/src/StorageSync/StorageSync.Test/ScenarioTests/CloudEndpointTests.cs index 7dcf2e21282c..2f8ff34a6aa2 100644 --- a/src/StorageSync/StorageSync.Test/ScenarioTests/CloudEndpointTests.cs +++ b/src/StorageSync/StorageSync.Test/ScenarioTests/CloudEndpointTests.cs @@ -14,7 +14,6 @@ using ScenarioTests; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; @@ -24,21 +23,14 @@ namespace StorageSyncTests /// /// Class CloudEndpointTests. /// - public class CloudEndpointTests + public class CloudEndpointTests : StorageSyncTestRunner { - /// - /// The logger - /// - private readonly XunitTracingInterceptor _logger; - /// /// Initializes a new instance of the class. /// /// The output. - public CloudEndpointTests(ITestOutputHelper output) + public CloudEndpointTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } /// @@ -48,7 +40,7 @@ public CloudEndpointTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCloudEndpoint() { - TestController.NewInstance.RunPsTest(_logger, "Test-CloudEndpoint"); + TestRunner.RunTestScript("Test-CloudEndpoint"); } /// @@ -58,7 +50,7 @@ public void TestCloudEndpoint() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewCloudEndpoint() { - TestController.NewInstance.RunPsTest(_logger, "Test-NewCloudEndpoint"); + TestRunner.RunTestScript("Test-NewCloudEndpoint"); } /// @@ -68,7 +60,7 @@ public void TestNewCloudEndpoint() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetCloudEndpoint() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetCloudEndpoint"); + TestRunner.RunTestScript("Test-GetCloudEndpoint"); } /// @@ -78,7 +70,7 @@ public void TestGetCloudEndpoint() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetCloudEndpointParentObject() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetCloudEndpointParentObject"); + TestRunner.RunTestScript("Test-GetCloudEndpointParentObject"); } /// @@ -88,7 +80,7 @@ public void TestGetCloudEndpointParentObject() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetCloudEndpointParentResourceId() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetCloudEndpointParentResourceId"); + TestRunner.RunTestScript("Test-GetCloudEndpointParentResourceId"); } @@ -99,7 +91,7 @@ public void TestGetCloudEndpointParentResourceId() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetCloudEndpoints() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetCloudEndpoints"); + TestRunner.RunTestScript("Test-GetCloudEndpoints"); } /// @@ -109,7 +101,7 @@ public void TestGetCloudEndpoints() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveCloudEndpoint() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveCloudEndpoint"); + TestRunner.RunTestScript("Test-RemoveCloudEndpoint"); } /// @@ -119,7 +111,7 @@ public void TestRemoveCloudEndpoint() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveCloudEndpointResourceId() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveCloudEndpointResourceId"); + TestRunner.RunTestScript("Test-RemoveCloudEndpointResourceId"); } /// @@ -129,7 +121,7 @@ public void TestRemoveCloudEndpointResourceId() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveCloudEndpointInputObject() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveCloudEndpointInputObject"); + TestRunner.RunTestScript("Test-RemoveCloudEndpointInputObject"); } } diff --git a/src/StorageSync/StorageSync.Test/ScenarioTests/RegisteredServerTests.cs b/src/StorageSync/StorageSync.Test/ScenarioTests/RegisteredServerTests.cs index bda20bde854e..f9f9717dcae3 100644 --- a/src/StorageSync/StorageSync.Test/ScenarioTests/RegisteredServerTests.cs +++ b/src/StorageSync/StorageSync.Test/ScenarioTests/RegisteredServerTests.cs @@ -13,7 +13,6 @@ // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.Azure.Test.HttpRecorder; using Microsoft.WindowsAzure.Commands.ScenarioTest; using ScenarioTests; @@ -25,20 +24,14 @@ namespace StorageSyncTests /// /// Class RegisteredServerTests. /// - public class RegisteredServerTests + public class RegisteredServerTests : StorageSyncTestRunner { - /// - /// The logger - /// - private readonly XunitTracingInterceptor _logger; - /// /// Initializes a new instance of the class. /// /// The output. - public RegisteredServerTests(ITestOutputHelper output) + public RegisteredServerTests(ITestOutputHelper output) : base(output) { - XunitTracingInterceptor.AddToContext(_logger = new XunitTracingInterceptor(output)); } /// @@ -48,7 +41,7 @@ public RegisteredServerTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRegisteredServer() { - TestController.NewInstance.RunPsTest(_logger, "Test-RegisteredServer"); + TestRunner.RunTestScript("Test-RegisteredServer"); } /// @@ -58,7 +51,7 @@ public void TestRegisteredServer() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRegisteredServerPipeline1() { - TestController.NewInstance.RunPsTest(_logger, "Test-RegisteredServerPipeline1"); + TestRunner.RunTestScript("Test-RegisteredServerPipeline1"); } /// @@ -68,7 +61,7 @@ public void TestRegisteredServerPipeline1() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRegisteredServerPipeline2() { - TestController.NewInstance.RunPsTest(_logger, "Test-RegisteredServerPipeline2"); + TestRunner.RunTestScript("Test-RegisteredServerPipeline2"); } /// @@ -79,7 +72,7 @@ public void TestRegisteredServerPipeline2() public void TestNewRegisteredServer() { var value = HttpMockServer.GetCurrentMode(); - TestController.NewInstance.RunPsTest(_logger, "Test-NewRegisteredServer"); + TestRunner.RunTestScript("Test-NewRegisteredServer"); } /// @@ -89,7 +82,7 @@ public void TestNewRegisteredServer() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewRegisteredServerParentObject() { - TestController.NewInstance.RunPsTest(_logger, "Test-NewRegisteredServerParentObject"); + TestRunner.RunTestScript("Test-NewRegisteredServerParentObject"); } /// @@ -99,7 +92,7 @@ public void TestNewRegisteredServerParentObject() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewRegisteredServerParentResourceId() { - TestController.NewInstance.RunPsTest(_logger, "Test-NewRegisteredServerParentResourceId"); + TestRunner.RunTestScript("Test-NewRegisteredServerParentResourceId"); } /// @@ -109,7 +102,7 @@ public void TestNewRegisteredServerParentResourceId() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetRegisteredServer() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetRegisteredServer"); + TestRunner.RunTestScript("Test-GetRegisteredServer"); } /// @@ -119,7 +112,7 @@ public void TestGetRegisteredServer() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetRegisteredServerParentObject() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetRegisteredServerParentObject"); + TestRunner.RunTestScript("Test-GetRegisteredServerParentObject"); } /// @@ -129,7 +122,7 @@ public void TestGetRegisteredServerParentObject() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetRegisteredServerParentResourceId() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetRegisteredServerParentResourceId"); + TestRunner.RunTestScript("Test-GetRegisteredServerParentResourceId"); } /// @@ -139,7 +132,7 @@ public void TestGetRegisteredServerParentResourceId() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetRegisteredServers() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetRegisteredServers"); + TestRunner.RunTestScript("Test-GetRegisteredServers"); } /// @@ -149,7 +142,7 @@ public void TestGetRegisteredServers() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveRegisteredServer() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveRegisteredServer"); + TestRunner.RunTestScript("Test-RemoveRegisteredServer"); } /// @@ -159,7 +152,7 @@ public void TestRemoveRegisteredServer() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveRegisteredServerResourceId() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveRegisteredServerResourceId"); + TestRunner.RunTestScript("Test-RemoveRegisteredServerResourceId"); } /// @@ -169,7 +162,7 @@ public void TestRemoveRegisteredServerResourceId() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveRegisteredServerInputObject() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveRegisteredServerInputObject"); + TestRunner.RunTestScript("Test-RemoveRegisteredServerInputObject"); } } } diff --git a/src/StorageSync/StorageSync.Test/ScenarioTests/ServerEndpointTests.cs b/src/StorageSync/StorageSync.Test/ScenarioTests/ServerEndpointTests.cs index 910b557c0f60..a58ecf03ee9c 100644 --- a/src/StorageSync/StorageSync.Test/ScenarioTests/ServerEndpointTests.cs +++ b/src/StorageSync/StorageSync.Test/ScenarioTests/ServerEndpointTests.cs @@ -14,7 +14,6 @@ using ScenarioTests; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; @@ -24,20 +23,14 @@ namespace StorageSyncTests /// /// Class ServerEndpointTests. /// - public class ServerEndpointTests + public class ServerEndpointTests : StorageSyncTestRunner { - /// - /// The logger - /// - private readonly XunitTracingInterceptor _logger; - /// /// Initializes a new instance of the class. /// /// The output. - public ServerEndpointTests(ITestOutputHelper output) + public ServerEndpointTests(ITestOutputHelper output) : base(output) { - XunitTracingInterceptor.AddToContext(_logger = new XunitTracingInterceptor(output)); } /// @@ -47,7 +40,7 @@ public ServerEndpointTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestServerEndpoint() { - TestController.NewInstance.RunPsTest(_logger, "Test-ServerEndpoint"); + TestRunner.RunTestScript("Test-ServerEndpoint"); } } diff --git a/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncServiceTests.cs b/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncServiceTests.cs index 4dd9fe500e40..5fc067d4e3fd 100644 --- a/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncServiceTests.cs +++ b/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncServiceTests.cs @@ -14,7 +14,6 @@ using ScenarioTests; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; @@ -24,20 +23,14 @@ namespace StorageSyncTests /// /// Class StorageSyncServiceTests. /// - public class StorageSyncServiceTests + public class StorageSyncServiceTests : StorageSyncTestRunner { - /// - /// The logger - /// - private readonly XunitTracingInterceptor _logger; - /// /// Initializes a new instance of the class. /// /// The output. - public StorageSyncServiceTests(ITestOutputHelper output) + public StorageSyncServiceTests(ITestOutputHelper output) : base(output) { - XunitTracingInterceptor.AddToContext(_logger = new XunitTracingInterceptor(output)); } /// @@ -47,7 +40,7 @@ public StorageSyncServiceTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestStorageSyncService() { - TestController.NewInstance.RunPsTest(_logger, "Test-StorageSyncService"); + TestRunner.RunTestScript("Test-StorageSyncService"); } /// @@ -57,7 +50,7 @@ public void TestStorageSyncService() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewStorageSyncService() { - TestController.NewInstance.RunPsTest(_logger, "Test-NewStorageSyncService"); + TestRunner.RunTestScript("Test-NewStorageSyncService"); } /// @@ -67,7 +60,7 @@ public void TestNewStorageSyncService() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetStorageSyncService() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetStorageSyncService"); + TestRunner.RunTestScript("Test-GetStorageSyncService"); } /// @@ -77,7 +70,7 @@ public void TestGetStorageSyncService() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetStorageSyncServices() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetStorageSyncServices"); + TestRunner.RunTestScript("Test-GetStorageSyncServices"); } /// @@ -87,7 +80,7 @@ public void TestGetStorageSyncServices() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveStorageSyncService() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveStorageSyncService"); + TestRunner.RunTestScript("Test-RemoveStorageSyncService"); } /// @@ -97,7 +90,7 @@ public void TestRemoveStorageSyncService() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveStorageSyncServiceInputObject() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveStorageSyncServiceInputObject"); + TestRunner.RunTestScript("Test-RemoveStorageSyncServiceInputObject"); } /// @@ -107,7 +100,7 @@ public void TestRemoveStorageSyncServiceInputObject() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveStorageSyncServiceResourceId() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveStorageSyncServiceResourceId"); + TestRunner.RunTestScript("Test-RemoveStorageSyncServiceResourceId"); } } diff --git a/src/StorageSync/StorageSync.Test/TestController.cs b/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTestRunner.cs similarity index 53% rename from src/StorageSync/StorageSync.Test/TestController.cs rename to src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTestRunner.cs index 6fcddd79d4a5..2ed3e2767d97 100644 --- a/src/StorageSync/StorageSync.Test/TestController.cs +++ b/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTestRunner.cs @@ -33,15 +33,19 @@ using System.Diagnostics; using System.IO; using System.Linq; +using Microsoft.Azure.Commands.TestFx; +using Microsoft.Azure.Internal.Common; +using Microsoft.Azure.KeyVault; +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using Microsoft.Rest; +using Xunit.Abstractions; namespace ScenarioTests { /// - /// Class TestController. - /// Implements the + /// Class StorageSyncTestRunner. /// - /// - public class TestController : RMTestBase + public class StorageSyncTestRunner { /// /// The tenant identifier key @@ -62,132 +66,101 @@ public class TestController : RMTestBase /// The user domain. public string UserDomain { get; private set; } - /// - /// The helper - /// - private readonly EnvironmentSetupHelper _helper; + protected readonly ITestRunner TestRunner; - /// - /// Creates new instance. - /// - /// The new instance. - public static TestController NewInstance => new TestController(); + protected StorageSyncTestRunner(ITestOutputHelper output) + { + TestRunner = TestManager.CreateInstance(output) + .WithNewPsScriptFilename($"{GetType().Name}.ps1") + .WithProjectSubfolderForTests("ScenarioTests") + .WithCommonPsScripts(new[] + { + @"Common.ps1", + @"../AzureRM.Storage.ps1", + @"../AzureRM.Resources.ps1" + }) + .WithNewRmModules(helper => new[] + { + helper.RMProfileModule, + helper.RMStorageModule, + helper.GetRMModulePath("Az.StorageSync.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.Storage", null}, + {"Microsoft.StorageSync", null} + } + ).WithMockContextAction(() => + { + var sf = new StackTrace().GetFrame(2); + var callingClassType = sf.GetMethod().ReflectedType?.ToString(); + var testName = sf.GetMethod().Name; + + using (var context = MockContext.Start(callingClassType, testName)) + { + RegisterComponents(context, testName); + } + } + ) + .Build(); + } /// - /// Initializes a new instance of the class. + /// Registers the components. /// - public TestController() + /// The context. + /// Name of the test. + private void RegisterComponents(MockContext context, string testName) { - _helper = new EnvironmentSetupHelper(); + AzureSession.Instance.RegisterComponent(StorageSyncConstants.StorageSyncResourceManager, () => new MockStorageSyncResourceManager(testName), overwrite: true); } /// - /// Runs the ps test. + /// Gets the resource management client. /// - /// The logger. - /// The scripts. - public void RunPsTest(XunitTracingInterceptor logger, params string[] scripts) + /// The context. + /// ResourceManagementClient. + private ResourceManagementClient GetRMClient(MockContext context) { - 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); + return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); } /// - /// Runs the ps test workflow. + /// Gets the subscription client. /// - /// The script builder. - /// The cleanup. - /// Type of the calling class. - /// Name of the test. - public void RunPsTestWorkflow( - Func scriptBuilder, - Action cleanup, - string callingClassType, - string testName) + /// The context. + /// SubscriptionClient. + private SubscriptionClient GetSubClient(MockContext context) { - var d = new Dictionary - { - {"Microsoft.Resources", null}, - {"Microsoft.Features", null}, - {"Microsoft.Authorization", null}, - {"Microsoft.Storage", null}, - {"Microsoft.StorageSync", 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, testName)) - { - RegisterComponents(context,testName); - SetupManagementClients(context); - - _helper.SetupEnvironment(AzureModule.AzureResourceManager); - - var callingClassName = callingClassType.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last(); - _helper.SetupModules(AzureModule.AzureResourceManager, - _helper.RMProfileModule, - _helper.GetRMModulePath("AzureRM.StorageSync.psd1"), - "ScenarioTests\\Common.ps1", - "ScenarioTests\\" + callingClassName + ".ps1", - "AzureRM.Storage.ps1", - "AzureRM.Resources.ps1", - _helper.RMStorageModule); - - try - { - if (scriptBuilder == null) return; - - var psScripts = scriptBuilder(); - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - finally - { - cleanup?.Invoke(); - } - } + return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); } /// - /// Registers the components. + /// Gets the storage sync management client. /// /// The context. - /// Name of the test. - private void RegisterComponents(MockContext context, string testName) + /// StorageSyncManagementClient. + private StorageSyncManagementClient GetStorageSyncClient(MockContext context) { - AzureSession.Instance.RegisterComponent(StorageSyncConstants.StorageSyncResourceManager, () => new MockStorageSyncResourceManager(testName), overwrite: true); + return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); } /// - /// Setups the management clients. + /// Gets the storage management client. /// /// The context. - private void SetupManagementClients(MockContext context) + /// StorageManagementClient. + private StorageManagementClient GetStorageClient(MockContext context) { - var rmClient = context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - var subClient = context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - var storageSyncClient = context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - var storageClient = context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - MicrosoftGraphClient microsoftGraphClient = GetGraphClient(context); - var authClient = context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - _helper.SetupManagementClients(rmClient, subClient, storageSyncClient, storageClient, microsoftGraphClient, authClient); + return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); } /// @@ -235,5 +208,15 @@ private MicrosoftGraphClient GetGraphClient(MockContext context) } return client; } + + /// + /// Gets the authorization management client. + /// + /// The context. + /// AuthorizationManagementClient. + private AuthorizationManagementClient GetAuthClient(MockContext context) + { + return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); + } } } \ No newline at end of file diff --git a/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTests.cs b/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTests.cs index 3453c38dcc93..095944a7ae63 100644 --- a/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTests.cs +++ b/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTests.cs @@ -13,7 +13,6 @@ // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; @@ -23,21 +22,14 @@ namespace ScenarioTests /// /// Class StorageSyncTests. /// - public class StorageSyncTests + public class StorageSyncTests : StorageSyncTestRunner { - /// - /// The logger - /// - private readonly XunitTracingInterceptor _logger; - /// /// Initializes a new instance of the class. /// /// The output. - public StorageSyncTests(ITestOutputHelper output) + public StorageSyncTests(ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } /// @@ -47,7 +39,7 @@ public StorageSyncTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestStorageSync() { - TestController.NewInstance.RunPsTest(_logger, "Test-StorageSync"); + TestRunner.RunTestScript("Test-StorageSync"); } } } diff --git a/src/StorageSync/StorageSync.Test/ScenarioTests/SyncGroupTests.cs b/src/StorageSync/StorageSync.Test/ScenarioTests/SyncGroupTests.cs index 1f57708797d8..c82befcd702b 100644 --- a/src/StorageSync/StorageSync.Test/ScenarioTests/SyncGroupTests.cs +++ b/src/StorageSync/StorageSync.Test/ScenarioTests/SyncGroupTests.cs @@ -14,7 +14,6 @@ using ScenarioTests; -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; using Xunit; using Xunit.Abstractions; @@ -24,20 +23,14 @@ namespace StorageSyncTests /// /// Class SyncGroupTests. /// - public class SyncGroupTests + public class SyncGroupTests : StorageSyncTestRunner { - /// - /// The logger - /// - private readonly XunitTracingInterceptor _logger; - /// /// Initializes a new instance of the class. /// /// The output. - public SyncGroupTests(ITestOutputHelper output) + public SyncGroupTests(ITestOutputHelper output) : base(output) { - XunitTracingInterceptor.AddToContext(_logger = new XunitTracingInterceptor(output)); } /// @@ -47,7 +40,7 @@ public SyncGroupTests(ITestOutputHelper output) [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSyncGroup() { - TestController.NewInstance.RunPsTest(_logger, "Test-SyncGroup"); + TestRunner.RunTestScript("Test-SyncGroup"); } /// @@ -57,7 +50,7 @@ public void TestSyncGroup() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewSyncGroup() { - TestController.NewInstance.RunPsTest(_logger, "Test-NewSyncGroup"); + TestRunner.RunTestScript("Test-NewSyncGroup"); } /// @@ -67,7 +60,7 @@ public void TestNewSyncGroup() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetSyncGroup() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetSyncGroup"); + TestRunner.RunTestScript("Test-GetSyncGroup"); } /// @@ -77,7 +70,7 @@ public void TestGetSyncGroup() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetSyncGroupParentObject() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetSyncGroupParentObject"); + TestRunner.RunTestScript("Test-GetSyncGroupParentObject"); } /// @@ -87,7 +80,7 @@ public void TestGetSyncGroupParentObject() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetSyncGroupParentResourceId() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetSyncGroupParentResourceId"); + TestRunner.RunTestScript("Test-GetSyncGroupParentResourceId"); } @@ -98,7 +91,7 @@ public void TestGetSyncGroupParentResourceId() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetSyncGroups() { - TestController.NewInstance.RunPsTest(_logger, "Test-GetSyncGroups"); + TestRunner.RunTestScript("Test-GetSyncGroups"); } /// @@ -108,7 +101,7 @@ public void TestGetSyncGroups() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveSyncGroup() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveSyncGroup"); + TestRunner.RunTestScript("Test-RemoveSyncGroup"); } /// @@ -118,7 +111,7 @@ public void TestRemoveSyncGroup() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveSyncGroupResourceId() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveSyncGroupResourceId"); + TestRunner.RunTestScript("Test-RemoveSyncGroupResourceId"); } /// @@ -128,7 +121,7 @@ public void TestRemoveSyncGroupResourceId() [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveSyncGroupInputObject() { - TestController.NewInstance.RunPsTest(_logger, "Test-RemoveSyncGroupInputObject"); + TestRunner.RunTestScript("Test-RemoveSyncGroupInputObject"); } } From 4295c31876553098bb6115410dd626ac31d5f79b Mon Sep 17 00:00:00 2001 From: Ziyue Zheng Date: Thu, 26 May 2022 13:58:24 +0800 Subject: [PATCH 2/2] Add StorageSyncTestRunner to replace TestController --- .../ScenarioTests/StorageSyncTestRunner.cs | 127 ------------------ 1 file changed, 127 deletions(-) diff --git a/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTestRunner.cs b/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTestRunner.cs index 2ed3e2767d97..f01c9adb4b91 100644 --- a/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTestRunner.cs +++ b/src/StorageSync/StorageSync.Test/ScenarioTests/StorageSyncTestRunner.cs @@ -13,31 +13,13 @@ // ---------------------------------------------------------------------------------- using Microsoft.Azure.Commands.Common.Authentication; -using Microsoft.Azure.Commands.Common.Authentication.Abstractions; -using Microsoft.Azure.Commands.Common.MSGraph.Version1_0; using Microsoft.Azure.Commands.StorageSync.Common; using Microsoft.Azure.Commands.StorageSync.Interfaces; -using Microsoft.Azure.Management.Authorization.Version2015_07_01; -using Microsoft.Azure.Management.Internal.Resources; -using Microsoft.Azure.Management.ResourceManager.Version2021_01_01; -using Microsoft.Azure.Management.Storage.Version2017_10_01; -using Microsoft.Azure.Management.StorageSync; -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 StorageSync.Test.Common; -using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Linq; using Microsoft.Azure.Commands.TestFx; -using Microsoft.Azure.Internal.Common; -using Microsoft.Azure.KeyVault; -using Microsoft.IdentityModel.Clients.ActiveDirectory; -using Microsoft.Rest; using Xunit.Abstractions; namespace ScenarioTests @@ -47,19 +29,6 @@ namespace ScenarioTests /// public class StorageSyncTestRunner { - /// - /// The tenant identifier key - /// - private const string TenantIdKey = StorageSyncConstants.TenantId; - /// - /// The domain key - /// - private const string DomainKey = "Domain"; - /// - /// The subscription identifier key - /// - private const string SubscriptionIdKey = "SubscriptionId"; - /// /// Gets the user domain. /// @@ -122,101 +91,5 @@ private void RegisterComponents(MockContext context, string testName) { AzureSession.Instance.RegisterComponent(StorageSyncConstants.StorageSyncResourceManager, () => new MockStorageSyncResourceManager(testName), overwrite: true); } - - /// - /// Gets the resource management client. - /// - /// The context. - /// ResourceManagementClient. - private ResourceManagementClient GetRMClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - /// - /// Gets the subscription client. - /// - /// The context. - /// SubscriptionClient. - private SubscriptionClient GetSubClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - /// - /// Gets the storage sync management client. - /// - /// The context. - /// StorageSyncManagementClient. - private StorageSyncManagementClient GetStorageSyncClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - /// - /// Gets the storage management client. - /// - /// The context. - /// StorageManagementClient. - private StorageManagementClient GetStorageClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - /// - /// Gets the graph client. - /// - /// The context. - /// MicrosoftGraphClient. - private MicrosoftGraphClient GetGraphClient(MockContext context) - { - var environment = TestEnvironmentFactory.GetTestEnvironment(); - string tenantId = null; - - if (HttpMockServer.Mode == HttpRecorderMode.Record) - { - tenantId = environment.Tenant; - UserDomain = String.IsNullOrEmpty(environment.UserName) ? String.Empty : environment.UserName.Split(new[] { "@" }, StringSplitOptions.RemoveEmptyEntries).Last(); - - HttpMockServer.Variables[TenantIdKey] = tenantId; - HttpMockServer.Variables[DomainKey] = UserDomain; - } - else if (HttpMockServer.Mode == HttpRecorderMode.Playback) - { - if (HttpMockServer.Variables.ContainsKey(TenantIdKey)) - { - tenantId = HttpMockServer.Variables[TenantIdKey]; - } - if (HttpMockServer.Variables.ContainsKey(DomainKey)) - { - UserDomain = HttpMockServer.Variables[DomainKey]; - } - if (HttpMockServer.Variables.ContainsKey(SubscriptionIdKey)) - { - AzureRmProfileProvider.Instance.Profile.DefaultContext.Subscription.Id = HttpMockServer.Variables[SubscriptionIdKey]; - } - } - - var client = context.GetGraphServiceClient(environment, true); - client.TenantID = tenantId; - if (AzureRmProfileProvider.Instance != null && - AzureRmProfileProvider.Instance.Profile != null && - AzureRmProfileProvider.Instance.Profile.DefaultContext != null && - AzureRmProfileProvider.Instance.Profile.DefaultContext.Tenant != null) - { - AzureRmProfileProvider.Instance.Profile.DefaultContext.Tenant.Id = client.TenantID; - } - return client; - } - - /// - /// Gets the authorization management client. - /// - /// The context. - /// AuthorizationManagementClient. - private AuthorizationManagementClient GetAuthClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } } } \ No newline at end of file