Skip to content

Commit 68bb5f2

Browse files
author
maddieclayton
authored
Merge pull request #5225 from bganapa/stack-network-test-pr
Stack: Network module scenario tests
2 parents a0e33ed + f3eceaf commit 68bb5f2

File tree

34 files changed

+14695
-10330
lines changed

34 files changed

+14695
-10330
lines changed

src/ResourceManager/Network/Stack/Commands.Network.Test/Commands.Network.Test.csproj

Lines changed: 19 additions & 145 deletions
Large diffs are not rendered by default.

src/ResourceManager/Network/Stack/Commands.Network.Test/NetworkResourcesController.cs

Lines changed: 50 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,18 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.Common.Authentication;
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
1618
using Microsoft.Azure.Gallery;
1719
using Microsoft.Azure.Management.Authorization;
18-
using Microsoft.Azure.Management.Compute;
19-
using Microsoft.Azure.Management.Insights;
2020
using Microsoft.Azure.Management.Network;
21-
using Microsoft.Azure.Management.Redis;
2221
using Microsoft.Azure.Management.Resources;
23-
using Microsoft.Azure.Management.Storage;
2422
using Microsoft.Azure.Subscriptions;
23+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2524
using Microsoft.Azure.Test;
25+
using Microsoft.Azure.Commands.Common.Authentication;
2626
using Microsoft.Azure.Test.HttpRecorder;
27-
using Microsoft.WindowsAzure.Commands.ScenarioTest;
28-
using System;
29-
using System.Collections.Generic;
30-
using System.IO;
31-
using System.Linq;
3227
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
3328

