Skip to content

Commit d82db34

Browse files
author
Jianghao Lu
committed
Split ScenarioTest.Common into ASM & ARM
1 parent 2fe1f7f commit d82db34

File tree

53 files changed

+3121
-186
lines changed

Some content is hidden

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

53 files changed

+3121
-186
lines changed

src/Common/AzurePSCmdlet.cs

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@
2121
using Microsoft.Azure.Common.Authentication;
2222
using Microsoft.Azure.Common.Authentication.Models;
2323
using Microsoft.WindowsAzure.Commands.Common;
24-
using Microsoft.WindowsAzure.Commands.Common.Properties;
2524
using Newtonsoft.Json;
26-
using System;
27-
using System.Collections.Concurrent;
28-
using System.Diagnostics;
2925
using System.IO;
30-
using System.Management.Automation;
3126
using System.Management.Automation.Host;
3227
using System.Threading;
3328

@@ -56,9 +51,6 @@ protected virtual bool IsErrorMetricEnabled
5651
get { return true; }
5752
}
5853

59-
[Parameter(Mandatory = false, HelpMessage = "In-memory profile.")]
60-
public AzureProfile Profile { get; set; }
61-
6254
/// <summary>
6355
/// Gets the PowerShell module name used for user agent header.
6456
/// By default uses "Azurepowershell"
@@ -160,18 +152,7 @@ public static bool IsDataCollectionAllowed()
160152
/// Save the current data collection profile Json data into the default file path
161153
/// </summary>
162154
/// <param name="profile"></param>
163-
protected void SaveDataCollectionProfile()
164-
{
165-
if (_dataCollectionProfile == null)
166-
{
167-
InitializeDataCollectionProfile();
168-
}
169-
170-
string fileFullPath = Path.Combine(AzureSession.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName);
171-
var contents = JsonConvert.SerializeObject(_dataCollectionProfile);
172-
AzureSession.DataStore.WriteFile(fileFullPath, contents);
173-
WriteWarning(string.Format(Resources.DataCollectionSaveFileInformation, fileFullPath));
174-
}
155+
protected abstract void SaveDataCollectionProfile();
175156

176157
protected bool CheckIfInteractive()
177158
{
@@ -203,47 +184,7 @@ protected bool CheckIfInteractive()
203184
/// Prompt for the current data collection profile
204185
/// </summary>
205186
/// <param name="profile"></param>
206-
protected void PromptForDataCollectionProfileIfNotExists()
207-
{
208-
// Initialize it from the environment variable or profile file.
209-
InitializeDataCollectionProfile();
210-
211-
if (!_dataCollectionProfile.EnableAzureDataCollection.HasValue && CheckIfInteractive())
212-
{
213-
WriteWarning(Resources.DataCollectionPrompt);
214-
215-
const double timeToWaitInSeconds = 60;
216-
var status = string.Format(Resources.DataCollectionConfirmTime, timeToWaitInSeconds);
217-
ProgressRecord record = new ProgressRecord(0, Resources.DataCollectionActivity, status);
218-
219-
var startTime = DateTime.Now;
220-
var endTime = DateTime.Now;
221-
double elapsedSeconds = 0;
222-
223-
while (!this.Host.UI.RawUI.KeyAvailable && elapsedSeconds < timeToWaitInSeconds)
224-
{
225-
Thread.Sleep(TimeSpan.FromMilliseconds(10));
226-
endTime = DateTime.Now;
227-
228-
elapsedSeconds = (endTime - startTime).TotalSeconds;
229-
record.PercentComplete = ((int)elapsedSeconds * 100 / (int)timeToWaitInSeconds);
230-
WriteProgress(record);
231-
}
232-
233-
bool enabled = false;
234-
if (this.Host.UI.RawUI.KeyAvailable)
235-
{
236-
KeyInfo keyInfo = this.Host.UI.RawUI.ReadKey(ReadKeyOptions.NoEcho | ReadKeyOptions.AllowCtrlC | ReadKeyOptions.IncludeKeyDown);
237-
enabled = (keyInfo.Character == 'Y' || keyInfo.Character == 'y');
238-
}
239-
240-
_dataCollectionProfile.EnableAzureDataCollection = enabled;
241-
242-
WriteWarning(enabled ? Resources.DataCollectionConfirmYes : Resources.DataCollectionConfirmNo);
243-
244-
SaveDataCollectionProfile();
245-
}
246-
}
187+
protected abstract void PromptForDataCollectionProfileIfNotExists();
247188

248189
/// <summary>
249190
/// Cmdlet begin process. Write to logs, setup Http Tracing and initialize profile
@@ -430,24 +371,7 @@ private void FlushDebugMessages()
430371
}
431372
}
432373

