Skip to content

Commit d62adf0

Browse files
merge with dev and resolve conflicts
2 parents f82ff82 + be2a4ad commit d62adf0

File tree

478 files changed

+3110
-588
lines changed

Some content is hidden

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

478 files changed

+3110
-588
lines changed

src/Common/Commands.ScenarioTests.Common/Commands.ScenarioTests.Common.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
<HintPath>..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
5555
</Reference>
5656
<Reference Include="Microsoft.Azure.Test.Framework">
57-
<HintPath>..\..\packages\Microsoft.Azure.Test.Framework.1.0.5896.19355-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
57+
<HintPath>..\..\packages\Microsoft.Azure.Test.Framework.1.0.5945.28173-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
5858
</Reference>
5959
<Reference Include="Microsoft.Azure.Test.HttpRecorder">
60-
<HintPath>..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5896.19355-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
60+
<HintPath>..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5945.28173-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
6161
</Reference>
6262
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory">
6363
<SpecificVersion>False</SpecificVersion>
@@ -149,6 +149,7 @@
149149
<Compile Include="PowerShellExtensions.cs" />
150150
<Compile Include="Properties\AssemblyInfo.cs" />
151151
<Compile Include="SMTestBase.cs" />
152+
<Compile Include="XunitTracingInterceptor.cs" />
152153
</ItemGroup>
153154
<ItemGroup>
154155
<None Include="Assert.ps1">

src/Common/Commands.ScenarioTests.Common/EnvironmentSetupHelper.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using System.Security.Cryptography.X509Certificates;
2929
using Microsoft.Azure.ServiceManagemenet.Common;
3030
using System.Text;
31+
using Microsoft.WindowsAzure.ServiceManagemenet.Common.Models;
3132

3233
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
3334
{
@@ -46,6 +47,8 @@ public class EnvironmentSetupHelper
4647

4748
protected List<string> modules;
4849

50+
public XunitTracingInterceptor TracingInterceptor { get; set; }
51+
4952
protected ProfileClient ProfileClient { get; set; }
5053

5154
public EnvironmentSetupHelper()
@@ -299,7 +302,10 @@ private Collection<PSObject> ExecuteShellTest(
299302

300303
foreach (var script in scripts)
301304
{
302-
Console.WriteLine(script);
305+
if (TracingInterceptor != null)
306+
{
307+
TracingInterceptor.Information(script);
308+
}
303309
powershell.AddScript(script);
304310
}
305311
try
@@ -326,12 +332,12 @@ private Collection<PSObject> ExecuteShellTest(
326332
}
327333
catch (Exception psException)
328334
{
329-
powershell.LogPowerShellException(psException);
335+
powershell.LogPowerShellException(psException, TracingInterceptor);
330336
throw;
331337
}
332338
finally
333339
{
334-
powershell.LogPowerShellResults(output);
340+
powershell.LogPowerShellResults(output, TracingInterceptor);
335341
powershell.Streams.Error.Clear();
336342
}
337343
}
@@ -354,7 +360,7 @@ private void SetupPowerShellModules(System.Management.Automation.PowerShell powe
354360
}
355361

356362
powershell.AddScript(
357-
string.Format(@"set-location {0}", AppDomain.CurrentDomain.BaseDirectory));
363+
string.Format("set-location \"{0}\"", AppDomain.CurrentDomain.BaseDirectory));
358364
powershell.AddScript(string.Format(@"$TestOutputRoot='{0}'", AppDomain.CurrentDomain.BaseDirectory));
359365
powershell.AddScript("$VerbosePreference='Continue'");
360366
powershell.AddScript("$DebugPreference='Continue'");

