Skip to content

Commit dc4d17e

Browse files
took latest with Mo changes
1 parent 1a50a2c commit dc4d17e

File tree

50 files changed

+5924
-28
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

+5924
-28
lines changed

src/ResourceManager/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.6179.26854-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
6969
</Reference>
7070
<Reference Include="Microsoft.Azure.Test.HttpRecorder">
71-
<SpecificVersion>False</SpecificVersion>
72-
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.7-preview\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
71+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.8.1\lib\net452\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
72+
<Private>True</Private>
7373
</Reference>
7474
<Reference Include="Microsoft.CSharp" />
7575
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -144,6 +144,7 @@
144144
<Compile Include="Properties\AssemblyInfo.cs" />
145145
<Compile Include="ScenarioTests\AutomationScenarioTestsBase.cs" />
146146
<Compile Include="ScenarioTests\AutomationTests.cs" />
147+
<Compile Include="ScenarioTests\UpdateManagement\UpdateManagementTests.cs" />
147148
<Compile Include="UnitTests\GetAzureAutomationDscNodeConfigurationDeploymentSchedulesTest.cs" />
148149
<Compile Include="UnitTests\GetAzureAutomationDscNodeConfigurationTest.cs" />
149150
<Compile Include="UnitTests\GetAzureAutomationDscNodeReportTest.cs" />
@@ -250,8 +251,60 @@
250251
<None Include="ScenarioTests\Resources\Write-DebugAndVerboseOutput.ps1">
251252
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
252253
</None>
254+
<None Include="ScenarioTests\UpdateManagement\UpdateManagementTests.ps1">
255+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
256+
</None>
257+
<None Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\CreateLinuxWeeklySUC.json" />
258+
<None Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\CreateWindowsMonthlySUC.json" />
253259
</ItemGroup>
254260
<ItemGroup />
261+
<ItemGroup>
262+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\CreateLinuxOneTimeSUCNonAzureOnly.json">
263+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
264+
</Content>
265+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\CreateLinuxOneTimeSUCWithAllOption.json">
266+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
267+
</Content>
268+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\CreateLinuxOneTimeSUCWithDefaults.json">
269+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
270+
</Content>
271+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\CreateOneTimeSoftwareUpdateConfigurationWithDefaults.json">
272+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
273+
</Content>
274+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\CreateWindowsOneTimeSUCWithAllOption.json">
275+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
276+
</Content>
277+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\CreateWindowsOneTimeSUCWithDefaults.json">
278+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
279+
</Content>
280+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\DeleteSUC.json">
281+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
282+
</Content>
283+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\GetAllMachineRuns.json">
284+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
285+
</Content>
286+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\GetAllMachineRunsWithFilters.json">
287+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
288+
</Content>
289+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\GetAllMachineRunsWithFiltersNoResults.json">
290+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
291+
</Content>
292+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\GetAllRuns.json">
293+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
294+
</Content>
295+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\GetAllRunsWithFilters.json">
296+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
297+
</Content>
298+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\GetAllRunsWithFiltersNoResults.json">
299+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
300+
</Content>
301+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\GetAllSUCs.json">
302+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
303+
</Content>
304+
<Content Include="SessionRecords\Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement.UpdateManagementTests\GetAllSUCsForVM.json">
305+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
306+
</Content>
307+
</ItemGroup>
255308
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
256309
<Import Project="..\..\..\..\tools\Common.Dependencies.Test.targets" />
257310
</Project>

src/ResourceManager/Automation/Commands.Automation.Test/ScenarioTests/AutomationScenarioTestsBase.cs

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

15+
using System;
16+
using System.Linq;
1517
using Microsoft.Azure.Commands.Common.Authentication;
1618
using Microsoft.Azure.Management.Automation;
1719
using Microsoft.Azure.Test;
1820
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1921
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
22+
using Microsoft.Azure.Test.HttpRecorder;
23+
using System.Reflection;
24+
using Microsoft.Rest;
25+
using System.Net.Http;
2026

