diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.cs index 9d72f81d388f..e38e2d0233f7 100644 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.cs +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.cs @@ -17,70 +17,66 @@ namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest { - public class AccountTests + public class AccountTests : CosmosDBTestRunner { - private ServiceManagement.Common.Models.XunitTracingInterceptor _logger; - - public AccountTests(Xunit.Abstractions.ITestOutputHelper output) + public AccountTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output); - ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAccountRelatedCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdlets"); + TestRunner.RunTestScript("Test-AccountRelatedCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAccountRelatedCmdletsUsingRid() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingRid"); + TestRunner.RunTestScript("Test-AccountRelatedCmdletsUsingRid"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAccountRelatedCmdletsUsingObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingObject"); + TestRunner.RunTestScript("Test-AccountRelatedCmdletsUsingObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddRegionOperation() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-AddRegionOperation"); + TestRunner.RunTestScript("Test-AddRegionOperation"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestPrivateEndpoint() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-PrivateEndpoint"); + TestRunner.RunTestScript("Test-PrivateEndpoint"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAnalyticalStorageSchemaTypeNewAccount() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-AnalyticalStorageSchemaTypeNewAccount"); + TestRunner.RunTestScript("Test-AnalyticalStorageSchemaTypeNewAccount"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAnalyticalStorageSchemaTypeUpdateAccount() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-AnalyticalStorageSchemaTypeUpdateAccount"); + TestRunner.RunTestScript("Test-AnalyticalStorageSchemaTypeUpdateAccount"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCosmosDBLocations() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CosmosDBLocations"); + TestRunner.RunTestScript("Test-CosmosDBLocations"); } } } \ No newline at end of file diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/CassandraOperationsTests.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/CassandraOperationsTests.cs index 59909408044c..cedbed96d55d 100644 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/CassandraOperationsTests.cs +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/CassandraOperationsTests.cs @@ -17,42 +17,38 @@ namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest { - public class CassandraOperationsTests + public class CassandraOperationsTests : CosmosDBTestRunner { - private ServiceManagement.Common.Models.XunitTracingInterceptor _logger; - - public CassandraOperationsTests(Xunit.Abstractions.ITestOutputHelper output) + public CassandraOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output); - ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCassandraCreateUpdateGetCmdletsByPiping() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CassandraCreateUpdateGetCmdletsByPiping"); + TestRunner.RunTestScript("Test-CassandraCreateUpdateGetCmdletsByPiping"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCassandraThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CassandraThroughputCmdlets"); + TestRunner.RunTestScript("Test-CassandraThroughputCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCassandraCreateUpdateGetCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CassandraCreateUpdateGetCmdlets"); + TestRunner.RunTestScript("Test-CassandraCreateUpdateGetCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestCassandraMigrateThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-CassandraMigrateThroughputCmdlets"); + TestRunner.RunTestScript("Test-CassandraMigrateThroughputCmdlets"); } } } \ No newline at end of file diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/CosmosDBTestRunner.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/CosmosDBTestRunner.cs new file mode 100644 index 000000000000..7d6ef0c7a43b --- /dev/null +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/CosmosDBTestRunner.cs @@ -0,0 +1,59 @@ +// ---------------------------------------------------------------------------------- +// +// 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.CosmosDB.Test.ScenarioTests +{ + public class CosmosDBTestRunner + { + protected readonly ITestRunner TestRunner; + + protected CosmosDBTestRunner(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.KeyVault.psd1"), + helper.GetRMModulePath("Az.CosmosDB.psd1"), + helper.GetRMModulePath("Az.Network.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.Network", null}, + {"Microsoft.Compute", null} + } + ) + .Build(); + } + } +} diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/GremlinOperationsTests.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/GremlinOperationsTests.cs index 397fec625a51..4e79d6bc0108 100644 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/GremlinOperationsTests.cs +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/GremlinOperationsTests.cs @@ -17,42 +17,38 @@ namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest { - public class GremlinOperationsTests + public class GremlinOperationsTests : CosmosDBTestRunner { - private ServiceManagement.Common.Models.XunitTracingInterceptor _logger; - - public GremlinOperationsTests(Xunit.Abstractions.ITestOutputHelper output) + public GremlinOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output); - ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGremlinOperationsCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-GremlinOperationsCmdlets"); + TestRunner.RunTestScript("Test-GremlinOperationsCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGremlinOperationsCmdletsUsingInputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-GremlinOperationsCmdletsUsingInputObject"); + TestRunner.RunTestScript("Test-GremlinOperationsCmdletsUsingInputObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGremlinThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-GremlinThroughputCmdlets"); + TestRunner.RunTestScript("Test-GremlinThroughputCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGremlinMigrateThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-GremlinMigrateThroughputCmdlets"); + TestRunner.RunTestScript("Test-GremlinMigrateThroughputCmdlets"); } } } \ No newline at end of file diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/ManagedCassandraOperationsTests.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/ManagedCassandraOperationsTests.cs index 98308cac578e..155a5ccd6e3e 100644 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/ManagedCassandraOperationsTests.cs +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/ManagedCassandraOperationsTests.cs @@ -17,21 +17,17 @@ namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest { - public class ManagedCassandraOperationsTests + public class ManagedCassandraOperationsTests : CosmosDBTestRunner { - private ServiceManagement.Common.Models.XunitTracingInterceptor _logger; - - public ManagedCassandraOperationsTests(Xunit.Abstractions.ITestOutputHelper output) + public ManagedCassandraOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output); - ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger); } [Fact(Skip = "Cannot assign network contributor role to virtual networks. Test Fails.")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestManagedCassandraClusterCreateUpdateGetCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-ManagedCassandraCreateUpdateGetCmdlets"); + TestRunner.RunTestScript("Test-ManagedCassandraCreateUpdateGetCmdlets"); } } } \ No newline at end of file diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/MongoOperationsTests.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/MongoOperationsTests.cs index 7246a089eee2..413305efc521 100644 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/MongoOperationsTests.cs +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/MongoOperationsTests.cs @@ -17,42 +17,38 @@ namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest { - public class MongoOperationsTests + public class MongoOperationsTests : CosmosDBTestRunner { - private ServiceManagement.Common.Models.XunitTracingInterceptor _logger; - - public MongoOperationsTests(Xunit.Abstractions.ITestOutputHelper output) + public MongoOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output); - ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestMongoOperationsCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoOperationsCmdlets"); + TestRunner.RunTestScript("Test-MongoOperationsCmdlets"); } [Fact(Skip = "The MAC signature found in the HTTP request is not the same as the computed signature.")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestMongoOperationsCmdletsUsingInputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoOperationsCmdletsUsingInputObject"); + TestRunner.RunTestScript("Test-MongoOperationsCmdletsUsingInputObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestMongoThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoThroughputCmdlets"); + TestRunner.RunTestScript("Test-MongoThroughputCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestMongoMigrateThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoMigrateThroughputCmdlets"); + TestRunner.RunTestScript("Test-MongoMigrateThroughputCmdlets"); } } } \ No newline at end of file diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs index fdfea81f9e0d..d17e149aec62 100644 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs @@ -17,63 +17,59 @@ namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest { - public class RestoreTests + public class RestoreTests : CosmosDBTestRunner { - private readonly ServiceManagement.Common.Models.XunitTracingInterceptor _logger; - - public RestoreTests(Xunit.Abstractions.ITestOutputHelper output) + public RestoreTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output); - ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger); } [Fact(Skip = "Unrecognized time format for linux/mac.")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRestoreAccountCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-RestoreAccountCmdlets"); + TestRunner.RunTestScript("Test-RestoreAccountCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRestoreFromNewAccountCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-RestoreFromNewAccountCmdlets"); + TestRunner.RunTestScript("Test-RestoreFromNewAccountCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestMongoRestoreAccountCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoRestoreAccountCmdlets"); + TestRunner.RunTestScript("Test-MongoRestoreAccountCmdlets"); } [Fact(Skip = "Unrecognized time format for linux/mac.")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRestoreFailuresAccountCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-RestoreFailuresAccountCmdlets"); + TestRunner.RunTestScript("Test-RestoreFailuresAccountCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSqlContainerBackupInformationCmdLets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlContainerBackupInformationCmdLets"); + TestRunner.RunTestScript("Test-SqlContainerBackupInformationCmdLets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestMongoDBCollectionBackupInformationCmdLets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoDBCollectionBackupInformationCmdLets"); + TestRunner.RunTestScript("Test-MongoDBCollectionBackupInformationCmdLets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestUpdateCosmosDBAccountBackupPolicyCmdLet() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-UpdateCosmosDBAccountBackupPolicyCmdLet"); + TestRunner.RunTestScript("Test-UpdateCosmosDBAccountBackupPolicyCmdLet"); } } } diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/SqlOperationsTests.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/SqlOperationsTests.cs index 7fcf13a6319f..47ce23fd567a 100644 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/SqlOperationsTests.cs +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/SqlOperationsTests.cs @@ -17,63 +17,59 @@ namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest { - public class SqlOperationsTests + public class SqlOperationsTests : CosmosDBTestRunner { - private ServiceManagement.Common.Models.XunitTracingInterceptor _logger; - - public SqlOperationsTests(Xunit.Abstractions.ITestOutputHelper output) + public SqlOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output); - ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSqlOperationsCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlOperationsCmdlets"); + TestRunner.RunTestScript("Test-SqlOperationsCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSqlOperationsCmdletsUsingInputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlOperationsCmdletsUsingInputObject"); + TestRunner.RunTestScript("Test-SqlOperationsCmdletsUsingInputObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSqlThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlThroughputCmdlets"); + TestRunner.RunTestScript("Test-SqlThroughputCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSqlMigrateThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlMigrateThroughputCmdlets"); + TestRunner.RunTestScript("Test-SqlMigrateThroughputCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSqlRoleCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlRoleCmdlets"); + TestRunner.RunTestScript("Test-SqlRoleCmdlets"); } [Fact(Skip = "Cannot acquire token credential for a specific audience. No support from test framework. I have verified the tests manually.")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestClientEncryptionKeyCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-ClientEncryptionKeyCmdlets"); + TestRunner.RunTestScript("Test-ClientEncryptionKeyCmdlets"); } [Fact(Skip = "Cannot acquire token credential for a specific audience. No support from test framework. I have verified the tests manually.")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestClientEncryptionKeyCmdletsUsingInputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-ClientEncryptionKeyCmdletsUsingInputObject"); + TestRunner.RunTestScript("Test-ClientEncryptionKeyCmdletsUsingInputObject"); } } } \ No newline at end of file diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/TableOperationsTests.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/TableOperationsTests.cs index 536407b525c5..df5b553f3a6e 100644 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/TableOperationsTests.cs +++ b/src/CosmosDB/CosmosDB.Test/ScenarioTests/TableOperationsTests.cs @@ -17,42 +17,38 @@ namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest { - public class TableOperationsTests + public class TableOperationsTests : CosmosDBTestRunner { - private ServiceManagement.Common.Models.XunitTracingInterceptor _logger; - - public TableOperationsTests(Xunit.Abstractions.ITestOutputHelper output) + public TableOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output); - ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestTableOperationsCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-TableOperationsCmdlets"); + TestRunner.RunTestScript("Test-TableOperationsCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestTableOperationsCmdletsUsingInputObject() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-TableOperationsCmdletsUsingInputObject"); + TestRunner.RunTestScript("Test-TableOperationsCmdletsUsingInputObject"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestTableThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-TableThroughputCmdlets"); + TestRunner.RunTestScript("Test-TableThroughputCmdlets"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestTableMigrateThroughputCmdlets() { - TestController.NewInstance.RunPowerShellTest(_logger, "Test-TableMigrateThroughputCmdlets"); + TestRunner.RunTestScript("Test-TableMigrateThroughputCmdlets"); } } } \ No newline at end of file diff --git a/src/CosmosDB/CosmosDB.Test/ScenarioTests/TestController.cs b/src/CosmosDB/CosmosDB.Test/ScenarioTests/TestController.cs deleted file mode 100644 index 18fc8ad573ac..000000000000 --- a/src/CosmosDB/CosmosDB.Test/ScenarioTests/TestController.cs +++ /dev/null @@ -1,181 +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 System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Microsoft.Azure.Commands.Common.Authentication; -using Microsoft.Azure.Internal.Common; -using Microsoft.Azure.Management.Internal.Resources; -using Microsoft.Azure.Management.CosmosDB; -using Microsoft.Azure.Management.Network; -using Microsoft.Azure.Test.HttpRecorder; -using Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; -using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory; -using Microsoft.Azure.KeyVault; -using Microsoft.Azure.Commands.Common.KeyVault.Version2016_10_1; - -namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest -{ - public class TestController : RMTestBase - { - private readonly EnvironmentSetupHelper _helper; - - public ResourceManagementClient ResourceManagementClient { get; private set; } - - public CosmosDBManagementClient CosmosDBManagementClient { get; private set; } - - public NetworkManagementClient NetworkManagementClient { get; private set; } - - public AzureRestClient AzureRestClient { get; private set; } - - public KeyVaultManagementClient KeyVaultManagementClient { get; private set; } - - public KeyVaultClient KeyVaultClient { get; private set; } - - public static CosmosDBTestHelper CosmosDBTestHelper { get; private set; } - - public static TestController NewInstance => new TestController(); - - protected TestController() - { - _helper = new EnvironmentSetupHelper(); - } - - protected void SetupManagementClients(MockContext context) - { - ResourceManagementClient = GetResourceManagementClient(context); - CosmosDBManagementClient = GetCosmosDBManagementClient(context); - NetworkManagementClient = GetNetworkManagementClient(context); - AzureRestClient = GetAzureRestClient(context); - KeyVaultManagementClient = GetKeyVaultManagementClient(context); - _helper.SetupManagementClients( - ResourceManagementClient, - CosmosDBManagementClient, - NetworkManagementClient, - AzureRestClient, - KeyVaultManagementClient); - } - - public void RunPowerShellTest(ServiceManagement.Common.Models.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.Network", null}, - {"Microsoft.Compute", 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); - - KeyVaultClient = GetKeyVaultClient(); - CosmosDBTestHelper = GetTestHelper(); - - var callingClassName = callingClassType.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last(); - - _helper.SetupModules(AzureModule.AzureResourceManager, - "ScenarioTests\\Common.ps1", - "ScenarioTests\\" + callingClassName + ".ps1", - _helper.RMProfileModule, - _helper.GetRMModulePath("Az.KeyVault.psd1"), - _helper.GetRMModulePath("Az.CosmosDB.psd1"), - _helper.GetRMModulePath("Az.Network.psd1"), - "AzureRM.Resources.ps1"); - try - { - var psScripts = scriptBuilder?.Invoke(); - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - finally - { - cleanup?.Invoke(); - } - } - } - - protected ResourceManagementClient GetResourceManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static CosmosDBManagementClient GetCosmosDBManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static NetworkManagementClient GetNetworkManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static AzureRestClient GetAzureRestClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - - private static KeyVaultManagementClient GetKeyVaultManagementClient(MockContext context) - { - return context.GetServiceClient(TestEnvironmentFactory.GetTestEnvironment()); - } - private CosmosDBTestHelper GetTestHelper() - { - return new CosmosDBTestHelper(this.KeyVaultManagementClient, this.KeyVaultClient); - } - - private static KeyVaultClient GetKeyVaultClient() - { - return new KeyVaultClient(CosmosDBTestHelper.GetAccessToken, CosmosDBTestHelper.GetHandlers()); - } - } -}