3429
namespace Commands.Network.Test
@@ -37,7 +32,7 @@ public sealed class NetworkResourcesController
3732
{
3833
private CSMTestEnvironmentFactory csmTestFactory;
3934
private EnvironmentSetupHelper helper;
40-
35+
4136
public ResourceManagementClient ResourceManagementClient { get; private set; }
4237

4338
public SubscriptionClient SubscriptionClient { get; private set; }
@@ -48,16 +43,11 @@ public sealed class NetworkResourcesController
4843

4944
public NetworkManagementClient NetworkManagementClient { get; private set; }
5045

51-
public ComputeManagementClient ComputeManagementClient { get; private set; }
46+
public Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient InternalResourceManagementClient { get; private set; }
47+
public Microsoft.Azure.Management.ResourceManager.ResourceManagementClient LegacyResourceManagementClient { get; private set; }
5248

53-
public StorageManagementClient StorageManagementClient { get; private set; }
54-
55-
public InsightsManagementClient InsightsManagementClient { get; private set; }
56-
57-
public RedisManagementClient RedisManagementClient { get; private set; }
58-
59-
public static NetworkResourcesController NewInstance
60-
{
49+
public static NetworkResourcesController NewInstance
50+
{
6151
get
6252
{
6353
return new NetworkResourcesController();
@@ -71,64 +61,60 @@ public NetworkResourcesController()
7161

7262
public void RunPsTest(params string[] scripts)
7363
{
74-
Dictionary<string, string> d = new Dictionary<string, string>();
75-
d.Add("Microsoft.Resources", null);
76-
d.Add("Microsoft.Features", null);
77-
d.Add("Microsoft.Authorization", null);
78-
d.Add("Microsoft.Storage", null);
79-
var providersToIgnore = new Dictionary<string, string>();
80-
providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
81-
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore);
82-
8364
var callingClassType = TestUtilities.GetCallingClass(2);
8465
var mockName = TestUtilities.GetCurrentMethodName(2);
8566

8667
RunPsTestWorkflow(
87-
() => scripts,
68+
() => scripts,
8869
// no custom initializer
89-
null,
70+
null,
9071
// no custom cleanup
9172
null,
9273
callingClassType,
9374
mockName);
9475
}
9576

9677
public void RunPsTestWorkflow(
97-
Func<string[]> scriptBuilder,
98-
Action<CSMTestEnvironmentFactory> initialize,
78+
Func<string[]> scriptBuilder,
79+
Action<CSMTestEnvironmentFactory> initialize,
9980
Action cleanup,
10081
string callingClassType,
10182
string mockName)
10283
{
103-
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
84+
Dictionary<string, string> d = new Dictionary<string, string>();
85+
d.Add("Microsoft.Resources", null);
86+
d.Add("Microsoft.Features", null);
87+
d.Add("Microsoft.Authorization", null);
88+
d.Add("Microsoft.Compute", null);
89+
var providersToIgnore = new Dictionary<string, string>();
90+
providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
91+
providersToIgnore.Add("Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2016-02-01");
92+
providersToIgnore.Add("Microsoft.Azure.Management.Storage.StorageManagementClient", "2015-06-15");
93+
94+
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore);
95+
10496
using (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(callingClassType, mockName))
10597
{
10698
this.csmTestFactory = new CSMTestEnvironmentFactory();
10799

108-
if (initialize != null)
100+
if(initialize != null)
109101
{
110102
initialize(this.csmTestFactory);
111103
}
112104

113105
SetupManagementClients(context);
114106

115107
helper.SetupEnvironment(AzureModule.AzureResourceManager);
116-
108+
117109
var callingClassName = callingClassType
118110
.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
119111
.Last();
120-
helper.SetupModules(AzureModule.AzureResourceManager,
121-
"ScenarioTests\\Common.ps1",
122-
"ScenarioTests\\" + callingClassName + ".ps1",
123-
helper.RMProfileModule,
124-
helper.RMResourceModule,
125-
helper.GetRMModulePath("AzureRM.Insights.psd1"),
126-
helper.GetRMModulePath("AzureRM.RedisCache.psd1"),
127-
helper.GetRMModulePath("AzureRM.Network.psd1"),
128-
helper.GetRMModulePath("AzureRM.Compute.psd1"),
129-
helper.RMStorageDataPlaneModule,
130-
"AzureRM.Storage.ps1",
131-
"AzureRM.Resources.ps1");
112+
helper.SetupModules(AzureModule.AzureResourceManager,
113+
"ScenarioTests\\Common.ps1",
114+
"ScenarioTests\\" + callingClassName + ".ps1",
115+
helper.StackRMProfileModule,
116+
helper.StackRMResourceModule,
117+
helper.GetStackRMModulePath("AzureRM.Network.psd1"));
132118

133119
try
134120
{
@@ -144,53 +130,32 @@ public void RunPsTestWorkflow(
144130
}
145131
finally
146132
{
147-
if (cleanup != null)
133+
if(cleanup !=null)
148134
{
149135
cleanup();
150136
}
151137
}
152138
}
153139
}
154140

155-
private Microsoft.Azure.Management.Resources.ResourceManagementClient GetLegacyResourceManagementClient()
156-
{
157-
return Microsoft.Azure.Test.TestBase.GetServiceClient<Microsoft.Azure.Management.Resources.ResourceManagementClient>(this.csmTestFactory);
158-
}
159-
160-
private Microsoft.Azure.Subscriptions.SubscriptionClient GetLegacySubscriptionClient()
161-
{
162-
return Microsoft.Azure.Test.TestBase.GetServiceClient<Microsoft.Azure.Subscriptions.SubscriptionClient>(this.csmTestFactory);
163-
}
164-
165-
private Microsoft.Azure.Management.ResourceManager.ResourceManagementClient GetResourceManagerResourceManagementClient(RestTestFramework.MockContext context)
166-
{
167-
return context.GetServiceClient<Microsoft.Azure.Management.ResourceManager.ResourceManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
168-
}
169-
170141
private void SetupManagementClients(RestTestFramework.MockContext context)
171142
{
172-
Microsoft.Azure.Management.ResourceManager.ResourceManagementClient ResourceManagerResourceManagementClient = GetResourceManagerResourceManagementClient(context);
173143
this.ResourceManagementClient = this.GetResourceManagementClient();
174144
this.SubscriptionClient = this.GetSubscriptionClient();
145+
InternalResourceManagementClient = GetInternalResourceManagementClient(context);
146+
LegacyResourceManagementClient = GetLegacyResourceManagementClient(context);
175147
this.GalleryClient = this.GetGalleryClient();
176148
this.NetworkManagementClient = this.GetNetworkManagementClient(context);
177-
this.ComputeManagementClient = this.GetComputeManagementClient(context);
178-
this.StorageManagementClient = this.GetStorageManagementClient(context);
179149
this.AuthorizationManagementClient = this.GetAuthorizationManagementClient();
180-
this.InsightsManagementClient = this.GetInsightsManagementClient();
181-
this.RedisManagementClient = this.GetRedisManagementClient(context);
182150

183151
helper.SetupManagementClients(
184-
ResourceManagerResourceManagementClient,
185152
ResourceManagementClient,
153+
InternalResourceManagementClient,
154+
LegacyResourceManagementClient,
186155
SubscriptionClient,
187156
GalleryClient,
188-
this.NetworkManagementClient,
189-
this.ComputeManagementClient,
190-
this.StorageManagementClient,
191-
this.AuthorizationManagementClient,
192-
this.InsightsManagementClient,
193-
this.RedisManagementClient);
157+
AuthorizationManagementClient,
158+
this.NetworkManagementClient);
194159
}
195160

196161
private AuthorizationManagementClient GetAuthorizationManagementClient()
@@ -202,6 +167,15 @@ private ResourceManagementClient GetResourceManagementClient()
202167
{
203168
return TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
204169
}
170+
private Microsoft.Azure.Management.ResourceManager.ResourceManagementClient GetLegacyResourceManagementClient(RestTestFramework.MockContext context)
171+
{
172+
return context.GetServiceClient<Microsoft.Azure.Management.ResourceManager.ResourceManagementClient>(Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory.GetTestEnvironment());
173+
}
174+
175+
private Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient GetInternalResourceManagementClient(RestTestFramework.MockContext context)
176+
{
177+
return context.GetServiceClient<Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient>(Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory.GetTestEnvironment());
178+
}
205179

206180
private SubscriptionClient GetSubscriptionClient()
207181
{
@@ -212,30 +186,9 @@ private NetworkManagementClient GetNetworkManagementClient(RestTestFramework.Moc
212186
{
213187
return context.GetServiceClient<NetworkManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
214188
}
215-
216-
private StorageManagementClient GetStorageManagementClient(RestTestFramework.MockContext context)
217-
{
218-
return context.GetServiceClient<StorageManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
219-
}
220-
221189
private GalleryClient GetGalleryClient()
222190
{
223191
return TestBase.GetServiceClient<GalleryClient>(this.csmTestFactory);
224192
}
225-
226-
private InsightsManagementClient GetInsightsManagementClient()
227-
{
228-
return TestBase.GetServiceClient<InsightsManagementClient>(this.csmTestFactory);
229-
}
230-
231-
private RedisManagementClient GetRedisManagementClient(RestTestFramework.MockContext context)
232-
{
233-
return context.GetServiceClient<RedisManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
234-
}
235-
236-
private ComputeManagementClient GetComputeManagementClient(RestTestFramework.MockContext context)
237-
{
238-
return context.GetServiceClient<ComputeManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
239-
}
240193
}
241194
}

src/ResourceManager/Network/Stack/Commands.Network.Test/ScenarioTests/ApplicationGatewayTests.cs

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)