Skip to content

Commit e735ed7

Browse files
committed
Update DnsTestsBase class
Update DnsTestsBase class to match the latest test framework
1 parent 17fc468 commit e735ed7

File tree

4 files changed

+208
-73
lines changed

4 files changed

+208
-73
lines changed

src/ResourceManager/Dns/Commands.Dns.Test/Commands.Dns.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
<SpecificVersion>False</SpecificVersion>
5454
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.0.21-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
5555
</Reference>
56+
<Reference Include="Microsoft.Azure.Gallery, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57+
<SpecificVersion>False</SpecificVersion>
58+
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
59+
</Reference>
5660
<Reference Include="Microsoft.Azure.Management.Authorization, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5761
<SpecificVersion>False</SpecificVersion>
5862
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.0.18.0-preview\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/DnsTestsBase.cs

Lines changed: 177 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,182 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Common.Authentication;
16-
using Microsoft.Azure.Management.Resources;
17-
using Microsoft.Azure.Test;
18-
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19-
using Microsoft.WindowsAzure.Commands.Utilities.Common;
20-
2115
namespace Microsoft.Azure.Commands.ScenarioTest.DnsTests
2216
{
23-
public class DnsTestsBase
24-
{
25-
private EnvironmentSetupHelper helper;
26-
27-
protected DnsTestsBase()
28-
{
29-
helper = new EnvironmentSetupHelper();
30-
}
31-
32-
protected void SetupManagementClients()
33-
{
34-
var resourcesClient = GetResourcesClient();
35-
helper.SetupSomeOfManagementClients(resourcesClient);
36-
}
37-
38-
protected void RunPowerShellTest(params string[] scripts)
39-
{
40-
// Enable undo functionality as well as mock recording
41-
using (UndoContext context = UndoContext.Current)
42-
{
43-
// Configure recordings
44-
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));
45-
46-
SetupManagementClients();
47-
48-
helper.SetupEnvironment(AzureModule.AzureResourceManager);
49-
50-
helper.SetupModules(AzureModule.AzureProfile, "ScenarioTests\\Common.ps1",
51-
"ScenarioTests\\" + this.GetType().Name + ".ps1");
52-
53-
helper.RunPowerShellTest(scripts);
54-
}
55-
}
56-
57-
protected ResourceManagementClient GetResourcesClient()
58-
{
59-
return TestBase.GetServiceClient<ResourceManagementClient>(new CSMTestEnvironmentFactory());
60-
}
61-
}
62-
}
17+
using System;
18+
using System.Linq;
19+
using Microsoft.Azure.Common.Authentication;
20+
using Microsoft.Azure.Gallery;
21+
using Microsoft.Azure.Management.Authorization;
22+
using Microsoft.Azure.Management.Resources;
23+
using Microsoft.Azure.Subscriptions.Csm;
24+
using Microsoft.Azure.Test;
25+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
26+
using Microsoft.Azure.Commands.Dns.Models;
27+
28+
29+
public class DnsTestsBase
30+
{
31+
private CSMTestEnvironmentFactory csmTestFactory;
32+
33+
34+
private readonly EnvironmentSetupHelper helper;
35+
36+
37+
public ResourceManagementClient ResourceManagementClient { get; private set; }
38+
39+
40+
public SubscriptionClient SubscriptionClient { get; private set; }
41+
42+
43+
public GalleryClient GalleryClient { get; private set; }
44+
45+
46+
public AuthorizationManagementClient AuthorizationManagementClient { get; private set; }
47+
48+
49+
public DnsClient DnsClient { get; private set; }
50+
51+
52+
public static DnsTestsBase NewInstance
53+
{
54+
get
55+
{
56+
return new DnsTestsBase();
57+
}
58+
}
59+
60+
61+
protected DnsTestsBase()
62+
{
63+
this.helper = new EnvironmentSetupHelper();
64+
}
65+
66+
67+
protected void SetupManagementClients()
68+
{
69+
this.ResourceManagementClient = this.GetResourceManagementClient();
70+
this.SubscriptionClient = this.GetSubscriptionClient();
71+
this.GalleryClient = this.GetGalleryClient();
72+
this.AuthorizationManagementClient = this.GetAuthorizationManagementClient();
73+
this.DnsClient = this.GetFeatureClient();
74+
75+
76+
this.helper.SetupManagementClients(
77+
this.ResourceManagementClient,
78+
this.SubscriptionClient,
79+
this.GalleryClient,
80+
this.AuthorizationManagementClient,
81+
this.DnsClient);
82+
}
83+
84+
85+
public void RunPowerShellTest(params string[] scripts)
86+
{
87+
string callingClassType = TestUtilities.GetCallingClass(2);
88+
string mockName = TestUtilities.GetCurrentMethodName(2);
89+
90+
91+
this.RunPsTestWorkflow(
92+
() => scripts,
93+
// no custom initializer
94+
null,
95+
// no custom cleanup
96+
null,
97+
callingClassType,
98+
mockName);
99+
}
100+
101+
102+
public void RunPsTestWorkflow(
103+
Func<string[]> scriptBuilder,
104+
Action<CSMTestEnvironmentFactory> initialize,
105+
Action cleanup,
106+
string callingClassType,
107+
string mockName)
108+
{
109+
using (UndoContext context = UndoContext.Current)
110+
{
111+
context.Start(callingClassType, mockName);
112+
113+
114+
this.csmTestFactory = new CSMTestEnvironmentFactory();
115+
116+
117+
if (initialize != null)
118+
{
119+
initialize(this.csmTestFactory);
120+
}
121+
122+
123+
this.SetupManagementClients();
124+
125+
126+
this.helper.SetupEnvironment(AzureModule.AzureResourceManager);
127+
128+
129+
string callingClassName = callingClassType
130+
.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
131+
.Last();
132+
133+
134+
this.helper.SetupModules(
135+
AzureModule.AzureResourceManager,
136+
"ScenarioTests\\Common.ps1",
137+
"ScenarioTests\\" + callingClassName + ".ps1");
138+
139+
140+
try
141+
{
142+
if (scriptBuilder != null)
143+
{
144+
string[] psScripts = scriptBuilder();
145+
146+
147+
if (psScripts != null)
148+
{
149+
this.helper.RunPowerShellTest(psScripts);
150+
}
151+
}
152+
}
153+
finally
154+
{
155+
if (cleanup != null)
156+
{
157+
cleanup();
158+
}
159+
}
160+
}
161+
}
162+
163+
164+
protected ResourceManagementClient GetResourceManagementClient()
165+
{
166+
return TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
167+
}
168+
169+
170+
private AuthorizationManagementClient GetAuthorizationManagementClient()
171+
{
172+
return TestBase.GetServiceClient<AuthorizationManagementClient>(this.csmTestFactory);
173+
}
174+
175+
176+
private SubscriptionClient GetSubscriptionClient()
177+
{
178+
return TestBase.GetServiceClient<SubscriptionClient>(this.csmTestFactory);
179+
}
180+
181+
182+
private GalleryClient GetGalleryClient()
183+
{
184+
return TestBase.GetServiceClient<GalleryClient>(this.csmTestFactory);
185+
}
186+
187+
188+
private DnsClient GetFeatureClient()
189+
{
190+
return TestBase.GetServiceClient<DnsClient>(this.csmTestFactory);
191+
}
192+
}
193+
}

