Skip to content

Commit 4c9e0a9

Browse files
authored
Merge pull request #2993 from ericwill-msft/dev
Adding cmdlets for managing MachineLearning CommitmentPlans ARM resources
2 parents 43dd149 + 1dfaf74 commit 4c9e0a9

File tree

50 files changed

+8367
-1815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+8367
-1815
lines changed

src/ResourceManager/MachineLearning/Commands.MachineLearning.Test/Commands.MachineLearning.Test.csproj

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
6060
<Private>True</Private>
6161
</Reference>
62-
<Reference Include="..\..\..\packages\Microsoft.Azure.Management.MachineLearning.0.9.3-preview\lib\net45\Microsoft.Azure.Management.MachineLearning.dll">
62+
<Reference Include="..\..\..\packages\Microsoft.Azure.Management.MachineLearning.0.9.5-preview\lib\net45\Microsoft.Azure.Management.MachineLearning.dll">
6363
<Name>Microsoft.Azure.Management.MachineLearning</Name>
6464
<Private>True</Private>
6565
</Reference>
@@ -142,24 +142,32 @@
142142
</Reference>
143143
</ItemGroup>
144144
<ItemGroup>
145+
<Compile Include="ScenarioTests\BaseTestController.cs" />
146+
<Compile Include="ScenarioTests\CommitmentPlansTestController.cs" />
147+
<Compile Include="ScenarioTests\CommitmentPlanTests.cs" />
145148
<Compile Include="ScenarioTests\WebServicesTestController.cs" />
146149
<Compile Include="Properties\AssemblyInfo.cs" />
147150
<Compile Include="ScenarioTests\WebServiceTests.cs" />
148151
</ItemGroup>
149152
<ItemGroup>
150153
<None Include="..\..\Common\Commands.ScenarioTests.ResourceManager.Common\AzureRM.Storage.ps1">
151154
<Link>ScenarioTests\AzureRM.Storage.ps1</Link>
152-
</None>
155+
</None>
153156
<None Include="MSSharedLibKey.snk" />
154157
<None Include="packages.config">
155158
<SubType>Designer</SubType>
156159
</None>
157160
<None Include="ScenarioTests\Common.ps1">
158161
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
159162
</None>
163+
<None Include="ScenarioTests\CommitmentPlanTests.ps1">
164+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
165+
</None>
160166
<None Include="ScenarioTests\WebServiceTests.ps1">
161167
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
162168
</None>
169+
<None Include="SessionRecords\Microsoft.Azure.Commands.MachineLearning.Test.ScenarioTests.CommitmentPlanTests\TestListCommitmentPlans.json" />
170+
<None Include="SessionRecords\Microsoft.Azure.Commands.MachineLearning.Test.ScenarioTests.CommitmentPlanTests\TestUpdateCommitmentPlan.json" />
163171
<None Include="SessionRecords\Microsoft.Azure.Commands.MachineLearning.Test.ScenarioTests.WebServiceTests\TestCreateGetRemoveWebService.json">
164172
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
165173
</None>
@@ -172,6 +180,9 @@
172180
<None Include="SessionRecords\Microsoft.Azure.Commands.MachineLearning.Test.ScenarioTests.WebServiceTests\TestUpdateWebService.json">
173181
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
174182
</None>
183+
<None Include="SessionRecords\Microsoft.Azure.Commands.MachineLearning.Test.ScenarioTests.CommitmentPlanTests\TestCreateGetRemoveCommitmentPlan.json">
184+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
185+
</None>
175186
<None Include="TestData\GraphWebServiceDefinition_Dogfood.json">
176187
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
177188
</None>
@@ -200,7 +211,7 @@
200211
<Project>{e1f5201d-6067-430e-b303-4e367652991b}</Project>
201212
<Name>Commands.Resources</Name>
202213
</ProjectReference>
203-
<ProjectReference Include="..\..\Resources\Commands.ResourceManager\Cmdlets\Commands.Resources.Rest.csproj">
214+
<ProjectReference Include="..\..\Resources\Commands.ResourceManager\Cmdlets\Commands.Resources.Rest.csproj">
204215
<Project>{8058d403-06e3-4bed-8924-d166ce303961}</Project>
205216
<Name>Commands.Resources.Rest</Name>
206217
</ProjectReference>
@@ -214,4 +225,4 @@
214225
</ItemGroup>
215226
<ItemGroup />
216227
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
217-
</Project>
228+
</Project>
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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;
16+
using System.IO;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Net.Http;
20+
using System.Net.Http.Headers;
21+
using LegacyTest = Microsoft.Azure.Test;
22+
using Microsoft.Azure.Commands.Common.Authentication;
23+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
24+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
25+
using Microsoft.Azure.Gallery;
26+
using Microsoft.Azure.Management.Authorization;
27+
using Microsoft.Azure.Management.Resources;
28+
using Microsoft.Azure.Management.Storage;
29+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
30+
using Microsoft.Azure.Subscriptions;
31+
using Microsoft.Azure.Test.Authentication;
32+
using Microsoft.Azure.Test.HttpRecorder;
33+
using Microsoft.Rest;
34+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
35+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
36+
37+
namespace Microsoft.Azure.Commands.MachineLearning.Test.ScenarioTests
38+
{
39+
public abstract class BaseTestController<T> where T : ServiceClient<T>
40+
{
41+
private readonly EnvironmentSetupHelper helper;
42+
private LegacyTest.CSMTestEnvironmentFactory csmTestFactory;
43+
private T serviceClient;
44+
private ResourceManagementClient resourceManagementClient;
45+
private StorageManagementClient storageManagementClient;
46+
47+
protected BaseTestController()
48+
{
49+
this.helper = new EnvironmentSetupHelper();
50+
}
51+
52+
protected abstract T ConstructServiceClient(MockContext context);
53+
54+
public void RunPsTest(XunitTracingInterceptor logger, params string[] scripts)
55+
{
56+
var callingClassType = TestUtilities.GetCallingClass(2);
57+
var mockName = TestUtilities.GetCurrentMethodName(2);
58+
this.helper.TracingInterceptor = logger;
59+
60+
this.RunPsTestWorkflow(
61+
() => scripts,
62+
// no custom initializer
63+
null,
64+
// no custom cleanup
65+
null,
66+
callingClassType,
67+
mockName);
68+
}
69+
70+
public void RunPsTestWorkflow(
71+
Func<string[]> scriptBuilder,
72+
Action<LegacyTest.CSMTestEnvironmentFactory> initialize,
73+
Action cleanup,
74+
string callingClassType,
75+
string mockName)
76+
{
77+
var providers = new Dictionary<string, string>
78+
{
79+
{ "Microsoft.Resources", null },
80+
{ "Microsoft.Features", null },
81+
{ "Microsoft.Authorization", null }
82+
};
83+
var providersToIgnore = new Dictionary<string, string>
84+
{
85+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"}
86+
};
87+
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, providers, providersToIgnore);
88+
89+
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
90+
using (var context = MockContext.Start(callingClassType, mockName))
91+
{
92+
this.csmTestFactory = new LegacyTest.CSMTestEnvironmentFactory();
93+
if (initialize != null)
94+
{
95+
initialize(this.csmTestFactory);
96+
}
97+
98+
this.SetupManagementClients(context);
99+
helper.SetupEnvironment(AzureModule.AzureResourceManager);
100+
101+
var callingClassName = callingClassType
102+
.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
103+
.Last();
104+
105+
helper.SetupModules(AzureModule.AzureResourceManager,
106+
"ScenarioTests\\Common.ps1",
107+
"ScenarioTests\\" + callingClassName + ".ps1",
108+
helper.RMProfileModule,
109+
helper.RMResourceModule,
110+
helper.GetRMModulePath(@"AzureRM.MachineLearning.psd1"),
111+
"AzureRM.Storage.ps1",
112+
"AzureRM.Resources.ps1");
113+
114+
try
115+
{
116+
if (scriptBuilder != null)
117+
{
118+
var psScripts = scriptBuilder();
119+
120+
if (psScripts != null)
121+
{
122+
helper.RunPowerShellTest(psScripts);
123+
}
124+
}
125+
}
126+
finally
127+
{
128+
if (cleanup != null)
129+
{
130+
cleanup();
131+
}
132+
}
133+
}
134+
}
135+
136+
private void SetupManagementClients(MockContext context)
137+
{
138+
this.serviceClient = this.ConstructServiceClient(context);
139+
140+
this.resourceManagementClient = LegacyTest.TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
141+
this.storageManagementClient = LegacyTest.TestBase.GetServiceClient<StorageManagementClient>(this.csmTestFactory);
142+
var subscriptionClient = LegacyTest.TestBase.GetServiceClient<SubscriptionClient>(this.csmTestFactory);
143+
var authManagementClient = LegacyTest.TestBase.GetServiceClient<AuthorizationManagementClient>(this.csmTestFactory);
144+
var gallleryClient = LegacyTest.TestBase.GetServiceClient<GalleryClient>(this.csmTestFactory);
145+
146+
var testEnvironment = this.csmTestFactory.GetTestEnvironment();
147+
148+
var credentials = new SubscriptionCredentialsAdapter(
149+
testEnvironment.AuthorizationContext.TokenCredentials[Microsoft.Azure.Test.TokenAudience.Management],
150+
testEnvironment.SubscriptionId);
151+
152+
HttpClientHelperFactory.Instance = new TestHttpClientHelperFactory(credentials);
153+
154+
helper.SetupManagementClients(
155+
this.resourceManagementClient,
156+
subscriptionClient,
157+
this.serviceClient,
158+
authManagementClient,
159+
gallleryClient,
160+
this.storageManagementClient);
161+
}
162+
163+
/// <summary>
164+
/// The test http client helper factory.
165+
/// </summary>
166+
private class TestHttpClientHelperFactory : HttpClientHelperFactory
167+
{
168+
/// <summary>
169+
/// The subscription cloud credentials.
170+
/// </summary>
171+
private readonly SubscriptionCloudCredentials credential;
172+
173+
/// <summary>
174+
/// Initializes a new instance of the <see cref="TestHttpClientHelperFactory"/> class.
175+
/// </summary>
176+
/// <param name="credentials"></param>
177+
public TestHttpClientHelperFactory(SubscriptionCloudCredentials credentials)
178+
{
179+
this.credential = credentials;
180+
}
181+
182+
/// <summary>
183+
/// Creates new instances of the <see cref="HttpClientHelper"/> class.
184+
/// </summary>
185+
/// <param name="credentials">The credentials.</param>
186+
/// <param name="headerValues">The headers.</param>
187+
public override HttpClientHelper CreateHttpClientHelper(
188+
SubscriptionCloudCredentials credentials,
189+
IEnumerable<ProductInfoHeaderValue> headerValues,
190+
Dictionary<string, string> cmdletHeaderValues)
191+
{
192+
return new HttpClientHelperImpl(
193+
credentials: this.credential,
194+
headerValues: headerValues,
195+
cmdletHeaderValues: cmdletHeaderValues);
196+
}
197+
198+
/// <summary>
199+
/// An implementation of the <see cref="HttpClientHelper"/> abstract class.
200+
/// </summary>
201+
private class HttpClientHelperImpl : HttpClientHelper
202+
{
203+
/// <summary>
204+
/// Initializes new instances of the <see cref="HttpClientHelperImpl"/> class.
205+
/// </summary>
206+
/// <param name="credentials">The credentials.</param>
207+
/// <param name="headerValues">The headers.</param>
208+
public HttpClientHelperImpl(
209+
SubscriptionCloudCredentials credentials,
210+
IEnumerable<ProductInfoHeaderValue> headerValues,
211+
Dictionary<string, string> cmdletHeaderValues)
212+
: base(
213+
credentials: credentials,
214+
headerValues: headerValues,
215+
cmdletHeaderValues: cmdletHeaderValues)
216+
{
217+
}
218+
219+
/// <summary>
220+
/// Creates an <see cref="HttpClient"/>
221+
/// </summary>
222+
/// <param name="primaryHandlers">The handlers that will be added to the top of the chain.</param>
223+
public override HttpClient CreateHttpClient(params DelegatingHandler[] primaryHandlers)
224+
{
225+
return base.CreateHttpClient(HttpMockServer.CreateInstance()
226+
.AsArray()
227+
.Concat(primaryHandlers)
228+
.ToArray());
229+
}
230+
}
231+
}
232+
}
233+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.ServiceManagemenet.Common.Models;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
18+
using Xunit;
19+
using Xunit.Abstractions;
20+
21+
namespace Microsoft.Azure.Commands.MachineLearning.Test.ScenarioTests
22+
{
23+
public class CommitmentPlanTests : RMTestBase
24+
{
25+
private readonly XunitTracingInterceptor interceptor;
26+
27+
public CommitmentPlanTests(ITestOutputHelper output)
28+
{
29+
this.interceptor = new XunitTracingInterceptor(output);
30+
XunitTracingInterceptor.AddToContext(this.interceptor);
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void TestCreateGetRemoveCommitmentPlan()
36+
{
37+
CommitmentPlansTestController.NewInstance.RunPsTest(this.interceptor, "Test-CreateGetRemoveMLCommitmentPlan");
38+
}
39+
40+
[Fact]
41+
[Trait(Category.AcceptanceType, Category.CheckIn)]
42+
public void TestUpdateCommitmentPlan()
43+
{
44+
CommitmentPlansTestController.NewInstance.RunPsTest(this.interceptor, "Test-UpdateMLCommitmentPlan");
45+
}
46+
47+
[Fact]
48+
[Trait(Category.AcceptanceType, Category.CheckIn)]
49+
public void TestListCommitmentPlans()
50+
{
51+
CommitmentPlansTestController.NewInstance.RunPsTest(this.interceptor, "Test-ListMLCommitmentPlans");
52+
}
53+
54+
}
55+
}

0 commit comments

Comments
 (0)