Skip to content

Commit 12c25f9

Browse files
author
Ziyue Zheng
authored
Add CognitiveServicesTestRunner and replace TestController (#18077)
* Add CognitiveServicesTestRunner and replace TestController * Add CognitiveServicesTestRunner and replace TestController
1 parent 81ec8cc commit 12c25f9

File tree

4 files changed

+96
-204
lines changed

4 files changed

+96
-204
lines changed

src/CognitiveServices/CognitiveServices.Test/ScenarioTests/CognitiveServicesAccountTests.cs

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,259 +14,250 @@
1414

1515

1616
using Microsoft.Azure.Commands.Management.CognitiveServices.Test.ScenarioTests;
17-
using Microsoft.Azure.Commands.ScenarioTest;
18-
using Microsoft.Azure.ServiceManagement.Common.Models;
1917
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
21-
using System;
2218
using Xunit;
2319
using Xunit.Abstractions;
2420

2521
namespace CognitiveServices.Test.ScenarioTests
2622
{
27-
public class CognitiveServicesAccountTests : RMTestBase
23+
public class CognitiveServicesAccountTests : CognitiveServicesTestRunner
2824
{
29-
XunitTracingInterceptor traceInterceptor;
30-
31-
public CognitiveServicesAccountTests(ITestOutputHelper output)
25+
public CognitiveServicesAccountTests(ITestOutputHelper output) : base(output)
3226
{
33-
this.traceInterceptor = new XunitTracingInterceptor(output);
34-
XunitTracingInterceptor.AddToContext(this.traceInterceptor);
35-
TestExecutionHelpers.SetUpSessionAndProfile();
3627
}
3728

3829
[Fact]
3930
[Trait(Category.AcceptanceType, Category.CheckIn)]
4031
public void TestNewAccount()
4132
{
42-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-NewAzureRmCognitiveServicesAccount");
33+
TestRunner.RunTestScript("Test-NewAzureRmCognitiveServicesAccount");
4334
}
4435

4536
[Fact]
4637
[Trait(Category.AcceptanceType, Category.CheckIn)]
4738
public void TestNewAccountWithCustomDomain()
4839
{
49-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-NewAzureRmCognitiveServicesAccountWithCustomDomain");
40+
TestRunner.RunTestScript("Test-NewAzureRmCognitiveServicesAccountWithCustomDomain");
5041
}
5142

5243
[Fact]
5344
[Trait(Category.AcceptanceType, Category.CheckIn)]
5445
public void TestNewAccountWithVnet()
5546
{
56-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-NewAzureRmCognitiveServicesAccountWithVnet");
47+
TestRunner.RunTestScript("Test-NewAzureRmCognitiveServicesAccountWithVnet");
5748
}
5849

5950
[Fact]
6051
[Trait(Category.AcceptanceType, Category.CheckIn)]
6152
public void TestRemoveAccount()
6253
{
63-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-RemoveAzureRmCognitiveServicesAccount");
54+
TestRunner.RunTestScript("Test-RemoveAzureRmCognitiveServicesAccount");
6455
}
6556

6657

6758
[Fact]
6859
[Trait(Category.AcceptanceType, Category.CheckIn)]
6960
public void TestGetAccounts()
7061
{
71-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureCognitiveServiceAccount");
62+
TestRunner.RunTestScript("Test-GetAzureCognitiveServiceAccount");
7263
}
7364

7465
[Fact]
7566
[Trait(Category.AcceptanceType, Category.CheckIn)]
7667
public void TestAsyncAccountOperations()
7768
{
78-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-AsyncAccountOperations");
69+
TestRunner.RunTestScript("Test-AsyncAccountOperations");
7970
}
8071

8172
[Fact]
8273
[Trait(Category.AcceptanceType, Category.CheckIn)]
8374
public void TestSetAccount()
8475
{
85-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-SetAzureRmCognitiveServicesAccount");
76+
TestRunner.RunTestScript("Test-SetAzureRmCognitiveServicesAccount");
8677
}
8778

8879
[Fact]
8980
[Trait(Category.AcceptanceType, Category.CheckIn)]
9081
public void TestSetAccountWithCustomDomain()
9182
{
92-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-SetAzureRmCognitiveServicesAccountWithCustomDomain");
83+
TestRunner.RunTestScript("Test-SetAzureRmCognitiveServicesAccountWithCustomDomain");
9384
}
9485

9586
[Fact]
9687
[Trait(Category.AcceptanceType, Category.CheckIn)]
9788
public void TestSetAccountWithVnet()
9889
{
99-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-SetAzureRmCognitiveServicesAccountWithVnet");
90+
TestRunner.RunTestScript("Test-SetAzureRmCognitiveServicesAccountWithVnet");
10091
}
10192

10293
[Fact]
10394
[Trait(Category.AcceptanceType, Category.CheckIn)]
10495
public void TestNetworkRuleSet()
10596
{
106-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-NetworkRuleSet");
97+
TestRunner.RunTestScript("Test-NetworkRuleSet");
10798
}
10899

109100

110101
[Fact]
111102
[Trait(Category.AcceptanceType, Category.CheckIn)]
112103
public void TestNetworkRuleSetDefaultActions()
113104
{
114-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-NetworkRuleSetDefaultActions");
105+
TestRunner.RunTestScript("Test-NetworkRuleSetDefaultActions");
115106
}
116107

117108
[Fact]
118109
[Trait(Category.AcceptanceType, Category.CheckIn)]
119110
public void TestGetAccountKeys()
120111
{
121-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureRmCognitiveServicesAccountKey");
112+
TestRunner.RunTestScript("Test-GetAzureRmCognitiveServicesAccountKey");
122113
}
123114

124115
[Fact]
125116
[Trait(Category.AcceptanceType, Category.CheckIn)]
126117
public void TestNewAccountKey()
127118
{
128-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-NewAzureRmCognitiveServicesAccountKey");
119+
TestRunner.RunTestScript("Test-NewAzureRmCognitiveServicesAccountKey");
129120
}
130121

131122
[Fact]
132123
[Trait(Category.AcceptanceType, Category.CheckIn)]
133124
public void TestAccountSkus()
134125
{
135-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureRmCognitiveServicesAccountSkus");
126+
TestRunner.RunTestScript("Test-GetAzureRmCognitiveServicesAccountSkus");
136127
}
137128

138129
[Fact]
139130
[Trait(Category.AcceptanceType, Category.CheckIn)]
140131
public void TestGetAccountType()
141132
{
142-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetAzureRmCognitiveServicesAccountType");
133+
TestRunner.RunTestScript("Test-GetAzureRmCognitiveServicesAccountType");
143134
}
144135

145136
[Fact]
146137
[Trait(Category.AcceptanceType, Category.CheckIn)]
147138
public void TestPipingToGetKey()
148139
{
149-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-PipingGetAccountToGetKey");
140+
TestRunner.RunTestScript("Test-PipingGetAccountToGetKey");
150141
}
151142

152143
[Fact]
153144
[Trait(Category.AcceptanceType, Category.CheckIn)]
154145
public void TestPipingToSetAccount()
155146
{
156-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-PipingToSetAzureAccount");
147+
TestRunner.RunTestScript("Test-PipingToSetAzureAccount");
157148
}
158149

159150
[Fact]
160151
[Trait(Category.AcceptanceType, Category.CheckIn)]
161152
public void TestMinMaxAccountNames()
162153
{
163-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-MinMaxAccountName");
154+
TestRunner.RunTestScript("Test-MinMaxAccountName");
164155
}
165156

166157

167158
[Fact]
168159
[Trait(Category.AcceptanceType, Category.CheckIn)]
169160
public void TestGetUsages()
170161
{
171-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-GetUsages");
162+
TestRunner.RunTestScript("Test-GetUsages");
172163
}
173164

174165
[Fact]
175166
[Trait(Category.AcceptanceType, Category.CheckIn)]
176167
public void TestManagedIdentity()
177168
{
178-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-ManagedIdentity");
169+
TestRunner.RunTestScript("Test-ManagedIdentity");
179170
}
180171

181172
[Fact]
182173
[Trait(Category.AcceptanceType, Category.CheckIn)]
183174
public void TestUserAssignedIdentity()
184175
{
185-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-UserAssignedIdentity");
176+
TestRunner.RunTestScript("Test-UserAssignedIdentity");
186177
}
187178

188179
[Fact]
189180
[Trait(Category.AcceptanceType, Category.CheckIn)]
190181
public void TestEncryption()
191182
{
192-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-Encryption");
183+
TestRunner.RunTestScript("Test-Encryption");
193184
}
194185

195186
[Fact]
196187
[Trait(Category.AcceptanceType, Category.CheckIn)]
197188
public void TestUserOwnedStorage()
198189
{
199-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-UserOwnedStorage");
190+
TestRunner.RunTestScript("Test-UserOwnedStorage");
200191
}
201192

202193
[Fact]
203194
[Trait(Category.AcceptanceType, Category.CheckIn)]
204195
public void TestPrivateEndpoint()
205196
{
206-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-PrivateEndpoint");
197+
TestRunner.RunTestScript("Test-PrivateEndpoint");
207198
}
208199

209200
[Fact]
210201
[Trait(Category.AcceptanceType, Category.CheckIn)]
211202
public void TestPublicNetworkAccess()
212203
{
213-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-PublicNetworkAccess");
204+
TestRunner.RunTestScript("Test-PublicNetworkAccess");
214205
}
215206

216207
[Fact]
217208
[Trait(Category.AcceptanceType, Category.CheckIn)]
218209
public void TestRestrictOutboundNetworkAccess()
219210
{
220-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-RestrictOutboundNetworkAccess");
211+
TestRunner.RunTestScript("Test-RestrictOutboundNetworkAccess");
221212
}
222213

223214
[Fact]
224215
[Trait(Category.AcceptanceType, Category.CheckIn)]
225216
public void TestDisableLocalAuth()
226217
{
227-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-DisableLocalAuth");
218+
TestRunner.RunTestScript("Test-DisableLocalAuth");
228219
}
229220

230221
[Fact]
231222
[Trait(Category.AcceptanceType, Category.CheckIn)]
232223
public void TestCapabilities()
233224
{
234-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-Capabilities");
225+
TestRunner.RunTestScript("Test-Capabilities");
235226
}
236227

237228
[Fact]
238229
[Trait(Category.AcceptanceType, Category.CheckIn)]
239230
public void TestApiProperties()
240231
{
241-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-ApiProperties");
232+
TestRunner.RunTestScript("Test-ApiProperties");
242233
}
243234

244235
[Fact]
245236
[Trait(Category.AcceptanceType, Category.CheckIn)]
246237
public void TestSoftDelete()
247238
{
248-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-SoftDelete");
239+
TestRunner.RunTestScript("Test-SoftDelete");
249240
}
250241

251242
[Fact]
252243
[Trait(Category.AcceptanceType, Category.CheckIn)]
253244
public void TestCommitmentPlan()
254245
{
255-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-CommitmentPlan");
246+
TestRunner.RunTestScript("Test-CommitmentPlan");
256247
}
257248

258249
[Fact]
259250
[Trait(Category.AcceptanceType, Category.CheckIn)]
260251
public void TestDeployment()
261252
{
262-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-Deployment");
253+
TestRunner.RunTestScript("Test-Deployment");
263254
}
264255

265256
[Fact]
266257
[Trait(Category.AcceptanceType, Category.CheckIn)]
267258
public void TestListModels()
268259
{
269-
TestController.NewInstance.RunPsTest(traceInterceptor, "Test-ListModels");
260+
TestRunner.RunTestScript("Test-ListModels");
270261
}
271262
}
272263
}
Lines changed: 57 additions & 0 deletions
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.Management.CognitiveServices.Test.ScenarioTests
20+
{
21+
public class CognitiveServicesTestRunner
22+
{
23+
protected readonly ITestRunner TestRunner;
24+
25+
protected CognitiveServicesTestRunner(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.RMNetworkModule,
39+
helper.GetRMModulePath("Az.CognitiveServices.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/CognitiveServices/CognitiveServices.Test/ScenarioTests/CognitiveServicesUtilsTests.cs

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

15-
1615
using Microsoft.Azure.Commands.Management.CognitiveServices;
17-
using Microsoft.Azure.Commands.ScenarioTest;
18-
using Microsoft.Azure.ServiceManagement.Common.Models;
16+
using Microsoft.Azure.Commands.Management.CognitiveServices.Test.ScenarioTests;
1917
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2118
using Xunit;
2219
using Xunit.Abstractions;
2320

2421
namespace CognitiveServices.Test.ScenarioTests
2522
{
26-
public class CognitiveServicesUtilsTests : RMTestBase
23+
public class CognitiveServicesUtilsTests : CognitiveServicesTestRunner
2724
{
28-
XunitTracingInterceptor traceInterceptor;
29-
30-
public CognitiveServicesUtilsTests(ITestOutputHelper output)
25+
public CognitiveServicesUtilsTests(ITestOutputHelper output) : base(output)
3126
{
32-
this.traceInterceptor = new XunitTracingInterceptor(output);
33-
XunitTracingInterceptor.AddToContext(this.traceInterceptor);
34-
TestExecutionHelpers.SetUpSessionAndProfile();
3527
}
28+
3629
[Fact]
3730
[Trait(Category.AcceptanceType, Category.CheckIn)]
3831
public void TestUtils()

0 commit comments

Comments
 (0)