src/ResourceManager/Dns/Commands.Dns.Test/ScenarioTests/RecordsTests.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,126 +24,126 @@ public class RecordsTests : DnsTestsBase
2424
[Trait(Category.AcceptanceType, Category.CheckIn)]
2525
public void TestRecordSetCrud()
2626
{
27-
RunPowerShellTest("Test-RecordSetCrud");
27+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetCrud");
2828
}
2929

3030
[Fact]
3131
[Trait(Category.AcceptanceType, Category.CheckIn)]
3232
public void TestRecordSetCrudWithPiping()
3333
{
34-
RunPowerShellTest("Test-RecordSetCrudWithPiping");
34+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetCrudWithPiping");
3535
}
3636

3737
[Fact]
3838
[Trait(Category.AcceptanceType, Category.CheckIn)]
3939
public void TestRecordSetA()
4040
{
41-
RunPowerShellTest("Test-RecordSetA");
41+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetA");
4242
}
4343

4444
[Fact]
4545
[Trait(Category.AcceptanceType, Category.CheckIn)]
4646
public void TestRecordSetAAAA()
4747
{
48-
RunPowerShellTest("Test-RecordSetAAAA");
48+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetAAAA");
4949
}
5050

5151
[Fact]
5252
[Trait(Category.AcceptanceType, Category.CheckIn)]
5353
public void TestRecordSetCNAME()
5454
{
55-
RunPowerShellTest("Test-RecordSetCNAME");
55+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetCNAME");
5656
}
5757

