Skip to content

Commit b64ba29

Browse files
Add CosmosDBTestRunner and replace TestController (Azure#18073)
1 parent fdbc302 commit b64ba29

10 files changed

+114
-268
lines changed

src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.cs

+10-14
Original file line numberDiff line numberDiff line change
@@ -17,70 +17,66 @@
1717

1818
namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest
1919
{
20-
public class AccountTests
20+
public class AccountTests : CosmosDBTestRunner
2121
{
22-
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
23-
24-
public AccountTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public AccountTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2523
{
26-
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
27-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2824
}
2925

3026
[Fact]
3127
[Trait(Category.AcceptanceType, Category.CheckIn)]
3228
public void TestAccountRelatedCmdlets()
3329
{
34-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdlets");
30+
TestRunner.RunTestScript("Test-AccountRelatedCmdlets");
3531
}
3632

3733
[Fact]
3834
[Trait(Category.AcceptanceType, Category.CheckIn)]
3935
public void TestAccountRelatedCmdletsUsingRid()
4036
{
41-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingRid");
37+
TestRunner.RunTestScript("Test-AccountRelatedCmdletsUsingRid");
4238
}
4339

4440
[Fact]
4541
[Trait(Category.AcceptanceType, Category.CheckIn)]
4642
public void TestAccountRelatedCmdletsUsingObject()
4743
{
48-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingObject");
44+
TestRunner.RunTestScript("Test-AccountRelatedCmdletsUsingObject");
4945
}
5046

5147
[Fact]
5248
[Trait(Category.AcceptanceType, Category.CheckIn)]
5349
public void TestAddRegionOperation()
5450
{
55-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AddRegionOperation");
51+
TestRunner.RunTestScript("Test-AddRegionOperation");
5652
}
5753

5854
[Fact]
5955
[Trait(Category.AcceptanceType, Category.CheckIn)]
6056
public void TestPrivateEndpoint()
6157
{
62-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-PrivateEndpoint");
58+
TestRunner.RunTestScript("Test-PrivateEndpoint");
6359
}
6460

6561
[Fact]
6662
[Trait(Category.AcceptanceType, Category.CheckIn)]
6763
public void TestAnalyticalStorageSchemaTypeNewAccount()
6864
{
69-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AnalyticalStorageSchemaTypeNewAccount");
65+
TestRunner.RunTestScript("Test-AnalyticalStorageSchemaTypeNewAccount");
7066
}
7167

7268
[Fact]
7369
[Trait(Category.AcceptanceType, Category.CheckIn)]
7470
public void TestAnalyticalStorageSchemaTypeUpdateAccount()
7571
{
76-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AnalyticalStorageSchemaTypeUpdateAccount");
72+
TestRunner.RunTestScript("Test-AnalyticalStorageSchemaTypeUpdateAccount");
7773
}
7874

7975
[Fact]
8076
[Trait(Category.AcceptanceType, Category.CheckIn)]
8177
public void TestCosmosDBLocations()
8278
{
83-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CosmosDBLocations");
79+
TestRunner.RunTestScript("Test-CosmosDBLocations");
8480
}
8581
}
8682
}

src/CosmosDB/CosmosDB.Test/ScenarioTests/CassandraOperationsTests.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,38 @@
1717

1818
namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest
1919
{
20-
public class CassandraOperationsTests
20+
public class CassandraOperationsTests : CosmosDBTestRunner
2121
{
22-
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
23-
24-
public CassandraOperationsTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public CassandraOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2523
{
26-
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
27-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2824
}
2925

3026
[Fact]
3127
[Trait(Category.AcceptanceType, Category.CheckIn)]
3228
public void TestCassandraCreateUpdateGetCmdletsByPiping()
3329
{
34-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CassandraCreateUpdateGetCmdletsByPiping");
30+
TestRunner.RunTestScript("Test-CassandraCreateUpdateGetCmdletsByPiping");
3531
}
3632

3733
[Fact]
3834
[Trait(Category.AcceptanceType, Category.CheckIn)]
3935
public void TestCassandraThroughputCmdlets()
4036
{
41-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CassandraThroughputCmdlets");
37+
TestRunner.RunTestScript("Test-CassandraThroughputCmdlets");
4238
}
4339

4440
[Fact]
4541
[Trait(Category.AcceptanceType, Category.CheckIn)]
4642
public void TestCassandraCreateUpdateGetCmdlets()
4743
{
48-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CassandraCreateUpdateGetCmdlets");
44+
TestRunner.RunTestScript("Test-CassandraCreateUpdateGetCmdlets");
4945
}
5046

5147
[Fact]
5248
[Trait(Category.AcceptanceType, Category.CheckIn)]
5349
public void TestCassandraMigrateThroughputCmdlets()
5450
{
55-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CassandraMigrateThroughputCmdlets");
51+
TestRunner.RunTestScript("Test-CassandraMigrateThroughputCmdlets");
5652
}
5753
}
5854
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Collections.Generic;
16+
using Microsoft.Azure.Commands.TestFx;
17+
using Xunit.Abstractions;
18+
19+
namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests
20+
{
21+
public class CosmosDBTestRunner
22+
{
23+
protected readonly ITestRunner TestRunner;
24+
25+
protected CosmosDBTestRunner(ITestOutputHelper output)
26+
{
27+
TestRunner = TestManager.CreateInstance(output)
28+
.WithNewPsScriptFilename($"{GetType().Name}.ps1")
29+
.WithProjectSubfolderForTests("ScenarioTests")
30+
.WithCommonPsScripts(new[]
31+
{
32+
@"Common.ps1",
33+
@"../AzureRM.Resources.ps1",
34+
})
35+
.WithNewRmModules(helper => new[]
36+
{
37+
helper.RMProfileModule,
38+
helper.GetRMModulePath("Az.KeyVault.psd1"),
39+
helper.GetRMModulePath("Az.CosmosDB.psd1"),
40+
helper.GetRMModulePath("Az.Network.psd1")
41+
})
42+
.WithNewRecordMatcherArguments(
43+
userAgentsToIgnore: new Dictionary<string, string>
44+
{
45+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"},
46+
},
47+
resourceProviders: new Dictionary<string, string>
48+
{
49+
{"Microsoft.Resources", null},
50+
{"Microsoft.Features", null},
51+
{"Microsoft.Authorization", null},
52+
{"Microsoft.Network", null},
53+
{"Microsoft.Compute", null}
54+
}
55+
)
56+
.Build();
57+
}
58+
}
59+
}

src/CosmosDB/CosmosDB.Test/ScenarioTests/GremlinOperationsTests.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,38 @@
1717

1818
namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest
1919
{
20-
public class GremlinOperationsTests
20+
public class GremlinOperationsTests : CosmosDBTestRunner
2121
{
22-
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
23-
24-
public GremlinOperationsTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public GremlinOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2523
{
26-
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
27-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2824
}
2925

3026
[Fact]
3127
[Trait(Category.AcceptanceType, Category.CheckIn)]
3228
public void TestGremlinOperationsCmdlets()
3329
{
34-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GremlinOperationsCmdlets");
30+
TestRunner.RunTestScript("Test-GremlinOperationsCmdlets");
3531
}
3632

3733
[Fact]
3834
[Trait(Category.AcceptanceType, Category.CheckIn)]
3935
public void TestGremlinOperationsCmdletsUsingInputObject()
4036
{
41-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GremlinOperationsCmdletsUsingInputObject");
37+
TestRunner.RunTestScript("Test-GremlinOperationsCmdletsUsingInputObject");
4238
}
4339

4440
[Fact]
4541
[Trait(Category.AcceptanceType, Category.CheckIn)]
4642
public void TestGremlinThroughputCmdlets()
4743
{
48-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GremlinThroughputCmdlets");
44+
TestRunner.RunTestScript("Test-GremlinThroughputCmdlets");
4945
}
5046

5147
[Fact]
5248
[Trait(Category.AcceptanceType, Category.CheckIn)]
5349
public void TestGremlinMigrateThroughputCmdlets()
5450
{
55-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GremlinMigrateThroughputCmdlets");
51+
TestRunner.RunTestScript("Test-GremlinMigrateThroughputCmdlets");
5652
}
5753
}
5854
}

src/CosmosDB/CosmosDB.Test/ScenarioTests/ManagedCassandraOperationsTests.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,17 @@
1717

1818
namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest
1919
{
20-
public class ManagedCassandraOperationsTests
20+
public class ManagedCassandraOperationsTests : CosmosDBTestRunner
2121
{
22-
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
23-
24-
public ManagedCassandraOperationsTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public ManagedCassandraOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2523
{
26-
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
27-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2824
}
2925

3026
[Fact(Skip = "Cannot assign network contributor role to virtual networks. Test Fails.")]
3127
[Trait(Category.AcceptanceType, Category.CheckIn)]
3228
public void TestManagedCassandraClusterCreateUpdateGetCmdlets()
3329
{
34-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ManagedCassandraCreateUpdateGetCmdlets");
30+
TestRunner.RunTestScript("Test-ManagedCassandraCreateUpdateGetCmdlets");
3531
}
3632
}
3733
}

src/CosmosDB/CosmosDB.Test/ScenarioTests/MongoOperationsTests.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,38 @@
1717

1818
namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest
1919
{
20-
public class MongoOperationsTests
20+
public class MongoOperationsTests : CosmosDBTestRunner
2121
{
22-
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
23-
24-
public MongoOperationsTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public MongoOperationsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2523
{
26-
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
27-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2824
}
2925

3026
[Fact]
3127
[Trait(Category.AcceptanceType, Category.CheckIn)]
3228
public void TestMongoOperationsCmdlets()
3329
{
34-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoOperationsCmdlets");
30+
TestRunner.RunTestScript("Test-MongoOperationsCmdlets");
3531
}
3632

3733
[Fact(Skip = "The MAC signature found in the HTTP request is not the same as the computed signature.")]
3834
[Trait(Category.AcceptanceType, Category.CheckIn)]
3935
public void TestMongoOperationsCmdletsUsingInputObject()
4036
{
41-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoOperationsCmdletsUsingInputObject");
37+
TestRunner.RunTestScript("Test-MongoOperationsCmdletsUsingInputObject");
4238
}
4339

4440
[Fact]
4541
[Trait(Category.AcceptanceType, Category.CheckIn)]
4642
public void TestMongoThroughputCmdlets()
4743
{
48-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoThroughputCmdlets");
44+
TestRunner.RunTestScript("Test-MongoThroughputCmdlets");
4945
}
5046

5147
[Fact]
5248
[Trait(Category.AcceptanceType, Category.CheckIn)]
5349
public void TestMongoMigrateThroughputCmdlets()
5450
{
55-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoMigrateThroughputCmdlets");
51+
TestRunner.RunTestScript("Test-MongoMigrateThroughputCmdlets");
5652
}
5753
}
5854
}

src/CosmosDB/CosmosDB.Test/ScenarioTests/RestoreTests.cs

+9-13
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,59 @@
1717

1818
namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest
1919
{
20-
public class RestoreTests
20+
public class RestoreTests : CosmosDBTestRunner
2121
{
22-
private readonly ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
23-
24-
public RestoreTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public RestoreTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2523
{
26-
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
27-
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
2824
}
2925

3026
[Fact(Skip = "Unrecognized time format for linux/mac.")]
3127
[Trait(Category.AcceptanceType, Category.CheckIn)]
3228
public void TestRestoreAccountCmdlets()
3329
{
34-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-RestoreAccountCmdlets");
30+
TestRunner.RunTestScript("Test-RestoreAccountCmdlets");
3531
}
3632

3733
[Fact]
3834
[Trait(Category.AcceptanceType, Category.CheckIn)]
3935
public void TestRestoreFromNewAccountCmdlets()
4036
{
41-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-RestoreFromNewAccountCmdlets");
37+
TestRunner.RunTestScript("Test-RestoreFromNewAccountCmdlets");
4238
}
4339

4440
[Fact]
4541
[Trait(Category.AcceptanceType, Category.CheckIn)]
4642
public void TestMongoRestoreAccountCmdlets()
4743
{
48-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoRestoreAccountCmdlets");
44+
TestRunner.RunTestScript("Test-MongoRestoreAccountCmdlets");
4945
}
5046

5147
[Fact(Skip = "Unrecognized time format for linux/mac.")]
5248
[Trait(Category.AcceptanceType, Category.CheckIn)]
5349
public void TestRestoreFailuresAccountCmdlets()
5450
{
55-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-RestoreFailuresAccountCmdlets");
51+
TestRunner.RunTestScript("Test-RestoreFailuresAccountCmdlets");
5652
}
5753

5854
[Fact]
5955
[Trait(Category.AcceptanceType, Category.CheckIn)]
6056
public void TestSqlContainerBackupInformationCmdLets()
6157
{
62-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SqlContainerBackupInformationCmdLets");
58+
TestRunner.RunTestScript("Test-SqlContainerBackupInformationCmdLets");
6359
}
6460

6561
[Fact]
6662
[Trait(Category.AcceptanceType, Category.CheckIn)]
6763
public void TestMongoDBCollectionBackupInformationCmdLets()
6864
{
69-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-MongoDBCollectionBackupInformationCmdLets");
65+
TestRunner.RunTestScript("Test-MongoDBCollectionBackupInformationCmdLets");
7066
}
7167

7268
[Fact]
7369
[Trait(Category.AcceptanceType, Category.CheckIn)]
7470
public void TestUpdateCosmosDBAccountBackupPolicyCmdLet()
7571
{
76-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-UpdateCosmosDBAccountBackupPolicyCmdLet");
72+
TestRunner.RunTestScript("Test-UpdateCosmosDBAccountBackupPolicyCmdLet");
7773
}
7874
}
7975
}

0 commit comments

Comments
 (0)