diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs b/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs index 9caea8d8df283..804db915e6111 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs @@ -1355,6 +1355,7 @@ public void UrlPathTests() client.Paths.Base64Url(Encoding.UTF8.GetBytes("lorem")); var testArray = new List { "ArrayPath1", @"begin!*'();:@ &=+$,/?#[]end", null, "" }; client.Paths.ArrayCsvInPath(testArray); + client.Paths.UnixTimeUrl(new DateTime(2016, 4, 13, 0, 0, 0)); } } diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs index ce60b9a5c2f28..d8f9e2c761579 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/IPaths.cs @@ -305,5 +305,18 @@ public partial interface IPaths /// The cancellation token. /// Task ArrayCsvInPathWithHttpMessagesAsync(IList arrayPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time) + /// + /// + /// Unix time encoded value + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task UnixTimeUrlWithHttpMessagesAsync(DateTime unixTimeUrlPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); } } diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs index d880804521f0c..3892f728ba11b 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/Paths.cs @@ -2692,5 +2692,111 @@ public Paths(AutoRestUrlTestService client) return _result; } + /// + /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time) + /// + /// + /// Unix time encoded value + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task UnixTimeUrlWithHttpMessagesAsync(DateTime unixTimeUrlPath, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("unixTimeUrlPath", unixTimeUrlPath); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "UnixTimeUrl", tracingParameters); + } + // Construct URL + var _baseUrl = this.Client.BaseUri.AbsoluteUri; + var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "paths/int/1460505600/{unixTimeUrlPath}").ToString(); + _url = _url.Replace("{unixTimeUrlPath}", Uri.EscapeDataString(SafeJsonConvert.SerializeObject(unixTimeUrlPath, new UnixTimeJsonConverter()).Trim('"'))); + // Create HTTP transport objects + HttpRequestMessage _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("GET"); + _httpRequest.RequestUri = new Uri(_url); + // Set Headers + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + Error _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + } } diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs index 65ea07ea61b8b..b4e8d2ce268e6 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/Expected/AcceptanceTests/Url/PathsExtensions.cs @@ -712,5 +712,36 @@ public static void ArrayCsvInPath(this IPaths operations, IList arrayPat await operations.ArrayCsvInPathWithHttpMessagesAsync(arrayPath, null, cancellationToken).ConfigureAwait(false); } + /// + /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time) + /// + /// + /// The operations group for this extension method. + /// + /// + /// Unix time encoded value + /// + public static void UnixTimeUrl(this IPaths operations, DateTime unixTimeUrlPath) + { + Task.Factory.StartNew(s => ((IPaths)s).UnixTimeUrlAsync(unixTimeUrlPath), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); + } + + /// + /// Get the date 2016-04-13 encoded value as '1460505600' (Unix time) + /// + /// + /// The operations group for this extension method. + /// + /// + /// Unix time encoded value + /// + /// + /// The cancellation token. + /// + public static async Task UnixTimeUrlAsync(this IPaths operations, DateTime unixTimeUrlPath, CancellationToken cancellationToken = default(CancellationToken)) + { + await operations.UnixTimeUrlWithHttpMessagesAsync(unixTimeUrlPath, null, cancellationToken).ConfigureAwait(false); + } + } } diff --git a/AutoRest/TestServer/server/routes/paths.js b/AutoRest/TestServer/server/routes/paths.js index ba1b8e99df9e6..04b5002453c3c 100644 --- a/AutoRest/TestServer/server/routes/paths.js +++ b/AutoRest/TestServer/server/routes/paths.js @@ -23,6 +23,7 @@ var scenarioMap = { "2012-01-01T01:01:01Z": "Valid", "green color" : "Valid", "bG9yZW0" : "Base64Url", + "1460505600": "UnixTime", "ArrayPath1,begin!*'();:@ &=+$,/?#[]end,,": "CSVInPath" }; diff --git a/AutoRest/TestServer/swagger/url.json b/AutoRest/TestServer/swagger/url.json index 4bf4530d177fb..670ff00f9bd1d 100644 --- a/AutoRest/TestServer/swagger/url.json +++ b/AutoRest/TestServer/swagger/url.json @@ -773,6 +773,36 @@ } } }, + "/paths/int/1460505600/{unixTimeUrlPath}": { + "get": { + "operationId": "paths_unixTimeUrl", + "description": "Get the date 2016-04-13 encoded value as '1460505600' (Unix time)", + "tags": [ + "Path Operations" + ], + "parameters": [ + { + "name": "unixTimeUrlPath", + "in": "path", + "description": "Unix time encoded value", + "type": "integer", + "format": "unixtime", + "required": true + } + ], + "responses": { + "200": { + "description": "Successfully Received date 2016-04-13 encoded value as '1460505600' (Unix time)" + }, + "default": { + "description": "Unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, "/queries/bool/true": { "get": { "operationId": "queries_getBooleanTrue",