433-
protected void InitializeQosEvent()
434-
{
435-
QosEvent = new AzurePSQoSEvent()
436-
{
437-
CmdletType = this.GetType().Name,
438-
IsSuccess = true,
439-
};
440-
441-
if (this.Profile != null && this.Profile.DefaultSubscription != null)
442-
{
443-
QosEvent.Uid = MetricHelper.GenerateSha256HashString(
444-
this.Profile.DefaultSubscription.Id.ToString());
445-
}
446-
else
447-
{
448-
QosEvent.Uid = "defaultid";
449-
}
450-
}
374+
protected abstract void InitializeQosEvent();
451375

452376
/// <summary>
453377
/// Invoke this method when the cmdlet is completed or terminated.

src/Common/Commands.Common/AzureSMCmdlet.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2323
using Microsoft.WindowsAzure.Commands.Common;
2424
using Microsoft.WindowsAzure.Commands.Common.Properties;
25+
using Newtonsoft.Json;
26+
using System.Threading;
27+
using System.Management.Automation.Host;
2528

2629
namespace Microsoft.WindowsAzure.Commands.Utilities.Common
2730
{
@@ -131,6 +134,80 @@ protected static void SetTokenCacheForProfile(AzureSMProfile profile)
131134
}
132135
}
133136

137+
protected override void SaveDataCollectionProfile()
138+
{
139+
if (_dataCollectionProfile == null)
140+
{
141+
InitializeDataCollectionProfile();
142+
}
143+
144+
string fileFullPath = Path.Combine(AzureSession.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName);
145+
var contents = JsonConvert.SerializeObject(_dataCollectionProfile);
146+
AzureSession.DataStore.WriteFile(fileFullPath, contents);
147+
WriteWarning(string.Format(Resources.DataCollectionSaveFileInformation, fileFullPath));
148+
}
149+
150+
protected override void PromptForDataCollectionProfileIfNotExists()
151+
{
152+
// Initialize it from the environment variable or profile file.
153+
InitializeDataCollectionProfile();
154+
155+
if (!_dataCollectionProfile.EnableAzureDataCollection.HasValue && CheckIfInteractive())
156+
{
157+
WriteWarning(Resources.DataCollectionPrompt);
158+
159+
const double timeToWaitInSeconds = 60;
160+
var status = string.Format(Resources.DataCollectionConfirmTime, timeToWaitInSeconds);
161+
ProgressRecord record = new ProgressRecord(0, Resources.DataCollectionActivity, status);
162+
163+
var startTime = DateTime.Now;
164+
var endTime = DateTime.Now;
165+
double elapsedSeconds = 0;
166+
167+
while (!this.Host.UI.RawUI.KeyAvailable && elapsedSeconds < timeToWaitInSeconds)
168+
{
169+
Thread.Sleep(TimeSpan.FromMilliseconds(10));
170+
endTime = DateTime.Now;
171+
172+
elapsedSeconds = (endTime - startTime).TotalSeconds;
173+
record.PercentComplete = ((int)elapsedSeconds * 100 / (int)timeToWaitInSeconds);
174+
WriteProgress(record);
175+
}
176+
177+
bool enabled = false;
178+
if (this.Host.UI.RawUI.KeyAvailable)
179+
{
180+
KeyInfo keyInfo = this.Host.UI.RawUI.ReadKey(ReadKeyOptions.NoEcho | ReadKeyOptions.AllowCtrlC | ReadKeyOptions.IncludeKeyDown);
181+
enabled = (keyInfo.Character == 'Y' || keyInfo.Character == 'y');
182+
}
183+
184+
_dataCollectionProfile.EnableAzureDataCollection = enabled;
185+
186+
WriteWarning(enabled ? Resources.DataCollectionConfirmYes : Resources.DataCollectionConfirmNo);
187+
188+
SaveDataCollectionProfile();
189+
}
190+
}
191+
192+
protected override void InitializeQosEvent()
193+
{
194+
QosEvent = new AzurePSQoSEvent()
195+
{
196+
CmdletType = this.GetType().Name,
197+
IsSuccess = true,
198+
};
199+
200+
if (this.Profile != null && this.Profile.DefaultSubscription != null)
201+
{
202+
QosEvent.Uid = MetricHelper.GenerateSha256HashString(
203+
this.Profile.DefaultSubscription.Id.ToString());
204+
}
205+
else
206+
{
207+
QosEvent.Uid = "defaultid";
208+
}
209+
}
210+
134211
/// <summary>
135212
/// Cmdlet begin process. Write to logs, setup Http Tracing and initialize profile
136213
/// </summary>

