Skip to content

Commit 81ec8cc

Browse files
author
Ziyue Zheng
authored
Add BatchTestRunner class (#18082)
1 parent 8886bdd commit 81ec8cc

File tree

3 files changed

+74
-19
lines changed

3 files changed

+74
-19
lines changed

src/Batch/Batch.Test/ScenarioTests/BatchAccountTests.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,43 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.ServiceManagement.Common.Models;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1716
using Xunit;
1817

1918
namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
2019
{
21-
public class BatchAccountTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
20+
public class BatchAccountTests : BatchTestRunner
2221
{
23-
public XunitTracingInterceptor _logger;
24-
25-
public BatchAccountTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public BatchAccountTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2623
{
27-
_logger = new XunitTracingInterceptor(output);
28-
XunitTracingInterceptor.AddToContext(_logger);
2924
}
3025

3126
[Fact]
3227
[Trait(Category.AcceptanceType, Category.CheckIn)]
3328
public void TestBatchAccountEndToEnd()
3429
{
35-
BatchController.NewInstance.RunPsTest(_logger, "Test-BatchAccountEndToEnd");
30+
TestRunner.RunTestScript("Test-BatchAccountEndToEnd");
3631
}
3732

3833
[Fact]
3934
[Trait(Category.AcceptanceType, Category.CheckIn)]
4035
public void TestGetBatchSupportedImages()
4136
{
42-
BatchController.NewInstance.RunPsTest(_logger, "Test-GetBatchSupportedImage");
37+
TestRunner.RunTestScript("Test-GetBatchSupportedImage");
4338
}
4439

4540
[Fact]
4641
[Trait(Category.AcceptanceType, Category.CheckIn)]
4742
public void TestCreateNewBatchAccountWithNoPublicIp()
4843
{
49-
BatchController.NewInstance.RunPsTest(_logger, "Test-CreateNewBatchAccountWithNoPublicIp");
44+
TestRunner.RunTestScript("Test-CreateNewBatchAccountWithNoPublicIp");
5045
}
5146

5247
[Fact]
5348
[Trait(Category.AcceptanceType, Category.CheckIn)]
5449
public void TestCreateNewBatchAccountWithSystemIdentity()
5550
{
56-
BatchController.NewInstance.RunPsTest(_logger, "Test-CreateNewBatchAccountWithSystemIdentity");
51+
TestRunner.RunTestScript("Test-CreateNewBatchAccountWithSystemIdentity");
5752
}
5853
}
5954
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 Microsoft.Azure.Internal.Common;
16+
using Microsoft.Azure.Management.Batch;
17+
using Microsoft.Azure.Management.Internal.Resources;
18+
using Microsoft.Azure.Management.Network;
19+
using Microsoft.Azure.Test.HttpRecorder;
20+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
21+
using System;
22+
using System.Collections.Generic;
23+
using Microsoft.Azure.Commands.TestFx;
24+
using Xunit.Abstractions;
25+
26+
namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
27+
{
28+
// Needs more initialize parameters after setup HttpMockServer.
29+
public class BatchTestRunner
30+
{
31+
protected readonly ITestRunner TestRunner;
32+
33+
protected BatchTestRunner(ITestOutputHelper output)
34+
{
35+
TestRunner = TestManager.CreateInstance(output)
36+
.WithNewPsScriptFilename($"{GetType().Name}.ps1")
37+
.WithProjectSubfolderForTests("ScenarioTests")
38+
.WithCommonPsScripts(new[]
39+
{
40+
@"Common.ps1",
41+
@"../AzureRM.Resources.ps1",
42+
})
43+
.WithNewRmModules(helper => new[]
44+
{
45+
helper.RMProfileModule,
46+
helper.GetRMModulePath("Az.Batch.psd1"),
47+
helper.GetRMModulePath("Az.Network.psd1")
48+
})
49+
.WithNewRecordMatcherArguments(
50+
userAgentsToIgnore: new Dictionary<string, string>
51+
{
52+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"},
53+
},
54+
resourceProviders: new Dictionary<string, string>
55+
{
56+
{"Microsoft.Resources", null},
57+
{"Microsoft.Features", null},
58+
{"Microsoft.Network", null},
59+
{"Microsoft.Authorization", null}
60+
}
61+
)
62+
.Build();
63+
}
64+
}
65+
}

src/Batch/Batch.Test/ScenarioTests/LocationTests.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,22 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.ServiceManagement.Common.Models;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1716
using Xunit;
1817

1918
namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
2019
{
21-
public class LocationTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
20+
public class LocationTests : BatchTestRunner
2221
{
23-
public XunitTracingInterceptor _logger;
24-
25-
public LocationTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public LocationTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2623
{
27-
_logger = new XunitTracingInterceptor(output);
28-
XunitTracingInterceptor.AddToContext(_logger);
2924
}
3025

3126
[Fact]
3227
[Trait(Category.AcceptanceType, Category.CheckIn)]
3328
public void TestGetLocationQuotas()
3429
{
35-
BatchController.NewInstance.RunPsTest(_logger, "Test-GetLocationQuotas");
30+
TestRunner.RunTestScript("Test-GetLocationQuotas");
3631
}
3732
}
3833
}

0 commit comments

Comments
 (0)