Skip to content

Commit eb5048d

Browse files
committed
Merge branch 'dev' of github.com:Azure/autorest into subscriptionId
2 parents 1fa5936 + 71d7491 commit eb5048d

24 files changed

Lines changed: 1527 additions & 137 deletions

AutoRest/AutoRest.Core/AutoRest.nuget.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
44
<SdkNuGetPackage Include="AutoRest">
5-
<PackageVersion>1.0.0</PackageVersion>
5+
<PackageVersion>0.10.0</PackageVersion>
66
<Folder>$(MSBuildThisFileDirectory)</Folder>
77
</SdkNuGetPackage>
88
</ItemGroup>

AutoRest/AutoRest.Core/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
[assembly: AssemblyCompany("Microsoft Corporation")]
1212
[assembly: AssemblyProduct("Microsoft AutoRest")]
1313
[assembly: AssemblyCopyright("Copyright © Microsoft Corporation")]
14-
[assembly: AssemblyVersion("1.0.0.0")]
15-
[assembly: AssemblyFileVersion("1.0.0.0")]
14+
[assembly: AssemblyVersion("0.9.0.0")]
15+
[assembly: AssemblyFileVersion("0.10.0.0")]
1616

1717
[assembly: NeutralResourcesLanguage("en")]
1818
[assembly: CLSCompliant(true)]

AutoRest/Generators/CSharp/Azure.CSharp.Tests/AutoRest.Generator.Azure.CSharp.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,16 @@
270270
<Compile Include="Expected\SwaggerBat\Paging.Cs\PagingOperationsExtensions.cs">
271271
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
272272
</Compile>
273-
<Compile Include="Expected\SwaggerBat\Report.Cs\AutoRestReportServiceForAzure.cs">
273+
<Compile Include="Expected\SwaggerBat\AzureReport.Cs\AutoRestReportServiceForAzure.cs">
274274
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
275275
</Compile>
276-
<Compile Include="Expected\SwaggerBat\Report.Cs\AutoRestReportServiceForAzureExtensions.cs">
276+
<Compile Include="Expected\SwaggerBat\AzureReport.Cs\AutoRestReportServiceForAzureExtensions.cs">
277277
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
278278
</Compile>
279-
<Compile Include="Expected\SwaggerBat\Report.Cs\IAutoRestReportServiceForAzure.cs">
279+
<Compile Include="Expected\SwaggerBat\AzureReport.Cs\IAutoRestReportServiceForAzure.cs">
280280
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
281281
</Compile>
282-
<Compile Include="Expected\SwaggerBat\Report.Cs\Models\Error.cs">
282+
<Compile Include="Expected\SwaggerBat\AzureReport.Cs\Models\Error.cs">
283283
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
284284
</Compile>
285285
<Compile Include="Expected\SwaggerBat\ResourceFlattening.Cs\AutoRestResourceFlatteningTestService.cs">

AutoRest/Generators/CSharp/Azure.CSharp.Tests/CSharpAzureSwaggerBat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Fixtures.Azure.SwaggerBatLro.Models;
1313
using Fixtures.Azure.SwaggerBatLro;
1414
using Fixtures.Azure.SwaggerBatPaging;
15-
using Fixtures.Azure.SwaggerBatReport;
1615
using Microsoft.Azure;
1716
using Microsoft.Rest.Generator.CSharp.Tests;
1817
using Microsoft.Rest.Generator.Utilities;
@@ -26,6 +25,7 @@
2625
using Fixtures.Azure.SwaggerBatResourceFlattening;
2726
using Fixtures.Azure.SwaggerBatResourceFlattening.Models;
2827
using Fixtures.Azure.SwaggerBatHead;
28+
using Fixtures.Azure.SwaggerBatAzureReport;
2929

