Skip to content

Commit a4fb790

Browse files
committed
TrafficManager tests running in Az.
1 parent e50daee commit a4fb790

File tree

4 files changed

+71
-99
lines changed

4 files changed

+71
-99
lines changed

src/Azure.PowerShell.Netcore.Test.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commands.ServiceBus.Test.Ne
4949
EndProject
5050
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commands.ServiceFabric.Test.Netcore", "ResourceManager\ServiceFabric\Commands.ServiceFabric.Test\Commands.ServiceFabric.Test.Netcore.csproj", "{7D025377-637F-4F3D-9657-5079045AEBFB}"
5151
EndProject
52+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commands.TrafficManager.Test.Netcore", "ResourceManager\TrafficManager\Commands.TrafficManager2.Test\Commands.TrafficManager.Test.Netcore.csproj", "{9AB72517-E580-430C-9284-8EB271093CEA}"
53+
EndProject
5254
Global
5355
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5456
Debug|Any CPU = Debug|Any CPU
@@ -335,6 +337,18 @@ Global
335337
{7D025377-637F-4F3D-9657-5079045AEBFB}.Release|x64.Build.0 = Release|Any CPU
336338
{7D025377-637F-4F3D-9657-5079045AEBFB}.Release|x86.ActiveCfg = Release|Any CPU
337339
{7D025377-637F-4F3D-9657-5079045AEBFB}.Release|x86.Build.0 = Release|Any CPU
340+
{9AB72517-E580-430C-9284-8EB271093CEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
341+
{9AB72517-E580-430C-9284-8EB271093CEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
342+
{9AB72517-E580-430C-9284-8EB271093CEA}.Debug|x64.ActiveCfg = Debug|Any CPU
343+
{9AB72517-E580-430C-9284-8EB271093CEA}.Debug|x64.Build.0 = Debug|Any CPU
344+
{9AB72517-E580-430C-9284-8EB271093CEA}.Debug|x86.ActiveCfg = Debug|Any CPU
345+
{9AB72517-E580-430C-9284-8EB271093CEA}.Debug|x86.Build.0 = Debug|Any CPU
346+
{9AB72517-E580-430C-9284-8EB271093CEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
347+
{9AB72517-E580-430C-9284-8EB271093CEA}.Release|Any CPU.Build.0 = Release|Any CPU
348+
{9AB72517-E580-430C-9284-8EB271093CEA}.Release|x64.ActiveCfg = Release|Any CPU
349+
{9AB72517-E580-430C-9284-8EB271093CEA}.Release|x64.Build.0 = Release|Any CPU
350+
{9AB72517-E580-430C-9284-8EB271093CEA}.Release|x86.ActiveCfg = Release|Any CPU
351+
{9AB72517-E580-430C-9284-8EB271093CEA}.Release|x86.Build.0 = Release|Any CPU
338352
EndGlobalSection
339353
GlobalSection(SolutionProperties) = preSolution
340354
HideSolutionNode = FALSE

src/ResourceManager/TrafficManager/Commands.TrafficManager2.Test/Commands.TrafficManager.Test.Netcore.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1010
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1111
<WarningsAsErrors />
12+
<IsPackable>false</IsPackable>
1213
</PropertyGroup>
1314

1415
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -23,6 +24,16 @@
2324
<DefineConstants>TRACE;RELEASE;NETSTANDARD;SIGN</DefineConstants>
2425
</PropertyGroup>
2526

27+
<ItemGroup Condition="'$(TargetFramework)' != 'net472'">
28+
<PackageReference Include="Microsoft.Azure.Management.TrafficManager" Version="2.5.0" />
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<Reference Include="Microsoft.Azure.Commands.TrafficManager">
33+
<HintPath>..\..\..\Package\$(Configuration)\ResourceManager\AzureResourceManager\Az.TrafficManager\Microsoft.Azure.Commands.TrafficManager.dll</HintPath>
34+
</Reference>
35+
</ItemGroup>
36+
2637
<ItemGroup>
2738
<None Update="SessionRecords\**\*.json">
2839
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

src/ResourceManager/TrafficManager/Commands.TrafficManager2.Test/ScenarioTests/TestController.cs

Lines changed: 45 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -15,80 +15,54 @@
1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Test.HttpRecorder;
1717
using System.Collections.Generic;
18+
using System.Diagnostics;
1819
using Microsoft.Azure.Management.Internal.Resources;
20+
using Microsoft.Azure.Management.TrafficManager;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
23+
using System;
24+
using System.IO;
25+
using System.Linq;
26+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
27+
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
1928

2029
namespace Microsoft.Azure.Commands.TrafficManager.Test.ScenarioTests
2130
{
22-
using Microsoft.Azure.Gallery;
23-
using Microsoft.Azure.Management.Authorization;
24-
using Microsoft.Azure.Management.TrafficManager;
25-
using Microsoft.Azure.Subscriptions;
26-
using Microsoft.Azure.Test;
27-
using Microsoft.WindowsAzure.Commands.ScenarioTest;
28-
using ServiceManagemenet.Common.Models;
29-
using System;
30-
using System.IO;
31-
using System.Linq;
32-
using WindowsAzure.Commands.Test.Utilities.Common;
33-
34-
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
35-
3631
public class TestController : RMTestBase
3732
{
38-
private CSMTestEnvironmentFactory csmTestFactory;
39-
40-
private EnvironmentSetupHelper helper;
33+
private readonly EnvironmentSetupHelper _helper;
4134

4235
public ResourceManagementClient ResourceManagementClient { get; private set; }
4336

44-
public SubscriptionClient SubscriptionClient { get; private set; }
45-
46-
public GalleryClient GalleryClient { get; private set; }
47-
48-
public AuthorizationManagementClient AuthorizationManagementClient { get; private set; }
49-
5037
public TrafficManagerManagementClient TrafficManagerManagementClient { get; private set; }
5138

52-
public static TestController NewInstance
53-
{
54-
get
55-
{
56-
return new TestController();
57-
}
58-
}
39+
public static TestController NewInstance => new TestController();
5940

6041
protected TestController()
6142
{
62-
this.helper = new EnvironmentSetupHelper();
43+
_helper = new EnvironmentSetupHelper();
6344
}
6445

6546
protected void SetupManagementClients(RestTestFramework.MockContext context)
6647
{
67-
this.ResourceManagementClient = this.GetResourceManagementClient(context);
68-
this.SubscriptionClient = this.GetSubscriptionClient();
69-
this.GalleryClient = this.GetGalleryClient();
70-
this.AuthorizationManagementClient = this.GetAuthorizationManagementClient();
71-
this.TrafficManagerManagementClient = this.GetFeatureClient(context);
72-
73-
this.helper.SetupManagementClients(
74-
this.ResourceManagementClient,
75-
this.SubscriptionClient,
76-
this.GalleryClient,
77-
this.AuthorizationManagementClient,
78-
this.TrafficManagerManagementClient);
48+
ResourceManagementClient = GetResourceManagementClient(context);
49+
TrafficManagerManagementClient = GetFeatureClient(context);
50+
51+
_helper.SetupManagementClients(
52+
ResourceManagementClient,
53+
TrafficManagerManagementClient);
7954
}
8055

8156
public void RunPowerShellTest(XunitTracingInterceptor logger, params string[] scripts)
8257
{
83-
string callingClassType = TestUtilities.GetCallingClass(2);
84-
string mockName = TestUtilities.GetCurrentMethodName(2);
58+
var sf = new StackTrace().GetFrame(1);
59+
var callingClassType = sf.GetMethod().ReflectedType?.ToString();
60+
var mockName = sf.GetMethod().Name;
8561

86-
helper.TracingInterceptor = logger;
62+
_helper.TracingInterceptor = logger;
8763

88-
this.RunPsTestWorkflow(
64+
RunPsTestWorkflow(
8965
() => scripts,
90-
// no custom initializer
91-
null,
9266
// no custom cleanup
9367
null,
9468
callingClassType,
@@ -97,62 +71,49 @@ public void RunPowerShellTest(XunitTracingInterceptor logger, params string[] sc
9771

9872
public void RunPsTestWorkflow(
9973
Func<string[]> scriptBuilder,
100-
Action<CSMTestEnvironmentFactory> initialize,
10174
Action cleanup,
10275
string callingClassType,
10376
string mockName)
10477
{
105-
Dictionary<string, string> d = new Dictionary<string, string>();
106-
d.Add("Microsoft.Resources", null);
107-
d.Add("Microsoft.Features", null);
108-
d.Add("Microsoft.Authorization", null);
109-
var providersToIgnore = new Dictionary<string, string>();
110-
providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
78+
var d = new Dictionary<string, string>
79+
{
80+
{"Microsoft.Resources", null},
81+
{"Microsoft.Features", null},
82+
{"Microsoft.Authorization", null}
83+
};
84+
var providersToIgnore = new Dictionary<string, string>
85+
{
86+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"}
87+
};
11188
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore);
11289

11390
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
114-
using (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(callingClassType, mockName))
91+
using (var context = RestTestFramework.MockContext.Start(callingClassType, mockName))
11592
{
116-
this.csmTestFactory = new CSMTestEnvironmentFactory();
93+
_helper.SetupEnvironment(AzureModule.AzureResourceManager);
11794

118-
if (initialize != null)
119-
{
120-
initialize(this.csmTestFactory);
121-
}
95+
SetupManagementClients(context);
12296

123-
this.helper.SetupEnvironment(AzureModule.AzureResourceManager);
97+
var callingClassName = callingClassType.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
12498

125-
this.SetupManagementClients(context);
126-
127-
string callingClassName = callingClassType
128-
.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
129-
.Last();
130-
131-
this.helper.SetupModules(AzureModule.AzureResourceManager,
99+
_helper.SetupModules(AzureModule.AzureResourceManager,
132100
"ScenarioTests\\Common.ps1",
133101
"ScenarioTests\\" + callingClassName + ".ps1",
134-
helper.RMProfileModule,
135-
helper.GetRMModulePath(@"AzureRM.TrafficManager.psd1"),
102+
_helper.RMProfileModule,
103+
_helper.GetRMModulePath(@"AzureRM.TrafficManager.psd1"),
136104
"AzureRM.Resources.ps1");
137105

138106
try
139107
{
140-
if (scriptBuilder != null)
108+
var psScripts = scriptBuilder?.Invoke();
109+
if (psScripts != null)
141110
{
142-
string[] psScripts = scriptBuilder();
143-
144-
if (psScripts != null)
145-
{
146-
this.helper.RunPowerShellTest(psScripts);
147-
}
111+
_helper.RunPowerShellTest(psScripts);
148112
}
149113
}
150114
finally
151115
{
152-
if (cleanup != null)
153-
{
154-
cleanup();
155-
}
116+
cleanup?.Invoke();
156117
}
157118
}
158119
}
@@ -162,22 +123,7 @@ protected ResourceManagementClient GetResourceManagementClient(RestTestFramework
162123
return context.GetServiceClient<ResourceManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
163124
}
164125

165-
private AuthorizationManagementClient GetAuthorizationManagementClient()
166-
{
167-
return TestBase.GetServiceClient<AuthorizationManagementClient>(this.csmTestFactory);
168-
}
169-
170-
private SubscriptionClient GetSubscriptionClient()
171-
{
172-
return TestBase.GetServiceClient<SubscriptionClient>(this.csmTestFactory);
173-
}
174-
175-
private GalleryClient GetGalleryClient()
176-
{
177-
return TestBase.GetServiceClient<GalleryClient>(this.csmTestFactory);
178-
}
179-
180-
private TrafficManagerManagementClient GetFeatureClient(RestTestFramework.MockContext context)
126+
private static TrafficManagerManagementClient GetFeatureClient(RestTestFramework.MockContext context)
181127
{
182128
return context.GetServiceClient<TrafficManagerManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
183129
}

src/TestPrerequisites/Common.Test.Prerequisites/Common.TestPrerequisites.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<PackageReference Include="Microsoft.Azure.Management.ServiceFabric" Version="1.0.0-preview" PrivateAssets="All" />
5151
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.18.0-preview" PrivateAssets="All" />
5252
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="8.1.0-preview" PrivateAssets="All" />
53+
<PackageReference Include="Microsoft.Azure.Management.TrafficManager" Version="2.5.0" PrivateAssets="All" />
5354
<PackageReference Include="Microsoft.Azure.Management.Websites" Version="2.0.0" PrivateAssets="All" />
5455
<PackageReference Include="YamlDotNet.Signed" Version="4.2.4" PrivateAssets="All" />
5556
<PackageReference Include="Moq" Version="4.7.145" />

0 commit comments

Comments
 (0)