src/Common/Commands.ScenarioTests.Common/PowerShellExtensions.cs

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.WindowsAzure.ServiceManagemenet.Common.Models;
1516
using System;
1617
using System.Collections.Generic;
1718
using System.Collections.ObjectModel;
@@ -95,59 +96,83 @@ public static void SetVariable(this System.Management.Automation.PowerShell powe
9596
/// PowerShell error record if available
9697
/// </summary>
9798
/// <param name="runtimeException">The exception to parse</param>
98-
public static void LogPowerShellException(this System.Management.Automation.PowerShell powershell, Exception runtimeException)
99+
public static void LogPowerShellException(
100+
this System.Management.Automation.PowerShell powershell,
101+
Exception runtimeException,
102+
XunitTracingInterceptor xunitLogger)
99103
{
100-
Console.WriteLine("Caught Exception: {0}\n", runtimeException);
101-
Console.WriteLine("Message: {0}\n", runtimeException.Message);
104+
if (xunitLogger != null)
105+
{
106+
xunitLogger.Information(string.Format("Caught Exception: {0}", runtimeException));
107+
xunitLogger.Information(string.Format("Message: {0}", runtimeException.Message));
108+
}
109+
102110
IContainsErrorRecord recordContainer = runtimeException as IContainsErrorRecord;
103111
if (recordContainer != null)
104112
{
105113
ErrorRecord record = recordContainer.ErrorRecord;
106-
Console.WriteLine("PowerShell Error Record: {0}\nException:{1}\nDetails:{2}\nScript Stack Trace: {3}\n: Target: {4}\n", record, record.Exception, record.ErrorDetails, record.ScriptStackTrace, record.TargetObject);
114+
115+
if (xunitLogger != null)
116+
{
117+
xunitLogger.Information(string.Format(
118+
"PowerShell Error Record: {0}\nException:{1}\nDetails:{2}\nScript Stack Trace: {3}\n: Target: {4}\n",
119+
record,
120+
record.Exception,
121+
record.ErrorDetails,
122+
record.ScriptStackTrace,
123+
record.TargetObject));
124+
}
107125
}
108126

109127
if (runtimeException.InnerException != null)
110128
{
111-
powershell.LogPowerShellException(runtimeException.InnerException);
129+
powershell.LogPowerShellException(runtimeException.InnerException, xunitLogger);
112130
}
113131
}
114132

115133
/// <summary>
116134
/// Log the PowerShell Streams from a PowerShell invocation
117135
/// </summary>
118136
/// <param name="powershell">The PowerShell instance to log</param>
119-
public static void LogPowerShellResults(this System.Management.Automation.PowerShell powershell)
137+
public static void LogPowerShellResults(
138+
this System.Management.Automation.PowerShell powershell,
139+
XunitTracingInterceptor xunitLogger)
120140
{
121-
powershell.LogPowerShellResults(null);
141+
powershell.LogPowerShellResults(null, xunitLogger);
122142
}
123143

124144
/// <summary>
125145
/// Log the PowerShell Streams from a PowerShell invocation
126146
/// </summary>
127147
/// <param name="powershell">The PowerShell instance to log</param>
128-
public static void LogPowerShellResults(this System.Management.Automation.PowerShell powershell, Collection<PSObject> output)
148+
public static void LogPowerShellResults(
149+
this System.Management.Automation.PowerShell powershell,
150+
Collection<PSObject> output,
151+
XunitTracingInterceptor xunitLogger)
129152
{
130153
if (output != null)
131154
{
132-
LogPowerShellStream<PSObject>(output, "OUTPUT");
155+
LogPowerShellStream<PSObject>(xunitLogger, output, "OUTPUT");
133156
}
134-
if (powershell.Commands != null && powershell.Commands.Commands != null &&
157+
if (xunitLogger != null &&
158+
powershell.Commands != null &&
159+
powershell.Commands.Commands != null &&
135160
powershell.Commands.Commands.Count > 0)
136161
{
137-
Console.WriteLine("================== COMMANDS =======================\n");
162+
xunitLogger.Information("================== COMMANDS =======================\n");
138163
foreach (Command command in powershell.Commands.Commands)
139164
{
140-
Console.WriteLine("{0}\n", command.CommandText);
165+
xunitLogger.Information(string.Format("{0}\n", command.CommandText));
141166
}
142167

143-
Console.WriteLine("===================================================\n");
168+
xunitLogger.Information("===================================================\n");
144169
}
145170

146-
LogPowerShellStream<DebugRecord>(powershell.Streams.Debug, "DEBUG");
147-
LogPowerShellStream<ErrorRecord>(powershell.Streams.Error, "ERROR");
148-
LogPowerShellStream<ProgressRecord>(powershell.Streams.Progress, "PROGRESS");
149-
LogPowerShellStream<VerboseRecord>(powershell.Streams.Verbose, "VERBOSE");
150-
LogPowerShellStream<WarningRecord>(powershell.Streams.Warning, "WARNING");
171+
LogPowerShellStream<DebugRecord>(xunitLogger, powershell.Streams.Debug, "DEBUG");
172+
LogPowerShellStream<ErrorRecord>(xunitLogger, powershell.Streams.Error, "ERROR");
173+
LogPowerShellStream<ProgressRecord>(xunitLogger, powershell.Streams.Progress, "PROGRESS");
174+
LogPowerShellStream<VerboseRecord>(xunitLogger, powershell.Streams.Verbose, "VERBOSE");
175+
LogPowerShellStream<WarningRecord>(xunitLogger, powershell.Streams.Warning, "WARNING");
151176
}
152177

153178
/// <summary>
@@ -196,23 +221,26 @@ public static void RemoveCredentials(this System.Management.Automation.PowerShel
196221
/// <typeparam name="T">The type of the internal data record (different for every stream)</typeparam>
197222
/// <param name="stream">The stream to log</param>
198223
/// <param name="name">The name of the stream to print in the log</param>
199-
private static void LogPowerShellStream<T>(ICollection<T> stream, string name)
224+
private static void LogPowerShellStream<T>(
225+
XunitTracingInterceptor xunitLogger,
226+
ICollection<T> stream,
227+
string name)
200228
{
201-
if (stream != null && stream.Count > 0)
229+
if (xunitLogger !=null && stream != null && stream.Count > 0)
202230
{
203-
204-
Console.WriteLine("---------------------------------------------------------------\n");
205-
Console.WriteLine("{0} STREAM\n", name);
206-
Console.WriteLine("---------------------------------------------------------------\n");
231+
xunitLogger.Information("---------------------------------------------------------------\n");
232+
xunitLogger.Information(string.Format("{0} STREAM\n", name));
233+
xunitLogger.Information("---------------------------------------------------------------\n");
207234
foreach (T item in stream)
208235
{
209236
if(item != null)
210237
{
211-
Console.WriteLine("{0}\n", item.ToString());
238+
xunitLogger.Information(string.Format("{0}\n", item.ToString()));
212239
}
213240
}
214-
Console.WriteLine("---------------------------------------------------------------\n");
215-
Console.WriteLine("");
241+
242+
xunitLogger.Information("---------------------------------------------------------------\n");
243+
xunitLogger.Information("");
216244
}
217245
}
218246
}

src/Common/Commands.ScenarioTests.Common/SMTestBase.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ public void Log(string format, params object[] args)
8383
{
8484
TestContext.WriteLine(format, args);
8585
}
86-
else
87-
{
88-
Console.WriteLine(format, args);
89-
}
9086
}
9187
}
9288
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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.Collections.Concurrent;
17+
using System.Collections.Generic;
18+
using System.Net.Http;
19+
using Hyak.Common;
20+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
21+
using Microsoft.WindowsAzure.Commands.Common;
22+
using Xunit.Abstractions;
23+
using System.IO;
24+
using System.Reflection;
25+
26+
namespace Microsoft.WindowsAzure.ServiceManagemenet.Common.Models
27+
{
28+
public class XunitTracingInterceptor : Hyak.Common.ICloudTracingInterceptor
29+
{
30+
private readonly string callingAssembly;
31+
32+
public XunitTracingInterceptor(ITestOutputHelper output)
33+
{
34+
traceOutput = output;
35+
callingAssembly = Assembly.GetCallingAssembly().FullName.Split(new[] { ',' })[0];
36+
}
37+
38+
public ITestOutputHelper traceOutput;
39+
40+
private void Write(string message, params object[] arguments)
41+
{
42+
try
43+
{
44+
traceOutput.WriteLine(string.Format(message, arguments));
45+
using (StreamWriter file = new StreamWriter(string.Format("{0}.test.log", callingAssembly).AsAbsoluteLocation(), true))
46+
{
47+
file.WriteLine(string.Format(message, arguments));
48+
}
49+
}
50+
catch {}
51+
}
52+
53+
public void Information(string message)
54+
{
55+
Write(message);
56+
}
57+
58+
public void Configuration(string source, string name, string value)
59+
{
60+
// Ignore
61+
}
62+
63+
public void Enter(string invocationId, object instance, string method, IDictionary<string, object> parameters)
64+
{
65+
// Ignore
66+
}
67+
68+
public void SendRequest(string invocationId, HttpRequestMessage request)
69+
{
70+
Write(GeneralUtilities.GetLog(request));
71+
}
72+
73+
public void ReceiveResponse(string invocationId, HttpResponseMessage response)
74+
{
75+
Write(GeneralUtilities.GetLog(response));
76+
}
77+
78+
public void Error(string invocationId, Exception ex)
79+
{
80+
// Ignore
81+
}
82+
83+
public void Exit(string invocationId, object result)
84+
{
85+
// Ignore
86+
}
87+
88+
public static void AddToContext(XunitTracingInterceptor interceptor)
89+
{
90+
RemoveFromContext(interceptor);
91+
TracingAdapter.AddTracingInterceptor(interceptor);
92+
}
93+
94+
public static void RemoveFromContext(XunitTracingInterceptor interceptor)
95+
{
96+
try
97+
{
98+
TracingAdapter.RemoveTracingInterceptor(interceptor);
99+
}
100+
catch
101+
{
102+
// Ignore
103+
}
104+
}
105+
}
106+
}