src/Common/Commands.Profile/DataCollection/EnableAzureDataCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace Microsoft.WindowsAzure.Commands.Profile
2020
{
2121
[Cmdlet(VerbsLifecycle.Enable, "AzureDataCollection")]
22-
public class EnableAzureDataCollectionCommand : AzurePSCmdlet
22+
public class EnableAzureDataCollectionCommand : AzureSMCmdlet
2323
{
2424
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
2525
public override void ExecuteCmdlet()

src/Common/Commands.ResourceManager.Common/AzureRMCmdlet.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
using Microsoft.Azure.Common.Authentication;
1717
using Microsoft.Azure.Common.Authentication.Models;
1818
using Microsoft.WindowsAzure.Commands.Utilities.Common;
19+
using System.IO;
20+
using Newtonsoft.Json;
21+
using Microsoft.Azure.Commands.ResourceManager.Common.Properties;
22+
using System;
23+
using System.Threading;
24+
using System.Management.Automation.Host;
25+
using Microsoft.WindowsAzure.Commands.Common;
1926

2027
namespace Microsoft.Azure.Commands.ResourceManager.Common
2128
{
@@ -52,5 +59,79 @@ protected override AzureContext DefaultContext
5259
return DefaultProfile.DefaultContext;
5360
}
5461
}
62+
63+
protected override void SaveDataCollectionProfile()
64+
{
65+
if (_dataCollectionProfile == null)
66+
{
67+
InitializeDataCollectionProfile();
68+
}
69+
70+
string fileFullPath = Path.Combine(AzureSession.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName);
71+
var contents = JsonConvert.SerializeObject(_dataCollectionProfile);
72+
AzureSession.DataStore.WriteFile(fileFullPath, contents);
73+
WriteWarning(string.Format(Resources.DataCollectionSaveFileInformation, fileFullPath));
74+
}
75+
76+
protected override void PromptForDataCollectionProfileIfNotExists()
77+
{
78+
// Initialize it from the environment variable or profile file.
79+
InitializeDataCollectionProfile();
80+
81+
if (!_dataCollectionProfile.EnableAzureDataCollection.HasValue && CheckIfInteractive())
82+
{
83+
WriteWarning(Resources.DataCollectionPrompt);
84+
85+
const double timeToWaitInSeconds = 60;
86+
var status = string.Format(Resources.DataCollectionConfirmTime, timeToWaitInSeconds);
87+
ProgressRecord record = new ProgressRecord(0, Resources.DataCollectionActivity, status);
88+
89+
var startTime = DateTime.Now;
90+
var endTime = DateTime.Now;
91+
double elapsedSeconds = 0;
92+
93+
while (!this.Host.UI.RawUI.KeyAvailable && elapsedSeconds < timeToWaitInSeconds)
94+
{
95+
Thread.Sleep(TimeSpan.FromMilliseconds(10));
96+
endTime = DateTime.Now;
97+
98+
elapsedSeconds = (endTime - startTime).TotalSeconds;
99+
record.PercentComplete = ((int)elapsedSeconds * 100 / (int)timeToWaitInSeconds);
100+
WriteProgress(record);
101+
}
102+
103+
bool enabled = false;
104+
if (this.Host.UI.RawUI.KeyAvailable)
105+
{
106+
KeyInfo keyInfo = this.Host.UI.RawUI.ReadKey(ReadKeyOptions.NoEcho | ReadKeyOptions.AllowCtrlC | ReadKeyOptions.IncludeKeyDown);
107+
enabled = (keyInfo.Character == 'Y' || keyInfo.Character == 'y');
108+
}
109+
110+
_dataCollectionProfile.EnableAzureDataCollection = enabled;
111+
112+
WriteWarning(enabled ? Resources.DataCollectionConfirmYes : Resources.DataCollectionConfirmNo);
113+
114+
SaveDataCollectionProfile();
115+
}
116+
}
117+
118+
protected override void InitializeQosEvent()
119+
{
120+
QosEvent = new AzurePSQoSEvent()
121+
{
122+
CmdletType = this.GetType().Name,
123+
IsSuccess = true,
124+
};
125+
126+
if (this.DefaultContext != null && this.DefaultContext.Subscription != null)
127+
{
128+
QosEvent.Uid = MetricHelper.GenerateSha256HashString(
129+
this.DefaultContext.Subscription.Id.ToString());
130+
}
131+
else
132+
{
133+
QosEvent.Uid = "defaultid";
134+
}
135+
}
55136
}
56137
}