3030
namespace Microsoft.Rest.Generator.CSharp.Azure.Tests
3131
{
@@ -243,7 +243,7 @@ public void PagingSadPathTests()
243243
public void EnsureTestCoverage()
244244
{
245245
SwaggerSpecHelper.RunTests<AzureCSharpCodeGenerator>(
246-
@"Swagger\azure-report.json", @"Expected\SwaggerBat\Report.Cs");
246+
@"Swagger\azure-report.json", @"Expected\SwaggerBat\AzureReport.Cs");
247247
var client =
248248
new AutoRestReportServiceForAzure(Fixture.Uri, new TokenCloudCredentials(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()));
249249
var report = client.GetReport();
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
namespace Fixtures.Azure.SwaggerBatAzureReport
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.Net;
7+
using System.Net.Http;
8+
using System.Net.Http.Headers;
9+
using System.Text;
10+
using System.Text.RegularExpressions;
11+
using System.Threading;
12+
using System.Threading.Tasks;
13+
using Microsoft.Rest;
14+
using Microsoft.Rest.Serialization;
15+
using Newtonsoft.Json;
16+
using Microsoft.Azure;
17+
using Models;
18+
19+
/// <summary>
20+
/// Test Infrastructure for AutoRest
21+
/// </summary>
22+
public partial class AutoRestReportServiceForAzure : ServiceClient<AutoRestReportServiceForAzure>, IAutoRestReportServiceForAzure, IAzureClient
23+
{
24+
/// <summary>
25+
/// The base URI of the service.
26+
/// </summary>
27+
public Uri BaseUri { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets json serialization settings.
31+
/// </summary>
32+
public JsonSerializerSettings SerializationSettings { get; private set; }
33+
34+
/// <summary>
35+
/// Gets or sets json deserialization settings.
36+
/// </summary>
37+
public JsonSerializerSettings DeserializationSettings { get; private set; }
38+
39+
/// <summary>
40+
/// The Api Version.
41+
/// </summary>
42+
public string ApiVersion { get; private set; }
43+
44+
/// <summary>
45+
/// Subscription credentials which uniquely identify Microsoft Azure
46+
/// subscription.
47+
/// </summary>
48+
public SubscriptionCloudCredentials Credentials { get; set; }
49+
50+
/// <summary>
51+
/// The retry timeout for Long Running Operations.
52+
/// </summary>
53+
public int? LongRunningOperationRetryTimeout { get; set; }
54+
55+
/// <summary>
56+
/// Initializes a new instance of the AutoRestReportServiceForAzure class.
57+
/// </summary>
58+
public AutoRestReportServiceForAzure() : base()
59+
{
60+
this.Initialize();
61+
}
62+
63+
/// <summary>
64+
/// Initializes a new instance of the AutoRestReportServiceForAzure class.
65+
/// </summary>
66+
/// <param name='handlers'>
67+
/// Optional. The set of delegating handlers to insert in the http
68+
/// client pipeline.
69+
/// </param>
70+
public AutoRestReportServiceForAzure(params DelegatingHandler[] handlers) : base(handlers)
71+
{
72+
this.Initialize();
73+
}
74+
75+
/// <summary>
76+
/// Initializes a new instance of the AutoRestReportServiceForAzure class.
77+
/// </summary>
78+
/// <param name='rootHandler'>
79+
/// Optional. The http client handler used to handle http transport.
80+
/// </param>
81+
/// <param name='handlers'>
82+
/// Optional. The set of delegating handlers to insert in the http
83+
/// client pipeline.
84+
/// </param>
85+
public AutoRestReportServiceForAzure(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandler, handlers)
86+
{
87+
this.Initialize();
88+
}
89+
90+
/// <summary>
91+
/// Initializes a new instance of the AutoRestReportServiceForAzure class.
92+
/// </summary>
93+
/// <param name='baseUri'>
94+
/// Optional. The base URI of the service.
95+
/// </param>
96+
/// <param name='handlers'>
97+
/// Optional. The set of delegating handlers to insert in the http
98+
/// client pipeline.
99+
/// </param>
100+
public AutoRestReportServiceForAzure(Uri baseUri, params DelegatingHandler[] handlers) : this(handlers)
101+
{
102+
if (baseUri == null)
103+
{
104+
throw new ArgumentNullException("baseUri");
105+
}
106+
this.BaseUri = baseUri;
107+
}
108+
109+
/// <summary>
110+
/// Initializes a new instance of the AutoRestReportServiceForAzure class.
111+
/// </summary>
112+
/// <param name='credentials'>
113+
/// Required. Subscription credentials which uniquely identify Microsoft Azure subscription.
114+
/// </param>
115+
/// <param name='handlers'>
116+
/// Optional. The set of delegating handlers to insert in the http
117+
/// client pipeline.
118+
/// </param>
119+
public AutoRestReportServiceForAzure(SubscriptionCloudCredentials credentials, params DelegatingHandler[] handlers) : this(handlers)
120+
{
121+
if (credentials == null)
122+
{
123+
throw new ArgumentNullException("credentials");
124+
}
125+
this.Credentials = credentials;
126+
}
127+
128+
/// <summary>
129+
/// Initializes a new instance of the AutoRestReportServiceForAzure class.
130+
/// </summary>
131+
/// <param name='baseUri'>
132+
/// Optional. The base URI of the service.
133+
/// </param>
134+
/// <param name='credentials'>
135+
/// Required. Subscription credentials which uniquely identify Microsoft Azure subscription.
136+
/// </param>
137+
/// <param name='handlers'>
138+
/// Optional. The set of delegating handlers to insert in the http
139+
/// client pipeline.
140+
/// </param>
141+
public AutoRestReportServiceForAzure(Uri baseUri, SubscriptionCloudCredentials credentials, params DelegatingHandler[] handlers) : this(handlers)
142+
{
143+
if (baseUri == null)
144+
{
145+
throw new ArgumentNullException("baseUri");
146+
}
147+
if (credentials == null)
148+
{
149+
throw new ArgumentNullException("credentials");
150+
}
151+
this.BaseUri = baseUri;
152+
this.Credentials = credentials;
153+
}
154+
155+
/// <summary>
156+
/// Initializes client properties.
157+
/// </summary>
158+
private void Initialize()
159+
{
160+
this.BaseUri = new Uri("http://localhost");
161+
this.ApiVersion = "1.0.0";
162+
SerializationSettings = new JsonSerializerSettings
163+
{
164+
Formatting = Formatting.Indented,
165+
DateFormatHandling = DateFormatHandling.IsoDateFormat,
166+
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
167+
NullValueHandling = NullValueHandling.Ignore,
168+
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
169+
ContractResolver = new ReadOnlyJsonContractResolver()
170+
};
171+
SerializationSettings.Converters.Add(new ResourceJsonConverter());
172+
DeserializationSettings = new JsonSerializerSettings{
173+
DateFormatHandling = DateFormatHandling.IsoDateFormat,
174+
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
175+
NullValueHandling = NullValueHandling.Ignore,
176+
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
177+
ContractResolver = new ReadOnlyJsonContractResolver()
178+
};
179+
DeserializationSettings.Converters.Add(new ResourceJsonConverter());
180+
DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
181+
}
182+
/// <summary>
183+
/// Get test coverage report
184+
/// </summary>
185+
/// <param name='cancellationToken'>
186+
/// Cancellation token.
187+
/// </param>
188+
public async Task<AzureOperationResponse<IDictionary<string, int?>>> GetReportWithOperationResponseAsync(CancellationToken cancellationToken = default(CancellationToken))
189+
{
190+
// Tracing
191+
bool shouldTrace = ServiceClientTracing.IsEnabled;
192+
string invocationId = null;
193+
if (shouldTrace)
194+
{
195+
invocationId = ServiceClientTracing.NextInvocationId.ToString();
196+
Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
197+
tracingParameters.Add("cancellationToken", cancellationToken);
198+
ServiceClientTracing.Enter(invocationId, this, "GetReport", tracingParameters);
199+
}
200+
// Construct URL
201+
string url = this.BaseUri.AbsoluteUri +
202+
"//report/azure";
203+
List<string> queryParameters = new List<string>();
204+
queryParameters.Add(string.Format("api-version={0}", Uri.EscapeDataString(this.ApiVersion)));
205+
if (queryParameters.Count > 0)
206+
{
207+
url += "?" + string.Join("&", queryParameters);
208+
}
209+
// trim all duplicate forward slashes in the url
210+
url = Regex.Replace(url, "([^:]/)/+", "$1");
211+
// Create HTTP transport objects
212+
HttpRequestMessage httpRequest = new HttpRequestMessage();
213+
httpRequest.Method = new HttpMethod("GET");
214+
httpRequest.RequestUri = new Uri(url);
215+
// Set Headers
216+
// Set Credentials
217+
cancellationToken.ThrowIfCancellationRequested();
218+
await this.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
219+
// Send Request
220+
if (shouldTrace)
221+
{
222+
ServiceClientTracing.SendRequest(invocationId, httpRequest);
223+
}
224+
cancellationToken.ThrowIfCancellationRequested();
225+
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
226+
if (shouldTrace)
227+
{
228+
ServiceClientTracing.ReceiveResponse(invocationId, httpResponse);
229+
}
230+
HttpStatusCode statusCode = httpResponse.StatusCode;
231+
cancellationToken.ThrowIfCancellationRequested();
232+
string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
233+
if (!(statusCode == (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), "OK")))
234+
{
235+
var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", statusCode));
236+
Error errorBody = JsonConvert.DeserializeObject<Error>(responseContent, this.DeserializationSettings);
237+
if (errorBody != null)
238+
{
239+
ex.Body = errorBody;
240+
}
241+
ex.Request = httpRequest;
242+
ex.Response = httpResponse;
243+
if (shouldTrace)
244+
{
245+
ServiceClientTracing.Error(invocationId, ex);
246+
}
247+
throw ex;
248+
}
249+
// Create Result
250+
var result = new AzureOperationResponse<IDictionary<string, int?>>();
251+
result.Request = httpRequest;
252+
result.Response = httpResponse;
253+
// Deserialize Response
254+
if (statusCode == (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), "OK"))
255+
{
256+
result.Body = JsonConvert.DeserializeObject<IDictionary<string, int?>>(responseContent, this.DeserializationSettings);
257+
}
258+
if (shouldTrace)
259+
{
260+
ServiceClientTracing.Exit(invocationId, result);
261+
}
262+
return result;
263+
}
264+
265+
}
266+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace Fixtures.Azure.SwaggerBatAzureReport
2+
{
3+
using System;
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.Rest;
9+
using Microsoft.Azure;
10+
using Models;
11+
12+
public static partial class AutoRestReportServiceForAzureExtensions
13+
{
14+
/// <summary>
15+
/// Get test coverage report
16+
/// </summary>
17+
/// <param name='operations'>
18+
/// The operations group for this extension method
19+
/// </param>
20+
public static IDictionary<string, int?> GetReport(this IAutoRestReportServiceForAzure operations)
21+
{
22+
return Task.Factory.StartNew(s => ((IAutoRestReportServiceForAzure)s).GetReportAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
23+
}
24+
25+
/// <summary>
26+
/// Get test coverage report
27+
/// </summary>
28+
/// <param name='operations'>
29+
/// The operations group for this extension method
30+
/// </param>
31+
/// <param name='cancellationToken'>
32+
/// Cancellation token.
33+
/// </param>
34+
public static async Task<IDictionary<string, int?>> GetReportAsync( this IAutoRestReportServiceForAzure operations, CancellationToken cancellationToken = default(CancellationToken))
35+
{
36+
AzureOperationResponse<IDictionary<string, int?>> result = await operations.GetReportWithOperationResponseAsync(cancellationToken).ConfigureAwait(false);
37+
return result.Body;
38+
}
39+
40+
}
41+
}

0 commit comments

Comments
 (0)