src/Common/Commands.ScenarioTests.Common/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
66
<package id="Microsoft.Azure.Management.Resources" version="2.18.11-preview" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Test.Framework" version="1.0.5896.19355-prerelease" targetFramework="net45" />
8-
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5896.19355-prerelease" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Test.Framework" version="1.0.5945.28173-prerelease" targetFramework="net45" />
8+
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5945.28173-prerelease" targetFramework="net45" />
99
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1010
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
1111
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/ApiManagementClient.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,5 +1739,27 @@ public PsApiManagementTenantConfigurationSyncState GetTenantConfigurationSyncSta
17391739
}
17401740

17411741
#endregion
1742+
1743+
#region TenantAccessInformation
1744+
public PsApiManagementAccessInformation GetTenantAccessInformation(PsApiManagementContext context)
1745+
{
1746+
var response = Client.TenantAccess.Get(
1747+
context.ResourceGroupName,
1748+
context.ServiceName);
1749+
1750+
return Mapper.Map<PsApiManagementAccessInformation>(response.Value);
1751+
}
1752+
1753+
public void TenantAccessSet(
1754+
PsApiManagementContext context,
1755+
bool enabledTenantAccess)
1756+
{
1757+
var accessInformationParams = new AccessInformationUpdateParameters
1758+
{
1759+
Enabled = enabledTenantAccess
1760+
};
1761+
Client.TenantAccess.Update(context.ResourceGroupName, context.ServiceName, accessInformationParams, "*");
1762+
}
1763+
#endregion
17421764
}
17431765
}

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands.ApiManagement.ServiceManagement.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<Compile Include="Commands\GetAzureApiManagementTenantSyncState.cs" />
161161
<Compile Include="Commands\GetAzureApiManagementUser.cs" />
162162
<Compile Include="Commands\GetAzureApiManagementUserSsoUrl.cs" />
163+
<Compile Include="Commands\GetAzureRmApiManagementTenantAccess.cs" />
163164
<Compile Include="Commands\GetAzureRmApiManagementTenantGitAccess.cs" />
164165
<Compile Include="Commands\ImportAzureApiManagementApi.cs" />
165166
<Compile Include="Commands\NewAzureApiManagementApi.cs" />
@@ -203,6 +204,7 @@
203204
<Compile Include="Commands\SetAzureApiManagementProperty.cs" />
204205
<Compile Include="Commands\SetAzureApiManagementSubscription.cs" />
205206
<Compile Include="Commands\SetAzureApiManagementUser.cs" />
207+
<Compile Include="Commands\SetAzureRmApiManagementTenantAccess.cs" />
206208
<Compile Include="Commands\SetAzureRmApiManagementTenantGitAccess.cs" />
207209
<Compile Include="Constants.cs" />
208210
<Compile Include="Models\ErrorBody.cs" />

0 commit comments

Comments
 (0)