src/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
<SpecificVersion>False</SpecificVersion>
5454
<HintPath>..\..\packages\Hyak.Common.1.0.2\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
5555
</Reference>
56+
<Reference Include="Microsoft.ApplicationInsights">
57+
<HintPath>..\..\packages\Microsoft.ApplicationInsights.1.1.1-beta\lib\net45\Microsoft.ApplicationInsights.dll</HintPath>
58+
</Reference>
5659
<Reference Include="Microsoft.Azure.Common">
5760
<SpecificVersion>False</SpecificVersion>
5861
<HintPath>..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
@@ -143,6 +146,9 @@
143146
<Compile Include="..\Commands.Common\AzurePowerShell.cs">
144147
<Link>Common\AzurePowerShell.cs</Link>
145148
</Compile>
149+
<Compile Include="..\Commands.Common\AzurePSDataCollectionProfile.cs">
150+
<Link>Common\AzurePSDataCollectionProfile.cs</Link>
151+
</Compile>
146152
<Compile Include="..\Commands.Common\CmdletExtensions.cs">
147153
<Link>Common\CmdletExtensions.cs</Link>
148154
</Compile>
@@ -155,6 +161,9 @@
155161
<Compile Include="..\Commands.Common\GeneralUtilities.cs">
156162
<Link>Common\GeneralUtilities.cs</Link>
157163
</Compile>
164+
<Compile Include="..\Commands.Common\MetricHelper.cs">
165+
<Link>Common\MetricHelper.cs</Link>
166+
</Compile>
158167
<Compile Include="..\Commands.Common\PowerShellUtilities.cs">
159168
<Link>Common\PowerShellUtilities.cs</Link>
160169
</Compile>
@@ -165,11 +174,23 @@
165174
<Link>Common\SecureStringExtensions.cs</Link>
166175
</Compile>
167176
<Compile Include="AzureRMCmdlet.cs" />
177+
<Compile Include="Common\TestMockSupport.cs" />
168178
<Compile Include="Properties\AssemblyInfo.cs" />
179+
<Compile Include="Properties\Resources.Designer.cs">
180+
<AutoGen>True</AutoGen>
181+
<DesignTime>True</DesignTime>
182+
<DependentUpon>Resources.resx</DependentUpon>
183+
</Compile>
169184
<None Include="packages.config">
170185
<SubType>Designer</SubType>
171186
</None>
172187
</ItemGroup>
188+
<ItemGroup>
189+
<EmbeddedResource Include="Properties\Resources.resx">
190+
<Generator>ResXFileCodeGenerator</Generator>
191+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
192+
</EmbeddedResource>
193+
</ItemGroup>
173194
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
174195
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
175196
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+

2+
// ----------------------------------------------------------------------------------
3+
//
4+
// Copyright Microsoft Corporation
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// ----------------------------------------------------------------------------------
15+
16+
namespace Microsoft.WindowsAzure.Commands.Utilities.Common
17+
{
18+
public class TestMockSupport
19+
{
20+
//a.k.a when you run under Playback mode
21+
public static bool RunningMocked { get; set; }
22+
23+
public static void Delay(int milliSeconds)
24+
{
25+
if (!RunningMocked)
26+
{
27+
System.Threading.Thread.Sleep(milliSeconds);
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)