5858
[Fact]
5959
[Trait(Category.AcceptanceType, Category.CheckIn)]
6060
public void TestRecordSetMX()
6161
{
62-
RunPowerShellTest("Test-RecordSetMX");
62+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetMX");
6363
}
6464

6565
[Fact]
6666
[Trait(Category.AcceptanceType, Category.CheckIn)]
6767
public void TestRecordSetNS()
6868
{
69-
RunPowerShellTest("Test-RecordSetNS");
69+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetNS");
7070
}
7171

7272
[Fact]
7373
[Trait(Category.AcceptanceType, Category.CheckIn)]
7474
public void TestRecordSetTXT()
7575
{
76-
RunPowerShellTest("Test-RecordSetTXT");
76+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetTXT");
7777
}
7878

7979
[Fact]
8080
[Trait(Category.AcceptanceType, Category.CheckIn)]
8181
public void TestRecordSetSRV()
8282
{
83-
RunPowerShellTest("Test-RecordSetSRV");
83+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetSRV");
8484
}
8585

8686
[Fact]
8787
[Trait(Category.AcceptanceType, Category.CheckIn)]
8888
public void TestRecordSetSOA()
8989
{
90-
RunPowerShellTest("Test-RecordSetSOA");
90+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetSOA");
9191
}
9292

9393
[Fact(Skip = "Not supported in Private Preview")]
9494
[Trait(Category.AcceptanceType, Category.CheckIn)]
9595
public void TestRecordSetPTR()
9696
{
97-
RunPowerShellTest("Test-RecordSetPTR");
97+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetPTR");
9898
}
9999

100100
[Fact(Skip = "If-None-Match header not supported yet on service")]
101101
[Trait(Category.AcceptanceType, Category.CheckIn)]
102102
public void TestRecordSetnewAlreadyExists()
103103
{
104-
RunPowerShellTest("Test-RecordSetnewAlreadyExists");
104+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetnewAlreadyExists");
105105
}
106106

107107
[Fact]
108108
[Trait(Category.AcceptanceType, Category.CheckIn)]
109109
public void TestRecordSetAddRecordTypeMismatch()
110110
{
111-
RunPowerShellTest("Test-RecordSetAddRecordTypeMismatch");
111+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetAddRecordTypeMismatch");
112112
}
113113

114114
[Fact]
115115
[Trait(Category.AcceptanceType, Category.CheckIn)]
116116
public void TestRecordSetAddTwoCnames()
117117
{
118-
RunPowerShellTest("Test-RecordSetAddTwoCnames");
118+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetAddTwoCnames");
119119
}
120120

121121
[Fact]
122122
[Trait(Category.AcceptanceType, Category.CheckIn)]
123123
public void TestRecordSetRemoveRecordTypeMismatch()
124124
{
125-
RunPowerShellTest("Test-RecordSetRemoveRecordTypeMismatch");
125+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetRemoveRecordTypeMismatch");
126126
}
127127

128128
[Fact]
129129
[Trait(Category.AcceptanceType, Category.CheckIn)]
130130
public void TestRecordSetEtagMismatch()
131131
{
132-
RunPowerShellTest("Test-RecordSetEtagMismatch");
132+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetEtagMismatch");
133133
}
134134

135135
[Fact]
136136
[Trait(Category.AcceptanceType, Category.CheckIn)]
137137
public void TestRecordSetGet()
138138
{
139-
RunPowerShellTest("Test-RecordSetGet");
139+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetGet");
140140
}
141141

142142
[Fact]
143143
[Trait(Category.AcceptanceType, Category.CheckIn)]
144144
public void TestRecordSetGetWithEndsWith()
145145
{
146-
RunPowerShellTest("Test-RecordSetGetWithEndsWith");
146+
DnsTestsBase.NewInstance.RunPowerShellTest("Test-RecordSetGetWithEndsWith");
147147
}
148148
}
149149
}

0 commit comments

Comments
 (0)