Skip to content

Commit ec77d18

Browse files
CaptainFanZzzZiyue Zheng
and
Ziyue Zheng
authored
Add ContainerRegistryTestRunner and replace TestController (Azure#18071)
* Add ContainerRegistryTestRunner and replace TestController * Add ContainerRegistryTestRunner and replace TestController Co-authored-by: Ziyue Zheng <[email protected]>
1 parent b64ba29 commit ec77d18

File tree

5 files changed

+70
-135
lines changed

5 files changed

+70
-135
lines changed

src/ContainerRegistry/ContainerRegistry.Test/ScenarioTests/ContainerRegistryCreateWithNetworkRuleSetTests.cs

+3-12
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,22 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1916
using Xunit;
20-
using Xunit.Abstractions;
2117

2218
namespace Microsoft.Azure.Commands.ContainerRegistry.Test.ScenarioTests
2319
{
24-
public class ContainerRegistryCreateWithNetworkRuleSetTests : RMTestBase
20+
public class ContainerRegistryCreateWithNetworkRuleSetTests : ContainerRegistryTestRunner
2521
{
26-
public XunitTracingInterceptor _logger;
27-
28-
public ContainerRegistryCreateWithNetworkRuleSetTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public ContainerRegistryCreateWithNetworkRuleSetTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2923
{
30-
_logger = new XunitTracingInterceptor(output);
31-
XunitTracingInterceptor.AddToContext(_logger);
32-
TestExecutionHelpers.SetUpSessionAndProfile();
3324
}
3425

3526
[Fact]
3627
[Trait(Category.AcceptanceType, Category.CheckIn)]
3728
public void TestCreateWithNetworkRuleSet()
3829
{
39-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateWithNetworkRuleSet");
30+
TestRunner.RunTestScript("Test-CreateWithNetworkRuleSet");
4031
}
4132
}
4233
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.ContainerRegistry.Test.ScenarioTests
20+
{
21+
public class ContainerRegistryTestRunner
22+
{
23+
protected readonly ITestRunner TestRunner;
24+
25+
protected ContainerRegistryTestRunner(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.Network.psd1"),
39+
helper.GetRMModulePath("Az.ContainerRegistry.psd1")
40+
})
41+
.WithNewRecordMatcherArguments(
42+
userAgentsToIgnore: new Dictionary<string, string>
43+
{
44+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"},
45+
},
46+
resourceProviders: new Dictionary<string, string>
47+
{
48+
{"Microsoft.Resources", null},
49+
{"Microsoft.Features", null},
50+
{"Microsoft.Authorization", null},
51+
{"Microsoft.Network", null}
52+
}
53+
)
54+
.Build();
55+
}
56+
}
57+
}

src/ContainerRegistry/ContainerRegistry.Test/ScenarioTests/ContainerRegistryTests.cs

+7-16
Original file line numberDiff line numberDiff line change
@@ -12,61 +12,52 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1916
using Xunit;
20-
using Xunit.Abstractions;
2117

2218
namespace Microsoft.Azure.Commands.ContainerRegistry.Test.ScenarioTests
2319
{
24-
public class ContainerRegistryTests : RMTestBase
20+
public class ContainerRegistryTests : ContainerRegistryTestRunner
2521
{
26-
public XunitTracingInterceptor _logger;
27-
28-
public ContainerRegistryTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public ContainerRegistryTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2923
{
30-
_logger = new XunitTracingInterceptor(output);
31-
XunitTracingInterceptor.AddToContext(_logger);
32-
TestExecutionHelpers.SetUpSessionAndProfile();
3324
}
3425

3526
[Fact]
3627
[Trait(Category.AcceptanceType, Category.CheckIn)]
3728
public void TestContainerReg()
3829
{
39-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureContainerRegistry");
30+
TestRunner.RunTestScript("Test-AzureContainerRegistry");
4031
}
4132

4233
[Fact]
4334
[Trait(Category.AcceptanceType, Category.CheckIn)]
4435
public void TestContainerRegCredential()
4536
{
46-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureContainerRegistryCredential");
37+
TestRunner.RunTestScript("Test-AzureContainerRegistryCredential");
4738
}
4839

4940
[Fact]
5041
[Trait(Category.AcceptanceType, Category.CheckIn)]
5142
public void TestContainerRegNameAvailability()
5243
{
53-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureContainerRegistryNameAvailability");
44+
TestRunner.RunTestScript("Test-AzureContainerRegistryNameAvailability");
5445
}
5546

5647
[Fact(Skip = "Need service team to re-record test after changes to the ClientRuntime.")]
5748
[Trait(Category.AcceptanceType, Category.CheckIn)]
5849
[Trait("Re-record", "ClientRuntime changes")]
5950
public void TestContainerRegReplication()
6051
{
61-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureContainerRegistryReplication");
52+
TestRunner.RunTestScript("Test-AzureContainerRegistryReplication");
6253
}
6354

6455
[Fact(Skip = "Need service team to re-record test after changes to the ClientRuntime.")]
6556
[Trait(Category.AcceptanceType, Category.CheckIn)]
6657
[Trait("Re-record", "ClientRuntime changes")]
6758
public void TestContainerRegWebhook()
6859
{
69-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzureContainerRegistryWebhook");
60+
TestRunner.RunTestScript("Test-AzureContainerRegistryWebhook");
7061
}
7162
}
7263
}

src/ContainerRegistry/ContainerRegistry.Test/ScenarioTests/ImportImageTests.cs

+3-12
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,22 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1916
using Xunit;
20-
using Xunit.Abstractions;
2117

2218
namespace Microsoft.Azure.Commands.ContainerRegistry.Test.ScenarioTests
2319
{
24-
public class ImportImageTests : RMTestBase
20+
public class ImportImageTests : ContainerRegistryTestRunner
2521
{
26-
public XunitTracingInterceptor _logger;
27-
28-
public ImportImageTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public ImportImageTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2923
{
30-
_logger = new XunitTracingInterceptor(output);
31-
XunitTracingInterceptor.AddToContext(_logger);
32-
TestExecutionHelpers.SetUpSessionAndProfile();
3324
}
3425

3526
[Fact]
3627
[Trait(Category.AcceptanceType, Category.CheckIn)]
3728
public void TestImportImage()
3829
{
39-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ImportImage");
30+
TestRunner.RunTestScript("Test-ImportImage");
4031
}
4132
}
4233
}

src/ContainerRegistry/ContainerRegistry.Test/ScenarioTests/TestController.cs

-95
This file was deleted.

0 commit comments

Comments
 (0)