2127
namespace Microsoft.Azure.Commands.Automation.Test
2228
{
@@ -38,6 +44,8 @@ protected void SetupManagementClients()
3844

3945
protected void RunPowerShellTest(params string[] scripts)
4046
{
47+
const string RootNamespace = "ScenarioTests";
48+
4149
using (UndoContext context = UndoContext.Current)
4250
{
4351
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));
@@ -46,8 +54,13 @@ protected void RunPowerShellTest(params string[] scripts)
4654

4755
helper.SetupEnvironment(AzureModule.AzureResourceManager);
4856

57+
58+
var psModuleFile = this.GetType().FullName.Contains(RootNamespace) ?
59+
this.GetType().FullName.Split(new[] { RootNamespace }, StringSplitOptions.RemoveEmptyEntries).Last().Replace(".", "\\") :
60+
$"\\{this.GetType().Name}";
61+
4962
helper.SetupModules(AzureModule.AzureResourceManager,
50-
"ScenarioTests\\" + this.GetType().Name + ".ps1",
63+
$"{RootNamespace}{psModuleFile}.ps1",
5164
helper.RMProfileModule,
5265
helper.GetRMModulePath(@"AzureRM.Automation.psd1"));
5366

@@ -57,7 +70,52 @@ protected void RunPowerShellTest(params string[] scripts)
5770

5871
protected AutomationClient GetAutomationManagementClient()
5972
{
60-
return TestBase.GetServiceClient<AutomationClient>(new CSMTestEnvironmentFactory());
73+
AutomationClient client;
74+
TestEnvironment currentEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment();
75+
var credentials = currentEnvironment.AuthorizationContext.TokenCredentials[TokenAudience.Management];
76+
77+
HttpMockServer server;
78+
79+
try
80+
{
81+
server = HttpMockServer.CreateInstance();
82+
}
83+
catch (ApplicationException)
84+
{
85+
// mock server has never been initialized, we will need to initialize it.
86+
HttpMockServer.Initialize("TestEnvironment", "InitialCreation");
87+
server = HttpMockServer.CreateInstance();
88+
}
89+
90+
if (currentEnvironment.UsesCustomUri())
91+
{
92+
ConstructorInfo constructor = typeof(AutomationClient).GetConstructor(new Type[] { typeof(Uri), typeof(ServiceClientCredentials), typeof(DelegatingHandler[]) });
93+
client = constructor.Invoke(new object[] { currentEnvironment.BaseUri, credentials, new DelegatingHandler[] { server } }) as AutomationClient;
94+
}
95+
else
96+
{
97+
ConstructorInfo constructor = typeof(AutomationClient).GetConstructor(new Type[] { typeof(ServiceClientCredentials) });
98+
client = constructor.Invoke(new object[] { credentials }) as AutomationClient;
99+
}
100+
101+
PropertyInfo subId = typeof(AutomationClient).GetProperty("SubscriptionId", typeof(string));
102+
if (subId != null)
103+
{
104+
subId.SetValue(client, currentEnvironment.SubscriptionId);
105+
}
106+
107+
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
108+
{
109+
PropertyInfo initialTimeout = typeof(AutomationClient).GetProperty("LongRunningOperationInitialTimeout", typeof(int));
110+
PropertyInfo retryTimeout = typeof(AutomationClient).GetProperty("LongRunningOperationRetryTimeout", typeof(int));
111+
if (initialTimeout != null && retryTimeout != null)
112+
{
113+
initialTimeout.SetValue(client, 0);
114+
retryTimeout.SetValue(client, 0);
115+
}
116+
}
117+
118+
return client;
61119
}
62120
}
63121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.ScenarioTests.UpdateManagement
16+
{
17+
using Microsoft.Azure.Commands.Automation.Test;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Xunit;
20+
21+
public class UpdateManagementTests : AutomationScenarioTestsBase
22+
{
23+
public UpdateManagementTests(Xunit.Abstractions.ITestOutputHelper output)
24+
{
25+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
26+
}
27+
28+
[Fact]
29+
[Trait(Category.AcceptanceType, Category.CheckIn)]
30+
[Trait(Category.Service, Category.Automation)]
31+
public void CreateWindowsOneTimeSUCWithDefaults()
32+
{
33+
RunPowerShellTest("Test-CreateWindowsOneTimeSoftwareUpdateConfigurationWithDefaults");
34+
}
35+
36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
[Trait(Category.Service, Category.Automation)]
39+
public void CreateLinuxOneTimeSUCWithDefaults()
40+
{
41+
RunPowerShellTest("Test-CreateLinuxOneTimeSoftwareUpdateConfigurationWithDefaults");
42+
}
43+
44+
[Fact]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
[Trait(Category.Service, Category.Automation)]
47+
public void CreateWindowsOneTimeSUCWithAllOption()
48+
{
49+
RunPowerShellTest("Test-CreateWindowsOneTimeSoftwareUpdateConfigurationWithAllOption");
50+
}
51+
52+
[Fact]
53+
[Trait(Category.AcceptanceType, Category.CheckIn)]
54+
[Trait(Category.Service, Category.Automation)]
55+
public void CreateLinuxOneTimeSUCWithAllOption()
56+
{
57+
RunPowerShellTest("Test-CreateLinuxOneTimeSoftwareUpdateConfigurationWithAllOption");
58+
}
59+
60+
[Fact]
61+
[Trait(Category.AcceptanceType, Category.CheckIn)]
62+
[Trait(Category.Service, Category.Automation)]
63+
public void CreateLinuxOneTimeSUCNonAzureOnly()
64+
{
65+
RunPowerShellTest("Test-CreateLinuxOneTimeSoftwareUpdateConfigurationNonAzureOnly");
66+
}
67+
68+
[Fact(Skip = "No recording generated")]
69+
[Trait(Category.AcceptanceType, Category.CheckIn)]
70+
[Trait(Category.Service, Category.Automation)]
71+
public void CreateLinuxOneTimeSUCNoTarget()
72+
{
73+
RunPowerShellTest("Test-CreateLinuxOneTimeSoftwareUpdateConfigurationNoTargets");
74+
}
75+
76+
[Fact]
77+
[Trait(Category.AcceptanceType, Category.CheckIn)]
78+
[Trait(Category.Service, Category.Automation)]
79+
public void GetAllSUCs()
80+
{
81+
RunPowerShellTest("Test-GetAllSoftwareUpdateConfigurations");
82+
}
83+
84+
[Fact]
85+
[Trait(Category.AcceptanceType, Category.CheckIn)]
86+
[Trait(Category.Service, Category.Automation)]
87+
public void GetAllSUCsForVM()
88+
{
89+
RunPowerShellTest("Test-GetSoftwareUpdateConfigurationsForVM");
90+
}
91+
92+
[Fact]
93+
[Trait(Category.AcceptanceType, Category.CheckIn)]
94+
[Trait(Category.Service, Category.Automation)]
95+
public void DeleteSUC()
96+
{
97+
RunPowerShellTest("Test-DeleteSoftwareUpdateConfiguration");
98+
}
99+
100+
[Fact]
101+
[Trait(Category.AcceptanceType, Category.CheckIn)]
102+
[Trait(Category.Service, Category.Automation)]
103+
public void GetAllRuns()
104+
{
105+
RunPowerShellTest("Test-GetAllSoftwareUpdateRuns");
106+
}
107+
108+
[Fact]
109+
[Trait(Category.AcceptanceType, Category.CheckIn)]
110+
[Trait(Category.Service, Category.Automation)]
111+
public void GetAllRunsWithFilters()
112+
{
113+
RunPowerShellTest("Test-GetAllSoftwareUpdateRunsWithFilters");
114+
}
115+
116+
[Fact]
117+
[Trait(Category.AcceptanceType, Category.CheckIn)]
118+
[Trait(Category.Service, Category.Automation)]
119+
public void GetAllRunsWithFiltersNoResults()
120+
{
121+
RunPowerShellTest("Test-GetAllSoftwareUpdateRunsWithFiltersNoResults");
122+
}
123+
124+
[Fact]
125+
[Trait(Category.AcceptanceType, Category.CheckIn)]
126+
[Trait(Category.Service, Category.Automation)]
127+
public void GetAllMachineRuns()
128+
{
129+
RunPowerShellTest("Test-GetAllSoftwareUpdateMachineRuns");
130+
}
131+
132+
[Fact]
133+
[Trait(Category.AcceptanceType, Category.CheckIn)]
134+
[Trait(Category.Service, Category.Automation)]
135+
public void GetAllMachineRunsWithFilters()
136+
{
137+
RunPowerShellTest("Test-GetAllSoftwareUpdateMachineRunsWithFilters");
138+
}
139+
140+
[Fact]
141+
[Trait(Category.AcceptanceType, Category.CheckIn)]
142+
[Trait(Category.Service, Category.Automation)]
143+
public void GetAllMachineRunsWithFiltersNoResults()
144+
{
145+
RunPowerShellTest("Test-GetAllSoftwareUpdateMachineRunsWithFiltersNoResults");
146+
}
147+
148+
[Fact]
149+
[Trait(Category.AcceptanceType, Category.CheckIn)]
150+
[Trait(Category.Service, Category.Automation)]
151+
public void CreateLinuxWeeklySUC()
152+
{
153+
RunPowerShellTest("Test-CreateLinuxWeeklySoftwareUpdateConfiguration");
154+
}
155+
156+
[Fact]
157+
[Trait(Category.AcceptanceType, Category.CheckIn)]
158+
[Trait(Category.Service, Category.Automation)]
159+
public void CreateWindowsMonthlySUC()
160+
{
161+
RunPowerShellTest("Test-CreateWindowsMonthlySoftwareUpdateConfiguration");
162+
}
163+
}
164+
}

0 commit comments

Comments
 (0)