From f05854345598a2be3978557d41c39e34c3f61b65 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Tue, 22 Mar 2016 16:47:05 -0700 Subject: [PATCH 01/19] fix async patch and post run --- .../ms-rest-azure/lib/azureServiceClient.js | 201 ++++++++---------- .../NodeJS/ms-rest-azure/lib/pollingState.js | 65 +++--- 2 files changed, 128 insertions(+), 138 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index ae1798dc5e56a..4b967ca5cd373 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -32,15 +32,15 @@ function AzureServiceClient(credentials, options) { if (!credentials) { throw new Error('Azure clients require credentials.'); } - + AzureServiceClient['super_'].call(this, credentials, options); - + this.acceptLanguage = 'en-US'; this.generateClientRequestId = true; this.longRunningOperationRetryTimeout = 30; if (!options) options = {}; - + if (options.acceptLanguage !== null && options.acceptLanguage !== undefined) { this.acceptLanguage = options.acceptLanguage; } @@ -62,68 +62,73 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfInitialRequest, options, callback) { var self = this; - if(!callback && typeof options === 'function') { + if (!callback && typeof options === 'function') { callback = options; options = null; } if (!callback) { throw new Error('Missing callback'); } - + if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - + + if (!resultOfInitialRequest.response) { + return callback(new Error('Missing resultOfInitialRequest.response')); + } + if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 201 && - resultOfInitialRequest.response.statusCode !== 202) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', + resultOfInitialRequest.response.statusCode !== 201 && + resultOfInitialRequest.response.statusCode !== 202 && + resultOfInitialRequest.response.statusCode !== 204) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', resultOfInitialRequest.response.statusCode))); } + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } - var resourceUrl = resultOfInitialRequest.request.url; this._options = options; - + async.whilst( - //while condition - function () { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function (e) { - return pollingState.status === e; + function() { + var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { + return e === pollingState.status; }); return !finished; }, - //while loop body - function (callback) { - setTimeout(function () { + function(callback) { + setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, false, function (err) { + self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeaderOnPut(pollingState, function (err) { + self._updateStateFromLocationHeader(pollingState, function(err) { return callback(err); }); - } else { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function (err) { + } else if (resultOfInitialRequest.request.method === "PUT") { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); + } else { + return callback(new Error('Location header is missing from long running operation.')); } }, pollingState.getTimeout()); }, //when done - function (err) { + function(err) { if (pollingState.status === LroStates.Succeeded) { - if (!pollingState.resource) { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function (err) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== "DELETE" && resultOfInitialRequest.request.method !== "POST") { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); } else { @@ -142,9 +147,9 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfInitialRequest, options, callback) { var self = this; - + if (!callback && typeof options === 'function') { callback = options; options = null; @@ -152,45 +157,52 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf if (!callback) { throw new Error('Missing callback'); } - + if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - + if (!resultOfInitialRequest.response) { return callback(new Error('Missing resultOfInitialRequest.response')); } - + if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 202 && - resultOfInitialRequest.response.statusCode !== 204) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', + resultOfInitialRequest.response.statusCode !== 201 && + resultOfInitialRequest.response.statusCode !== 202 && + resultOfInitialRequest.response.statusCode !== 204) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', resultOfInitialRequest.response.statusCode))); } - + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } + + var resourceUrl = resultOfInitialRequest.request.url; this._options = options; async.whilst( - function () { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function (e) { + function() { + var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { return e === pollingState.status; }); return !finished; }, - function (callback) { - setTimeout(function () { + function(callback) { + setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function (err) { + self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeaderOnPostOrDelete(pollingState, function (err) { + self._updateStateFromLocationHeader(pollingState, function(err) { + return callback(err); + }); + } else if (resultOfInitialRequest.request.method === "PUT") { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); } else { @@ -198,9 +210,16 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf } }, pollingState.getTimeout()); }, - function (err) { - if (pollingState.status === LroStates.Succeeded ) { - return callback(null, pollingState.getOperationResponse()); + //when done + function(err) { + if (pollingState.status === LroStates.Succeeded) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== "DELETE" && resultOfInitialRequest.request.method !== "POST") { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { + return callback(err, pollingState.getOperationResponse()); + }); + } else { + return callback(null, pollingState.getOperationResponse()); + } } else { return callback(pollingState.getCloudError(err)); } @@ -212,14 +231,14 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf * @param {object} [pollingState] - The object to persist current operation state. * @param {boolean} [inPostOrDelete] - Invoked by Post Or Delete operation. */ -AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = function (pollingState, inPostOrDelete, callback) { - this._getStatus(pollingState.azureAsyncOperationHeaderLink, function (err, result) { +AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = function(pollingState, inPostOrDelete, callback) { + this._getStatus(pollingState.azureAsyncOperationHeaderLink, function(err, result) { if (err) return callback(err); - + if (!result.body || !result.body.status) { return callback(new Error('The response from long running operation does not contain a body.')); } - + pollingState.status = result.body.status; pollingState.error = result.body.error; pollingState.response = result.response; @@ -233,36 +252,25 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio }; /** - * Retrieve PUT operation status by polling from 'location' header. + * Retrieve PUT/POST/PATCH/DELETE operation status by polling from 'location' header. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromLocationHeaderOnPut = function (pollingState, callback) { - this._getStatus(pollingState.locationHeaderLink, function (err, result) { +AzureServiceClient.prototype._updateStateFromLocationHeader = function(pollingState, callback) { + this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); - + pollingState.updateResponse(result.response); pollingState.request = result.request; - + var statusCode = result.response.statusCode; if (statusCode === 202) { pollingState.status = LroStates.InProgress; - } - else if (statusCode === 200 || - statusCode === 201) { - - if (!result.body) { - return callback(new Error('The response from long running operation does not contain a body.')); - } - - // In 202 pattern on PUT ProvisioningState may not be present in - // the response. In that case the assumption is the status is Succeeded. - if (result.body.properties && result.body.properties.provisioningState) { - pollingState.status = result.body.properties.provisioningState; - } - else { - pollingState.status = LroStates.Succeeded; - } - + } else if (statusCode === 200 || + statusCode === 201 || + statusCode === 204) { + + pollingState.status = LroStates.Succeeded; + pollingState.error = { code: pollingState.Status, message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) @@ -273,59 +281,34 @@ AzureServiceClient.prototype._updateStateFromLocationHeaderOnPut = function (pol }); }; -/** - * Retrieve POST or DELETE operation status by polling from 'location' header. - * @param {object} [pollingState] - The object to persist current operation state. - */ -AzureServiceClient.prototype._updateStateFromLocationHeaderOnPostOrDelete = function (pollingState, callback) { - this._getStatus(pollingState.locationHeaderLink, function (err, result) { - if (err) return callback(err); - - pollingState.updateResponse(result.response); - pollingState.request = result.request; - - var statusCode = result.response.statusCode; - if (statusCode === 202) { - pollingState.status = LroStates.InProgress; - } - else if (statusCode === 200 || - statusCode === 201 || - statusCode === 204) { - pollingState.status = LroStates.Succeeded; - pollingState.resource = result.body; - } - callback(null); - }); -}; - /** * Polling for resource status. * @param {function} [resourceUrl] - The url of resource. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromGetResourceOperation = function (resourceUrl, pollingState, callback) { - this._getStatus(resourceUrl, function (err, result) { +AzureServiceClient.prototype._updateStateFromGetResourceOperation = function(resourceUrl, pollingState, callback) { + this._getStatus(resourceUrl, function(err, result) { if (err) return callback(err); if (!result.body) { return callback(new Error('The response from long running operation does not contain a body.')); } - + if (result.body.properties && result.body.properties.provisioningState) { pollingState.status = result.body.properties.provisioningState; } else { pollingState.status = LroStates.Succeeded; } - + //we might not throw an error, but initialize here just in case. pollingState.error = { code: pollingState.status, message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) }; - + pollingState.updateResponse(result.response); pollingState.request = result.request; pollingState.resource = result.body; - + //nothing to return, the 'pollingState' has all the info we care. callback(null); }); @@ -335,21 +318,21 @@ AzureServiceClient.prototype._updateStateFromGetResourceOperation = function (re * Retrieve operation status by querying the operation URL. * @param {string} [operationUrl] - URL used to poll operation result. */ -AzureServiceClient.prototype._getStatus = function (operationUrl, callback) { +AzureServiceClient.prototype._getStatus = function(operationUrl, callback) { var self = this; if (!operationUrl) { return callback(new Error('operationUrl cannot be null.')); } - + // Construct URL var requestUrl = operationUrl.replace(' ', '%20'); - + // Create HTTP transport objects var httpRequest = new WebResource(); httpRequest.method = 'GET'; httpRequest.headers = {}; httpRequest.url = requestUrl; - if(this._options) { + if (this._options) { for (var headerName in this._options['customHeaders']) { if (this._options['customHeaders'].hasOwnProperty(headerName)) { httpRequest.headers[headerName] = this._options['customHeaders'][headerName]; @@ -357,13 +340,13 @@ AzureServiceClient.prototype._getStatus = function (operationUrl, callback) { } } // Send Request - return self.pipeline(httpRequest, function (err, response, responseBody) { + return self.pipeline(httpRequest, function(err, response, responseBody) { if (err) { return callback(err); } var statusCode = response.statusCode; if (statusCode !== 200 && statusCode !== 201 && statusCode !== 202 && statusCode !== 204) { - var error = new Error(util.format('Invalid status code with response body "%s" occurred ' + + var error = new Error(util.format('Invalid status code with response body "%s" occurred ' + 'when polling for operation status.', responseBody)); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -388,8 +371,8 @@ AzureServiceClient.prototype._getStatus = function (operationUrl, callback) { try { result.body = JSON.parse(responseBody); } catch (deserializationError) { - var parseError = new Error(util.format('Error "%s" occurred in deserializing the response body - "%s" -' + - ' when polling for operation status.', deserializationError, responseBody)); + var parseError = new Error(util.format('Error "%s" occurred in deserializing the response body - "%s" -' + + ' when polling for operation status.', deserializationError, responseBody)); parseError.request = msRest.stripRequest(httpRequest); parseError.response = msRest.stripResponse(response); parseError.body = responseBody; diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js index 87a68bf6dfc25..0d7c48fd1df0b 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js @@ -25,39 +25,46 @@ function PollingState(resultOfInitialRequest, retryTimeout) { this.request = resultOfInitialRequest.request; //Parse response.body & assign it as the resource try { - if (resultOfInitialRequest.body && - typeof resultOfInitialRequest.body.valueOf() === 'string' && - resultOfInitialRequest.body.length > 0) { + if (resultOfInitialRequest.body && + typeof resultOfInitialRequest.body.valueOf() === 'string' && + resultOfInitialRequest.body.length > 0) { this.resource = JSON.parse(resultOfInitialRequest.body); } else { this.resource = resultOfInitialRequest.body; - } + } } catch (error) { - var deserializationError = new Error(util.format('Error "%s" occurred in parsing the responseBody ' + + var deserializationError = new Error(util.format('Error "%s" occurred in parsing the responseBody ' + 'while creating the PollingState for Long Running Operation- "%s"', error, resultOfInitialRequest.body)); deserializationError.request = resultOfInitialRequest.request; deserializationError.response = resultOfInitialRequest.response; throw deserializationError; } - - if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { - this.status = this.resource.properties.provisioningState; - } else { - switch (this.response.statusCode) { - case 202: - this.status = LroStates.InProgress; - break; - case 204: - case 201: - case 200: - this.status = LroStates.Succeeded; - break; + switch (this.response.statusCode) { + case 202: + this.status = LroStates.InProgress; + break; - default: - this.status = LroStates.Failed; - break; - } + case 204: + this.status = LroStates.Succeeded; + break; + case 201: + if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { + this.status = this.resource.properties.provisioningState; + } else { + this.status = LroStates.InProgress; + } + break; + case 200: + if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { + this.status = this.resource.properties.provisioningState; + } else { + this.status = LroStates.Succeeded; + } + break; + default: + this.status = LroStates.Failed; + break; } } @@ -65,7 +72,7 @@ function PollingState(resultOfInitialRequest, retryTimeout) { * Gets timeout in milliseconds. * @returns {number} timeout */ -PollingState.prototype.getTimeout = function () { +PollingState.prototype.getTimeout = function() { if (this._retryTimeout || this._retryTimeout === 0) { return this._retryTimeout * 1000; } @@ -79,13 +86,13 @@ PollingState.prototype.getTimeout = function () { * Update cached data using the provided response object * @param {object} [response] - provider response object. */ -PollingState.prototype.updateResponse = function (response) { +PollingState.prototype.updateResponse = function(response) { this.response = response; if (response && response.headers) { if (response.headers['azure-asyncoperation']) { this.azureAsyncOperationHeaderLink = response.headers['azure-asyncoperation']; } - + if (response.headers['location']) { this.locationHeaderLink = response.headers['location']; } @@ -96,7 +103,7 @@ PollingState.prototype.updateResponse = function (response) { * Returns long running operation result. * @returns {object} HttpOperationResponse */ -PollingState.prototype.getOperationResponse = function () { +PollingState.prototype.getOperationResponse = function() { var result = new msRest.HttpOperationResponse(); result.request = this.request; result.response = this.response; @@ -112,7 +119,7 @@ PollingState.prototype.getOperationResponse = function () { * Returns an Error on operation failure. * @returns {object} Error */ -PollingState.prototype.getCloudError = function (err) { +PollingState.prototype.getCloudError = function(err) { var errMsg; var errCode; @@ -126,11 +133,11 @@ PollingState.prototype.getCloudError = function (err) { parsedResponse = JSON.parse(this.response.body); } } catch (err) { - error.message = util.format('Error "%s" occurred while deserializing the error ' + + error.message = util.format('Error "%s" occurred while deserializing the error ' + 'message "%s" for long running operation.', err.message, this.response.body); return error; } - + if (err && err.message) { errMsg = util.format('Long running operation failed with error: \'%s\'.', err.message); } else { From b789377b723611732d63266140f6592fd817d837 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 23 Mar 2016 10:43:45 -0700 Subject: [PATCH 02/19] add test for fixing the post/patch async operation --- .../ms-rest-azure/lib/azureServiceClient.js | 8 +-- .../test/azureServiceClientTests.js | 50 ++++++++++++++++++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index 4b967ca5cd373..4a7ce94cf713a 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -115,7 +115,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfIni self._updateStateFromLocationHeader(pollingState, function(err) { return callback(err); }); - } else if (resultOfInitialRequest.request.method === "PUT") { + } else if (resultOfInitialRequest.request.method === 'PUT') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); @@ -127,7 +127,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfIni //when done function(err) { if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== "DELETE" && resultOfInitialRequest.request.method !== "POST") { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); @@ -201,7 +201,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI self._updateStateFromLocationHeader(pollingState, function(err) { return callback(err); }); - } else if (resultOfInitialRequest.request.method === "PUT") { + } else if (resultOfInitialRequest.request.method === 'PUT') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); @@ -213,7 +213,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI //when done function(err) { if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== "DELETE" && resultOfInitialRequest.request.method !== "POST") { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index e28f44bf5ad68..bab92dc1e627c 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -156,11 +156,56 @@ describe('AzureServiceClient', function () { }); }); + describe('Patch', function () { + resultOfInitialRequest.response.statusCode = 202; + resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + + it('works by polling from azure-asyncoperation header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; + resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + should.not.exist(err); + JSON.parse(result.body).name.should.equal(testResourceName); + should.exist(result.response.randomFieldFromPollLocationHeader); + done(); + }); + }); + + it('works by polling from location header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; + resultOfInitialRequest.response.headers['location'] = ''; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + should.not.exist(err); + JSON.parse(result.body).name.should.equal(testResourceName); + done(); + }); + }); + + it('returns error if failed to poll from the azure-asyncoperation header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; + resultOfInitialRequest.response.headers['location'] = ''; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + err.message.should.containEql(testError); + done(); + }); + }); + + it('returns error if failed to poll from the location header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; + resultOfInitialRequest.response.headers['location'] = url_ReturnError; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + err.message.should.containEql(testError); + done(); + }); + }); + }); + describe('Post-or-Delete', function () { resultOfInitialRequest.response.statusCode = 202; - + resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + it('throw on not Lro related status code', function (done) { - client.getPostOrDeleteOperationResult({ response: { statusCode: 201 } }, function (err, result) { + client.getPostOrDeleteOperationResult({ response: { statusCode: 203 }, request: {url: url_resource}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -169,6 +214,7 @@ describe('AzureServiceClient', function () { it('works by polling from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; + resultOfInitialRequest.request.method = 'POST'; client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollAsyncOpHeader); From 9c7e28b27cdc5b49900ce005b1c4c6a06290264c Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Thu, 24 Mar 2016 10:09:33 -0700 Subject: [PATCH 03/19] code revise --- .../ms-rest-azure/lib/azureServiceClient.js | 83 ++++++++++--------- .../NodeJS/ms-rest-azure/lib/pollingState.js | 26 +++--- .../test/azureServiceClientTests.js | 4 +- 3 files changed, 60 insertions(+), 53 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index 4a7ce94cf713a..dabedd8d3217c 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -32,15 +32,15 @@ function AzureServiceClient(credentials, options) { if (!credentials) { throw new Error('Azure clients require credentials.'); } - + AzureServiceClient['super_'].call(this, credentials, options); - + this.acceptLanguage = 'en-US'; this.generateClientRequestId = true; this.longRunningOperationRetryTimeout = 30; if (!options) options = {}; - + if (options.acceptLanguage !== null && options.acceptLanguage !== undefined) { this.acceptLanguage = options.acceptLanguage; } @@ -62,7 +62,7 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; if (!callback && typeof options === 'function') { @@ -81,12 +81,10 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfIni return callback(new Error('Missing resultOfInitialRequest.response')); } - if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 201 && - resultOfInitialRequest.response.statusCode !== 202 && - resultOfInitialRequest.response.statusCode !== 204) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', - resultOfInitialRequest.response.statusCode))); + if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', + resultOfInitialRequest.response.statusCode, + resultOfInitialRequest.request.method))); } var pollingState = null; @@ -147,7 +145,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function(resultOfIni * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; if (!callback && typeof options === 'function') { @@ -166,12 +164,10 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI return callback(new Error('Missing resultOfInitialRequest.response')); } - if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 201 && - resultOfInitialRequest.response.statusCode !== 202 && - resultOfInitialRequest.response.statusCode !== 204) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', - resultOfInitialRequest.response.statusCode))); + if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', + resultOfInitialRequest.response.statusCode, + resultOfInitialRequest.request.method))); } var pollingState = null; @@ -180,7 +176,6 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI } catch (error) { callback(error); } - var resourceUrl = resultOfInitialRequest.request.url; this._options = options; @@ -226,19 +221,31 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function(resultOfI }); }; +AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) { + if (initialRequest.response.statusCode === 200 || + initialRequest.response.statusCode === 202 || + (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || + (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { + return false; + } else { + return true; + } +}; + + /** * Retrieve operation status by polling from 'azure-asyncoperation' header. * @param {object} [pollingState] - The object to persist current operation state. * @param {boolean} [inPostOrDelete] - Invoked by Post Or Delete operation. */ -AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = function(pollingState, inPostOrDelete, callback) { - this._getStatus(pollingState.azureAsyncOperationHeaderLink, function(err, result) { +AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = function (pollingState, inPostOrDelete, callback) { + this._getStatus(pollingState.azureAsyncOperationHeaderLink, function (err, result) { if (err) return callback(err); - + if (!result.body || !result.body.status) { return callback(new Error('The response from long running operation does not contain a body.')); } - + pollingState.status = result.body.status; pollingState.error = result.body.error; pollingState.response = result.response; @@ -252,10 +259,10 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio }; /** - * Retrieve PUT/POST/PATCH/DELETE operation status by polling from 'location' header. + * Retrieve PUT operation status by polling from 'location' header. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromLocationHeader = function(pollingState, callback) { +AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) { this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); @@ -286,29 +293,29 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function(pollingSt * @param {function} [resourceUrl] - The url of resource. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromGetResourceOperation = function(resourceUrl, pollingState, callback) { - this._getStatus(resourceUrl, function(err, result) { +AzureServiceClient.prototype._updateStateFromGetResourceOperation = function (resourceUrl, pollingState, callback) { + this._getStatus(resourceUrl, function (err, result) { if (err) return callback(err); if (!result.body) { return callback(new Error('The response from long running operation does not contain a body.')); } - + if (result.body.properties && result.body.properties.provisioningState) { pollingState.status = result.body.properties.provisioningState; } else { pollingState.status = LroStates.Succeeded; } - + //we might not throw an error, but initialize here just in case. pollingState.error = { code: pollingState.status, message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) }; - + pollingState.updateResponse(result.response); pollingState.request = result.request; pollingState.resource = result.body; - + //nothing to return, the 'pollingState' has all the info we care. callback(null); }); @@ -318,21 +325,21 @@ AzureServiceClient.prototype._updateStateFromGetResourceOperation = function(res * Retrieve operation status by querying the operation URL. * @param {string} [operationUrl] - URL used to poll operation result. */ -AzureServiceClient.prototype._getStatus = function(operationUrl, callback) { +AzureServiceClient.prototype._getStatus = function (operationUrl, callback) { var self = this; if (!operationUrl) { return callback(new Error('operationUrl cannot be null.')); } - + // Construct URL var requestUrl = operationUrl.replace(' ', '%20'); - + // Create HTTP transport objects var httpRequest = new WebResource(); httpRequest.method = 'GET'; httpRequest.headers = {}; httpRequest.url = requestUrl; - if (this._options) { + if(this._options) { for (var headerName in this._options['customHeaders']) { if (this._options['customHeaders'].hasOwnProperty(headerName)) { httpRequest.headers[headerName] = this._options['customHeaders'][headerName]; @@ -340,13 +347,13 @@ AzureServiceClient.prototype._getStatus = function(operationUrl, callback) { } } // Send Request - return self.pipeline(httpRequest, function(err, response, responseBody) { + return self.pipeline(httpRequest, function (err, response, responseBody) { if (err) { return callback(err); } var statusCode = response.statusCode; if (statusCode !== 200 && statusCode !== 201 && statusCode !== 202 && statusCode !== 204) { - var error = new Error(util.format('Invalid status code with response body "%s" occurred ' + + var error = new Error(util.format('Invalid status code with response body "%s" occurred ' + 'when polling for operation status.', responseBody)); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -371,8 +378,8 @@ AzureServiceClient.prototype._getStatus = function(operationUrl, callback) { try { result.body = JSON.parse(responseBody); } catch (deserializationError) { - var parseError = new Error(util.format('Error "%s" occurred in deserializing the response body - "%s" -' + - ' when polling for operation status.', deserializationError, responseBody)); + var parseError = new Error(util.format('Error "%s" occurred in deserializing the response body - "%s" -' + + ' when polling for operation status.', deserializationError, responseBody)); parseError.request = msRest.stripRequest(httpRequest); parseError.response = msRest.stripResponse(response); parseError.body = responseBody; diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js index 0d7c48fd1df0b..114eedf25c573 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js @@ -25,21 +25,21 @@ function PollingState(resultOfInitialRequest, retryTimeout) { this.request = resultOfInitialRequest.request; //Parse response.body & assign it as the resource try { - if (resultOfInitialRequest.body && - typeof resultOfInitialRequest.body.valueOf() === 'string' && - resultOfInitialRequest.body.length > 0) { + if (resultOfInitialRequest.body && + typeof resultOfInitialRequest.body.valueOf() === 'string' && + resultOfInitialRequest.body.length > 0) { this.resource = JSON.parse(resultOfInitialRequest.body); } else { this.resource = resultOfInitialRequest.body; - } + } } catch (error) { - var deserializationError = new Error(util.format('Error "%s" occurred in parsing the responseBody ' + + var deserializationError = new Error(util.format('Error "%s" occurred in parsing the responseBody ' + 'while creating the PollingState for Long Running Operation- "%s"', error, resultOfInitialRequest.body)); deserializationError.request = resultOfInitialRequest.request; deserializationError.response = resultOfInitialRequest.response; throw deserializationError; } - + switch (this.response.statusCode) { case 202: this.status = LroStates.InProgress; @@ -72,7 +72,7 @@ function PollingState(resultOfInitialRequest, retryTimeout) { * Gets timeout in milliseconds. * @returns {number} timeout */ -PollingState.prototype.getTimeout = function() { +PollingState.prototype.getTimeout = function () { if (this._retryTimeout || this._retryTimeout === 0) { return this._retryTimeout * 1000; } @@ -86,13 +86,13 @@ PollingState.prototype.getTimeout = function() { * Update cached data using the provided response object * @param {object} [response] - provider response object. */ -PollingState.prototype.updateResponse = function(response) { +PollingState.prototype.updateResponse = function (response) { this.response = response; if (response && response.headers) { if (response.headers['azure-asyncoperation']) { this.azureAsyncOperationHeaderLink = response.headers['azure-asyncoperation']; } - + if (response.headers['location']) { this.locationHeaderLink = response.headers['location']; } @@ -103,7 +103,7 @@ PollingState.prototype.updateResponse = function(response) { * Returns long running operation result. * @returns {object} HttpOperationResponse */ -PollingState.prototype.getOperationResponse = function() { +PollingState.prototype.getOperationResponse = function () { var result = new msRest.HttpOperationResponse(); result.request = this.request; result.response = this.response; @@ -119,7 +119,7 @@ PollingState.prototype.getOperationResponse = function() { * Returns an Error on operation failure. * @returns {object} Error */ -PollingState.prototype.getCloudError = function(err) { +PollingState.prototype.getCloudError = function (err) { var errMsg; var errCode; @@ -133,11 +133,11 @@ PollingState.prototype.getCloudError = function(err) { parsedResponse = JSON.parse(this.response.body); } } catch (err) { - error.message = util.format('Error "%s" occurred while deserializing the error ' + + error.message = util.format('Error "%s" occurred while deserializing the error ' + 'message "%s" for long running operation.', err.message, this.response.body); return error; } - + if (err && err.message) { errMsg = util.format('Long running operation failed with error: \'%s\'.', err.message); } else { diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index bab92dc1e627c..f358540bb6aae 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -92,7 +92,7 @@ describe('AzureServiceClient', function () { describe('Put', function () { resultOfInitialRequest.response.statusCode = 201; - + it('throw on not Lro related status code', function (done) { client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); @@ -205,7 +205,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; it('throw on not Lro related status code', function (done) { - client.getPostOrDeleteOperationResult({ response: { statusCode: 203 }, request: {url: url_resource}}, function (err, result) { + client.getPostOrDeleteOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); From 6e478d4e7c98b1a625715aeebf6809116e297110 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Tue, 22 Mar 2016 16:47:05 -0700 Subject: [PATCH 04/19] fix async patch and post run --- .../ms-rest-azure/lib/azureServiceClient.js | 168 ++++++++---------- .../NodeJS/ms-rest-azure/lib/pollingState.js | 39 ++-- .../test/azureServiceClientTests.js | 52 +++++- 3 files changed, 151 insertions(+), 108 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index ae1798dc5e56a..dabedd8d3217c 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -65,65 +65,68 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; - if(!callback && typeof options === 'function') { + if (!callback && typeof options === 'function') { callback = options; options = null; } if (!callback) { throw new Error('Missing callback'); } - + if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - - if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 201 && - resultOfInitialRequest.response.statusCode !== 202) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', - resultOfInitialRequest.response.statusCode))); + + if (!resultOfInitialRequest.response) { + return callback(new Error('Missing resultOfInitialRequest.response')); + } + + if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', + resultOfInitialRequest.response.statusCode, + resultOfInitialRequest.request.method))); } + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } - var resourceUrl = resultOfInitialRequest.request.url; this._options = options; - + async.whilst( - //while condition - function () { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function (e) { - return pollingState.status === e; + function() { + var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { + return e === pollingState.status; }); return !finished; }, - //while loop body - function (callback) { - setTimeout(function () { + function(callback) { + setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, false, function (err) { + self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeaderOnPut(pollingState, function (err) { + self._updateStateFromLocationHeader(pollingState, function(err) { return callback(err); }); - } else { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function (err) { + } else if (resultOfInitialRequest.request.method === 'PUT') { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); + } else { + return callback(new Error('Location header is missing from long running operation.')); } }, pollingState.getTimeout()); }, //when done - function (err) { + function(err) { if (pollingState.status === LroStates.Succeeded) { - if (!pollingState.resource) { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function (err) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); } else { @@ -144,7 +147,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn */ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; - + if (!callback && typeof options === 'function') { callback = options; options = null; @@ -152,45 +155,49 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf if (!callback) { throw new Error('Missing callback'); } - + if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - + if (!resultOfInitialRequest.response) { return callback(new Error('Missing resultOfInitialRequest.response')); } - - if (resultOfInitialRequest.response.statusCode !== 200 && - resultOfInitialRequest.response.statusCode !== 202 && - resultOfInitialRequest.response.statusCode !== 204) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\'', - resultOfInitialRequest.response.statusCode))); + + if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', + resultOfInitialRequest.response.statusCode, + resultOfInitialRequest.request.method))); } - + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } + var resourceUrl = resultOfInitialRequest.request.url; this._options = options; async.whilst( - function () { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function (e) { + function() { + var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { return e === pollingState.status; }); return !finished; }, - function (callback) { - setTimeout(function () { + function(callback) { + setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function (err) { + self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeaderOnPostOrDelete(pollingState, function (err) { + self._updateStateFromLocationHeader(pollingState, function(err) { + return callback(err); + }); + } else if (resultOfInitialRequest.request.method === 'PUT') { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); } else { @@ -198,15 +205,34 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf } }, pollingState.getTimeout()); }, - function (err) { - if (pollingState.status === LroStates.Succeeded ) { - return callback(null, pollingState.getOperationResponse()); + //when done + function(err) { + if (pollingState.status === LroStates.Succeeded) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { + self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { + return callback(err, pollingState.getOperationResponse()); + }); + } else { + return callback(null, pollingState.getOperationResponse()); + } } else { return callback(pollingState.getCloudError(err)); } }); }; +AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) { + if (initialRequest.response.statusCode === 200 || + initialRequest.response.statusCode === 202 || + (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || + (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { + return false; + } else { + return true; + } +}; + + /** * Retrieve operation status by polling from 'azure-asyncoperation' header. * @param {object} [pollingState] - The object to persist current operation state. @@ -236,33 +262,22 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio * Retrieve PUT operation status by polling from 'location' header. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromLocationHeaderOnPut = function (pollingState, callback) { - this._getStatus(pollingState.locationHeaderLink, function (err, result) { +AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) { + this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); - + pollingState.updateResponse(result.response); pollingState.request = result.request; - + var statusCode = result.response.statusCode; if (statusCode === 202) { pollingState.status = LroStates.InProgress; - } - else if (statusCode === 200 || - statusCode === 201) { - - if (!result.body) { - return callback(new Error('The response from long running operation does not contain a body.')); - } - - // In 202 pattern on PUT ProvisioningState may not be present in - // the response. In that case the assumption is the status is Succeeded. - if (result.body.properties && result.body.properties.provisioningState) { - pollingState.status = result.body.properties.provisioningState; - } - else { - pollingState.status = LroStates.Succeeded; - } - + } else if (statusCode === 200 || + statusCode === 201 || + statusCode === 204) { + + pollingState.status = LroStates.Succeeded; + pollingState.error = { code: pollingState.Status, message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) @@ -273,31 +288,6 @@ AzureServiceClient.prototype._updateStateFromLocationHeaderOnPut = function (pol }); }; -/** - * Retrieve POST or DELETE operation status by polling from 'location' header. - * @param {object} [pollingState] - The object to persist current operation state. - */ -AzureServiceClient.prototype._updateStateFromLocationHeaderOnPostOrDelete = function (pollingState, callback) { - this._getStatus(pollingState.locationHeaderLink, function (err, result) { - if (err) return callback(err); - - pollingState.updateResponse(result.response); - pollingState.request = result.request; - - var statusCode = result.response.statusCode; - if (statusCode === 202) { - pollingState.status = LroStates.InProgress; - } - else if (statusCode === 200 || - statusCode === 201 || - statusCode === 204) { - pollingState.status = LroStates.Succeeded; - pollingState.resource = result.body; - } - callback(null); - }); -}; - /** * Polling for resource status. * @param {function} [resourceUrl] - The url of resource. diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js index 87a68bf6dfc25..114eedf25c573 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/pollingState.js @@ -40,24 +40,31 @@ function PollingState(resultOfInitialRequest, retryTimeout) { throw deserializationError; } - if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { - this.status = this.resource.properties.provisioningState; - } else { - switch (this.response.statusCode) { - case 202: - this.status = LroStates.InProgress; - break; + switch (this.response.statusCode) { + case 202: + this.status = LroStates.InProgress; + break; - case 204: - case 201: - case 200: + case 204: + this.status = LroStates.Succeeded; + break; + case 201: + if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { + this.status = this.resource.properties.provisioningState; + } else { + this.status = LroStates.InProgress; + } + break; + case 200: + if (this.resource && this.resource.properties && this.resource.properties.provisioningState) { + this.status = this.resource.properties.provisioningState; + } else { this.status = LroStates.Succeeded; - break; - - default: - this.status = LroStates.Failed; - break; - } + } + break; + default: + this.status = LroStates.Failed; + break; } } diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index e28f44bf5ad68..f358540bb6aae 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -92,7 +92,7 @@ describe('AzureServiceClient', function () { describe('Put', function () { resultOfInitialRequest.response.statusCode = 201; - + it('throw on not Lro related status code', function (done) { client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); @@ -156,11 +156,56 @@ describe('AzureServiceClient', function () { }); }); + describe('Patch', function () { + resultOfInitialRequest.response.statusCode = 202; + resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + + it('works by polling from azure-asyncoperation header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; + resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + should.not.exist(err); + JSON.parse(result.body).name.should.equal(testResourceName); + should.exist(result.response.randomFieldFromPollLocationHeader); + done(); + }); + }); + + it('works by polling from location header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; + resultOfInitialRequest.response.headers['location'] = ''; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + should.not.exist(err); + JSON.parse(result.body).name.should.equal(testResourceName); + done(); + }); + }); + + it('returns error if failed to poll from the azure-asyncoperation header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; + resultOfInitialRequest.response.headers['location'] = ''; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + err.message.should.containEql(testError); + done(); + }); + }); + + it('returns error if failed to poll from the location header', function (done) { + resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; + resultOfInitialRequest.response.headers['location'] = url_ReturnError; + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + err.message.should.containEql(testError); + done(); + }); + }); + }); + describe('Post-or-Delete', function () { resultOfInitialRequest.response.statusCode = 202; - + resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + it('throw on not Lro related status code', function (done) { - client.getPostOrDeleteOperationResult({ response: { statusCode: 201 } }, function (err, result) { + client.getPostOrDeleteOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -169,6 +214,7 @@ describe('AzureServiceClient', function () { it('works by polling from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; + resultOfInitialRequest.request.method = 'POST'; client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollAsyncOpHeader); From 4ab8892519dfbb10ce902be4471ea9f45ca83ef4 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Thu, 24 Mar 2016 10:21:36 -0700 Subject: [PATCH 05/19] style change --- .../ms-rest-azure/lib/azureServiceClient.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index dabedd8d3217c..fa2e530176f81 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -65,7 +65,7 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; - if (!callback && typeof options === 'function') { + if(!callback && typeof options === 'function') { callback = options; options = null; } @@ -86,13 +86,14 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn resultOfInitialRequest.response.statusCode, resultOfInitialRequest.request.method))); } - + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { callback(error); } + var resourceUrl = resultOfInitialRequest.request.url; this._options = options; @@ -123,7 +124,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn }, pollingState.getTimeout()); }, //when done - function(err) { + function (err) { if (pollingState.status === LroStates.Succeeded) { if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { @@ -147,7 +148,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn */ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; - + if (!callback && typeof options === 'function') { callback = options; options = null; @@ -159,7 +160,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf if (!resultOfInitialRequest) { return callback(new Error('Missing resultOfInitialRequest parameter')); } - + if (!resultOfInitialRequest.response) { return callback(new Error('Missing resultOfInitialRequest.response')); } @@ -169,7 +170,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf resultOfInitialRequest.response.statusCode, resultOfInitialRequest.request.method))); } - + var pollingState = null; try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); @@ -186,7 +187,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf }); return !finished; }, - function(callback) { + function (callback) { setTimeout(function() { if (pollingState.azureAsyncOperationHeaderLink) { self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { @@ -206,7 +207,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf }, pollingState.getTimeout()); }, //when done - function(err) { + function (err) { if (pollingState.status === LroStates.Succeeded) { if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { @@ -265,10 +266,10 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) { this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); - + pollingState.updateResponse(result.response); pollingState.request = result.request; - + var statusCode = result.response.statusCode; if (statusCode === 202) { pollingState.status = LroStates.InProgress; From 39b4b190dfe0098bdb93c3075b93b651ba554d7d Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 6 Apr 2016 15:54:30 -0700 Subject: [PATCH 06/19] code revise --- .../NodeJS/ms-rest-azure/lib/azureServiceClient.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index fa2e530176f81..5d462e43b35c8 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -229,7 +229,7 @@ AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = func (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { return false; } else { - return true; + return true; } }; @@ -274,8 +274,8 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS if (statusCode === 202) { pollingState.status = LroStates.InProgress; } else if (statusCode === 200 || - statusCode === 201 || - statusCode === 204) { + (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || + (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { pollingState.status = LroStates.Succeeded; From d1ff9419ecaa9313a8bc33c20ff7b7cd03b9846e Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 6 Apr 2016 15:57:47 -0700 Subject: [PATCH 07/19] fix the naming issue in azure serviceClientTest --- .../NodeJS/ms-rest-azure/test/azureServiceClientTests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index f358540bb6aae..98c1e78c2d474 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -160,7 +160,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.statusCode = 202; resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; - it('works by polling from azure-asyncoperation header', function (done) { + it('works by polling from location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { @@ -171,7 +171,7 @@ describe('AzureServiceClient', function () { }); }); - it('works by polling from location header', function (done) { + it('works by polling from azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { From 9573dee1b9fe3d1cbf7c8dc03b7c4957048691e0 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 6 Apr 2016 16:16:25 -0700 Subject: [PATCH 08/19] code revise --- ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index 5d462e43b35c8..c81827aa1906b 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -274,8 +274,8 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS if (statusCode === 202) { pollingState.status = LroStates.InProgress; } else if (statusCode === 200 || - (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || - (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { + (statusCode === 201 && pollingState.request.method === 'PUT') || + (statusCode === 204 && pollingState.request.method === 'DELETE')) { pollingState.status = LroStates.Succeeded; From b9d642d3a779a9fe980717263ce357b1b4de2fbc Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 6 Apr 2016 17:37:27 -0700 Subject: [PATCH 09/19] add 204 poll state for post --- .../ms-rest-azure/lib/azureServiceClient.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index c81827aa1906b..7e07c3aea86a5 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -111,7 +111,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeader(pollingState, function(err) { + self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) { return callback(err); }); } else if (resultOfInitialRequest.request.method === 'PUT') { @@ -194,7 +194,7 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeader(pollingState, function(err) { + self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) { return callback(err); }); } else if (resultOfInitialRequest.request.method === 'PUT') { @@ -223,10 +223,11 @@ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOf }; AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) { - if (initialRequest.response.statusCode === 200 || - initialRequest.response.statusCode === 202 || - (initialRequest.response.statusCode === 201 && initialRequest.request.method === 'PUT') || - (initialRequest.response.statusCode === 204 && initialRequest.request.method === 'DELETE')) { + var statusCode = initialRequest.response.statusCode; + var method = initialRequest.request.method; + if (statusCode === 200 || statusCode === 202 || + (statusCode === 201 && method === 'PUT') || + (statusCode === 204 && (method === 'DELETE' || method === 'POST'))) { return false; } else { return true; @@ -263,7 +264,7 @@ AzureServiceClient.prototype._updateStateFromAzureAsyncOperationHeader = functio * Retrieve PUT operation status by polling from 'location' header. * @param {object} [pollingState] - The object to persist current operation state. */ -AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingState, callback) { +AzureServiceClient.prototype._updateStateFromLocationHeader = function (method, pollingState, callback) { this._getStatus(pollingState.locationHeaderLink, function(err, result) { if (err) return callback(err); @@ -274,8 +275,8 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS if (statusCode === 202) { pollingState.status = LroStates.InProgress; } else if (statusCode === 200 || - (statusCode === 201 && pollingState.request.method === 'PUT') || - (statusCode === 204 && pollingState.request.method === 'DELETE')) { + (statusCode === 201 && method === 'PUT') || + (statusCode === 204 && (method === 'DELETE' || method === 'POST'))) { pollingState.status = LroStates.Succeeded; @@ -284,7 +285,9 @@ AzureServiceClient.prototype._updateStateFromLocationHeader = function (pollingS message: util.format('Long running operation failed with status \'%s\'.', pollingState.status) }; pollingState.resource = result.body; - } + } else { + return callback(new Error('The response from long running operation does not have a valid status code.')); + } callback(null); }); }; From 5b4ca29a393a30f1f452436996d952e0aa868c3a Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Thu, 7 Apr 2016 14:13:09 -0700 Subject: [PATCH 10/19] change code gen in node js to merge LRO operations into one method --- .../Lro/operations/lRORetrys.js | 14 +-- .../AcceptanceTests/Lro/operations/lROSADs.js | 50 +++++------ .../AcceptanceTests/Lro/operations/lROs.js | 72 +++++++-------- .../Lro/operations/lROsCustomHeader.js | 8 +- .../AzureMethodTemplateModel.cs | 9 +- .../ms-rest-azure/lib/azureServiceClient.js | 88 +------------------ .../test/azureServiceClientTests.js | 36 ++++---- 7 files changed, 93 insertions(+), 184 deletions(-) diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js index f3cb1fecfb34b..bacca9fd614ab 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js @@ -81,7 +81,7 @@ LRORetrys.prototype.put201CreatingSucceeded200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -334,7 +334,7 @@ LRORetrys.prototype.putAsyncRelativeRetrySucceeded = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -562,7 +562,7 @@ LRORetrys.prototype.deleteProvisioning202Accepted200Succeeded = function (option initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -782,7 +782,7 @@ LRORetrys.prototype.delete202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -952,7 +952,7 @@ LRORetrys.prototype.deleteAsyncRelativeRetrySucceeded = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1130,7 +1130,7 @@ LRORetrys.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1332,7 +1332,7 @@ LRORetrys.prototype.postAsyncRelativeRetrySucceeded = function (options, callbac initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js index 33fff6078369c..850509ad638ea 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js @@ -78,7 +78,7 @@ LROSADs.prototype.putNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -326,7 +326,7 @@ LROSADs.prototype.putNonRetry201Creating400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -576,7 +576,7 @@ LROSADs.prototype.putAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -799,7 +799,7 @@ LROSADs.prototype.deleteNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -965,7 +965,7 @@ LROSADs.prototype.delete202NonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1133,7 +1133,7 @@ LROSADs.prototype.deleteAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1309,7 +1309,7 @@ LROSADs.prototype.postNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1506,7 +1506,7 @@ LROSADs.prototype.post202NonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1705,7 +1705,7 @@ LROSADs.prototype.postAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1906,7 +1906,7 @@ LROSADs.prototype.putError201NoProvisioningStatePayload = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2156,7 +2156,7 @@ LROSADs.prototype.putAsyncRelativeRetryNoStatus = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2390,7 +2390,7 @@ LROSADs.prototype.putAsyncRelativeRetryNoStatusPayload = function (options, call initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2614,7 +2614,7 @@ LROSADs.prototype.delete204Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2783,7 +2783,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryNoStatus = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2960,7 +2960,7 @@ LROSADs.prototype.post202NoLocation = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3160,7 +3160,7 @@ LROSADs.prototype.postAsyncRelativeRetryNoPayload = function (options, callback) initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3361,7 +3361,7 @@ LROSADs.prototype.put200InvalidJson = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3594,7 +3594,7 @@ LROSADs.prototype.putAsyncRelativeRetryInvalidHeader = function (options, callba initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3828,7 +3828,7 @@ LROSADs.prototype.putAsyncRelativeRetryInvalidJsonPolling = function (options, c initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4052,7 +4052,7 @@ LROSADs.prototype.delete202RetryInvalidHeader = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4220,7 +4220,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryInvalidHeader = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4389,7 +4389,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryInvalidJsonPolling = function (options initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4566,7 +4566,7 @@ LROSADs.prototype.post202RetryInvalidHeader = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4766,7 +4766,7 @@ LROSADs.prototype.postAsyncRelativeRetryInvalidHeader = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4967,7 +4967,7 @@ LROSADs.prototype.postAsyncRelativeRetryInvalidJsonPolling = function (options, initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js index b0cc6a272fd58..f403121e6dfec 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js @@ -79,7 +79,7 @@ LROs.prototype.put200Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -311,7 +311,7 @@ LROs.prototype.put200SucceededNoState = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -544,7 +544,7 @@ LROs.prototype.put202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -779,7 +779,7 @@ LROs.prototype.put201CreatingSucceeded200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1032,7 +1032,7 @@ LROs.prototype.put200UpdatingSucceeded204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1268,7 +1268,7 @@ LROs.prototype.put201CreatingFailed200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1521,7 +1521,7 @@ LROs.prototype.put200Acceptedcanceled200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1756,7 +1756,7 @@ LROs.prototype.putNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1990,7 +1990,7 @@ LROs.prototype.putAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2224,7 +2224,7 @@ LROs.prototype.putAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2458,7 +2458,7 @@ LROs.prototype.putAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2692,7 +2692,7 @@ LROs.prototype.putAsyncNoRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2926,7 +2926,7 @@ LROs.prototype.putAsyncNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3156,7 +3156,7 @@ LROs.prototype.putNonResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3382,7 +3382,7 @@ LROs.prototype.putAsyncNonResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3606,7 +3606,7 @@ LROs.prototype.putSubResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3828,7 +3828,7 @@ LROs.prototype.putAsyncSubResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4049,7 +4049,7 @@ LROs.prototype.deleteProvisioning202Accepted200Succeeded = function (options, ca initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4271,7 +4271,7 @@ LROs.prototype.deleteProvisioning202DeletingFailed200 = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4493,7 +4493,7 @@ LROs.prototype.deleteProvisioning202Deletingcanceled200 = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4711,7 +4711,7 @@ LROs.prototype.delete204Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4880,7 +4880,7 @@ LROs.prototype.delete202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5083,7 +5083,7 @@ LROs.prototype.delete202NoRetry204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5285,7 +5285,7 @@ LROs.prototype.deleteNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5455,7 +5455,7 @@ LROs.prototype.deleteAsyncNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5625,7 +5625,7 @@ LROs.prototype.deleteAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5795,7 +5795,7 @@ LROs.prototype.deleteAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5965,7 +5965,7 @@ LROs.prototype.deleteAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6135,7 +6135,7 @@ LROs.prototype.deleteAsyncRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6306,7 +6306,7 @@ LROs.prototype.post200WithPayload = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6533,7 +6533,7 @@ LROs.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6734,7 +6734,7 @@ LROs.prototype.post202NoRetry204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6967,7 +6967,7 @@ LROs.prototype.postAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7201,7 +7201,7 @@ LROs.prototype.postAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7434,7 +7434,7 @@ LROs.prototype.postAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7635,7 +7635,7 @@ LROs.prototype.postAsyncRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js index 9dc6656111ba1..3d4d296e68aaa 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js @@ -82,7 +82,7 @@ LROsCustomHeader.prototype.putAsyncRetrySucceeded = function (options, callback) initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -320,7 +320,7 @@ LROsCustomHeader.prototype.put201CreatingSucceeded200 = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -573,7 +573,7 @@ LROsCustomHeader.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -777,7 +777,7 @@ LROsCustomHeader.prototype.postAsyncRetrySucceeded = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { + client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS/TemplateModels/AzureMethodTemplateModel.cs b/AutoRest/Generators/NodeJS/Azure.NodeJS/TemplateModels/AzureMethodTemplateModel.cs index 95a519d366c9d..a6fbcc9e356e9 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS/TemplateModels/AzureMethodTemplateModel.cs +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS/TemplateModels/AzureMethodTemplateModel.cs @@ -86,14 +86,7 @@ public string LongRunningOperationMethodNameInRuntime string result = null; if (this.IsLongRunningOperation) { - if (HttpMethod == HttpMethod.Post || HttpMethod == HttpMethod.Delete) - { - result = "getPostOrDeleteOperationResult"; - } - else if (HttpMethod == HttpMethod.Put || HttpMethod == HttpMethod.Patch) - { - result = "getPutOrPatchOperationResult"; - } + result = "getLongRunningOperationResult"; } return result; } diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index 7e07c3aea86a5..e0207511c4c34 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -57,96 +57,12 @@ function AzureServiceClient(credentials, options) { util.inherits(AzureServiceClient, msRest.ServiceClient); /** - * Poll Azure long running PUT operation. - * @param {object} [resultOfInitialRequest] - Response of the initial request for the long running operation. - * @param {object} [options] - * @param {object} [options.customHeaders] headers that will be added to request - */ -AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { - var self = this; - - if(!callback && typeof options === 'function') { - callback = options; - options = null; - } - if (!callback) { - throw new Error('Missing callback'); - } - - if (!resultOfInitialRequest) { - return callback(new Error('Missing resultOfInitialRequest parameter')); - } - - if (!resultOfInitialRequest.response) { - return callback(new Error('Missing resultOfInitialRequest.response')); - } - - if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { - return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', - resultOfInitialRequest.response.statusCode, - resultOfInitialRequest.request.method))); - } - - var pollingState = null; - try { - pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); - } catch (error) { - callback(error); - } - - var resourceUrl = resultOfInitialRequest.request.url; - this._options = options; - - async.whilst( - function() { - var finished = [LroStates.Succeeded, LroStates.Failed, LroStates.Canceled].some(function(e) { - return e === pollingState.status; - }); - return !finished; - }, - function(callback) { - setTimeout(function() { - if (pollingState.azureAsyncOperationHeaderLink) { - self._updateStateFromAzureAsyncOperationHeader(pollingState, true, function(err) { - return callback(err); - }); - } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) { - return callback(err); - }); - } else if (resultOfInitialRequest.request.method === 'PUT') { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { - return callback(err); - }); - } else { - return callback(new Error('Location header is missing from long running operation.')); - } - }, pollingState.getTimeout()); - }, - //when done - function (err) { - if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { - self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { - return callback(err, pollingState.getOperationResponse()); - }); - } else { - return callback(null, pollingState.getOperationResponse()); - } - } else { - return callback(pollingState.getCloudError(err)); - } - }); -}; - - -/** - * Poll Azure long running POST or DELETE operations. + * Poll Azure long running GET, PATCH, POST or DELETE operations. * @param {object} [resultOfInitialRequest] - result of the initial request. * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request */ -AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { +AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfInitialRequest, options, callback) { var self = this; if (!callback && typeof options === 'function') { diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index 98c1e78c2d474..3a56e378e4d9c 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -94,7 +94,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.statusCode = 201; it('throw on not Lro related status code', function (done) { - client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { + client.getLongRunningOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -103,7 +103,7 @@ describe('AzureServiceClient', function () { it('works by polling from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); done(); @@ -118,7 +118,7 @@ describe('AzureServiceClient', function () { 'testCustomField': testCustomFieldValue } }; - client.getPutOrPatchOperationResult(resultOfInitialRequest, options, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, options, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); result.response.testCustomField.should.equal(testCustomFieldValue); @@ -129,7 +129,7 @@ describe('AzureServiceClient', function () { it('works by polling from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); should.exist(result.response.randomFieldFromPollLocationHeader); @@ -140,7 +140,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -149,7 +149,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -163,7 +163,7 @@ describe('AzureServiceClient', function () { it('works by polling from location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); should.exist(result.response.randomFieldFromPollLocationHeader); @@ -174,7 +174,7 @@ describe('AzureServiceClient', function () { it('works by polling from azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); done(); @@ -184,7 +184,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -193,7 +193,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -205,7 +205,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; it('throw on not Lro related status code', function (done) { - client.getPostOrDeleteOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { + client.getLongRunningOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -215,7 +215,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; resultOfInitialRequest.request.method = 'POST'; - client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollAsyncOpHeader); done(); @@ -225,7 +225,7 @@ describe('AzureServiceClient', function () { it('works by polling from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollLocationHeader); JSON.parse(result.body).name.should.equal(testResourceName); @@ -236,7 +236,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -245,7 +245,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { + client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -265,7 +265,7 @@ describe('AzureServiceClient', function () { negativeClient.addFilter(mockFilter({ statusCode: 200, body: badResponseBody }, badResponseBody)); resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - negativeClient.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + negativeClient.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.exist(err); should.exist(err.response); should.exist(err.message); @@ -280,7 +280,7 @@ describe('AzureServiceClient', function () { negativeClient.addFilter(mockFilter({ statusCode: 200, body: badResponseBody }, badResponseBody)); resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - negativeClient.getPutOrPatchOperationResult(resultOfInitialRequest, negativeClient._getStatus, function (err, result) { + negativeClient.getLongRunningOperationResult(resultOfInitialRequest, negativeClient._getStatus, function (err, result) { should.exist(err); should.exist(err.response); should.exist(err.message); @@ -295,7 +295,7 @@ describe('AzureServiceClient', function () { negativeClient.addFilter(mockFilter({ statusCode: 203, body: badResponseBody }, badResponseBody)); resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - negativeClient.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { + negativeClient.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { should.exist(err); should.exist(err.response); should.exist(err.message); From 08bd3364fd6760a056d439fcf590baaa27373578 Mon Sep 17 00:00:00 2001 From: tbombach Date: Fri, 22 Apr 2016 13:31:24 -0700 Subject: [PATCH 11/19] Adding documentation for instructions on writing tests in AutoRest --- Documentation/README.md | 3 +- Documentation/writing-tests.md | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Documentation/writing-tests.md diff --git a/Documentation/README.md b/Documentation/README.md index 890f11b09d4bf..6b77f525787bb 100644 --- a/Documentation/README.md +++ b/Documentation/README.md @@ -18,6 +18,7 @@ - Code Generators - Modelers 5. [Building AutoRest](building-code.md) -6. Contributing to the code +6. [Writing Tests](writing-tests.md) +7. Contributing to the code [Swagger2.0]:https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md diff --git a/Documentation/writing-tests.md b/Documentation/writing-tests.md new file mode 100644 index 0000000000000..7712f32f74753 --- /dev/null +++ b/Documentation/writing-tests.md @@ -0,0 +1,52 @@ +# Writing Tests + +## Build Prerequisites +To test AutoRest in each language, you must set up your machine according to the requirements on the [Building Code](building-code.md) page. + +## Architecture +Tests are split into unit and acceptance tests. Unit tests validate the AutoRest application itself and how it interprets Swagger documents. Acceptance tests validate the generated code in each language and are written in those languages. + +### Unit tests +Unit tests need to be updated when core parts of AutoRest change, not when the language-specific generator code changes. Unit tests are located in: +
+
\AutoRest\AutoRest.Core.Tests
+
These need to be updated when the command-line AutoRest application itself changes
+
\AutoRest\Modelers\Swagger.Tests
+ \AutoRest\Modelers\Swagger.Composite.Tests
+
These need to be updated when there are changes to how AutoRest processes Swagger files
+
+ +### Acceptance tests (and test server) +Acceptance tests are run against a Node.js test server (which uses [Express framework](http://expressjs.com/)). The code for the test server is checked in to the [\\AutoRest\\TestServer](../AutoRest/TestServer/) folder in the repository. + +There are two main components to the test server: the Swagger definitions that describe the server and the code that handles requests to the server and responds with the appropriate status code, payload, etc. if the request is constructed correctly. + +## How to add acceptance tests for scenarios +1. Add your scenarios to the Swagger files that describe the test server (located in the [\\AutoRest\\TestServer\\swagger](../AutoRest/TestServer/swagger/) folder). +2. Update the test server + - Update the routes to generate appropriate responses for your scenarios at paths specified in the Swagger files in step 1. This code is located in the [\\AutoRest\\TestServer\\server\\routes\\*.js](../AutoRest/TestServer/server/routes) files. + - For each scenario, the `coverage` dictionary needs to be incremented for the name of your scenario. This name will be used in the test report coverage. + - Update the `coverage` dictionary in [\\AutoRest\\TestServer\\server\\app.js](../AutoRest/TestServer/server/app.js) to include the names of your new scenarios. This lets the final test report include your scenarios when reporting on the coverage for each language. +3. Regenerate the expected code using `gulp regenerate` (this will use the Swagger files to generate client libraries for the test server). +4. In each language, write tests that cover your scenarios (for example, in C#, you must update [\\AutoRest\\Generators\\CSharp\CSharp.Tests\\AcceptanceTests.cs](../AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs) or [\\AutoRest\\Generators\\CSharp\\Azure.CSharp.Tests\\AcceptanceTests.cs](../AutoRest/Generators/CSharp/Azure.CSharp.Tests/AcceptanceTests.cs)). You will make calls to the test server using the generated code from step 3. +5. [Run the tests](#running-tests) + +## Running Tests +When you run tests, the test server is automatically started and the code that is generated for the test server Swagger files will correctly target this new instance. + +### Command Line +Tests can be run with `gulp test`. You can run tests for each language individually with `gulp:test:[language name]`. Use `gulp -T` to find the correct names. + +### Visual Studio +In Visual Studio, you can run tests for all languages using Task Runner Explorer. C# tests can also be run and debugged in Test Explorer. + +## Debugging the test server +When updating the test server code to return the appropriate responses for your scenarios, it can be useful to debug the code to make sure the test code calls the paths that you are expecting. + +### Visual Studio +1. Install [Node.js Tools for Visual Studio](https://www.visualstudio.com/en-us/features/node-js-vs.aspx) solution. +2. Open the [\\AutoRest\\TestServer\\server\\SwaggerBATServer.sln](../AutoRest/TestServer/server/SwaggerBATServer.sln). +3. Run the [SwaggerBATServer project](../AutoRest/TestServer/server/SwaggerBATServer.njsproj). +4. Make sure that the port that the test server is using matches the port that is used by the tests when you run them. + - For Node.js, this is straightforward because the server and tests both use port 3000 by default. + - For C#, the infrastructure is set up to use a random port to avoid conflicts. You must change the logic in [\\AutoRest\\Generators\\CSharp\\CSharp.Tests\\Utilities\\ServiceController.cs](../AutoRest/Generators/CSharp/CSharp.Tests/Utilities/ServiceController.cs).`GetRandomPort()` to use the same port as the test server. \ No newline at end of file From 2f7d3e4680f2688e3fa237b72b1e50db0e53593a Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Tue, 26 Apr 2016 17:42:57 -0700 Subject: [PATCH 12/19] Deprecate two old functions --- .../Lro/operations/lRORetrys.js | 16 ++-- .../AcceptanceTests/Lro/operations/lROSADs.js | 52 ++++++------- .../AcceptanceTests/Lro/operations/lROs.js | 74 +++++++++---------- .../Lro/operations/lROsCustomHeader.js | 10 +-- .../ms-rest-azure/lib/azureServiceClient.js | 46 ++++++++++-- .../test/azureServiceClientTests.js | 22 +++--- 6 files changed, 126 insertions(+), 94 deletions(-) diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js index bacca9fd614ab..91416004b938f 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lRORetrys.js @@ -81,7 +81,7 @@ LRORetrys.prototype.put201CreatingSucceeded200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -334,7 +334,7 @@ LRORetrys.prototype.putAsyncRelativeRetrySucceeded = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -562,7 +562,7 @@ LRORetrys.prototype.deleteProvisioning202Accepted200Succeeded = function (option initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -782,7 +782,7 @@ LRORetrys.prototype.delete202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -952,7 +952,7 @@ LRORetrys.prototype.deleteAsyncRelativeRetrySucceeded = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1130,7 +1130,7 @@ LRORetrys.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1332,7 +1332,7 @@ LRORetrys.prototype.postAsyncRelativeRetrySucceeded = function (options, callbac initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1485,4 +1485,4 @@ LRORetrys.prototype.beginPostAsyncRelativeRetrySucceeded = function (options, ca }; -module.exports = LRORetrys; +module.exports = LRORetrys; \ No newline at end of file diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js index 850509ad638ea..44a7ef1d9e6fc 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROSADs.js @@ -78,7 +78,7 @@ LROSADs.prototype.putNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -326,7 +326,7 @@ LROSADs.prototype.putNonRetry201Creating400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -576,7 +576,7 @@ LROSADs.prototype.putAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -799,7 +799,7 @@ LROSADs.prototype.deleteNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -965,7 +965,7 @@ LROSADs.prototype.delete202NonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1133,7 +1133,7 @@ LROSADs.prototype.deleteAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1309,7 +1309,7 @@ LROSADs.prototype.postNonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1506,7 +1506,7 @@ LROSADs.prototype.post202NonRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1705,7 +1705,7 @@ LROSADs.prototype.postAsyncRelativeRetry400 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1906,7 +1906,7 @@ LROSADs.prototype.putError201NoProvisioningStatePayload = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2156,7 +2156,7 @@ LROSADs.prototype.putAsyncRelativeRetryNoStatus = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2390,7 +2390,7 @@ LROSADs.prototype.putAsyncRelativeRetryNoStatusPayload = function (options, call initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2614,7 +2614,7 @@ LROSADs.prototype.delete204Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2783,7 +2783,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryNoStatus = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2960,7 +2960,7 @@ LROSADs.prototype.post202NoLocation = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3160,7 +3160,7 @@ LROSADs.prototype.postAsyncRelativeRetryNoPayload = function (options, callback) initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3361,7 +3361,7 @@ LROSADs.prototype.put200InvalidJson = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3594,7 +3594,7 @@ LROSADs.prototype.putAsyncRelativeRetryInvalidHeader = function (options, callba initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3828,7 +3828,7 @@ LROSADs.prototype.putAsyncRelativeRetryInvalidJsonPolling = function (options, c initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4052,7 +4052,7 @@ LROSADs.prototype.delete202RetryInvalidHeader = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4220,7 +4220,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryInvalidHeader = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4389,7 +4389,7 @@ LROSADs.prototype.deleteAsyncRelativeRetryInvalidJsonPolling = function (options initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4566,7 +4566,7 @@ LROSADs.prototype.post202RetryInvalidHeader = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4766,7 +4766,7 @@ LROSADs.prototype.postAsyncRelativeRetryInvalidHeader = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4967,7 +4967,7 @@ LROSADs.prototype.postAsyncRelativeRetryInvalidJsonPolling = function (options, initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5119,4 +5119,4 @@ LROSADs.prototype.beginPostAsyncRelativeRetryInvalidJsonPolling = function (opti }; -module.exports = LROSADs; +module.exports = LROSADs; \ No newline at end of file diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js index f403121e6dfec..7655fc4191aa2 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROs.js @@ -79,7 +79,7 @@ LROs.prototype.put200Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -311,7 +311,7 @@ LROs.prototype.put200SucceededNoState = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -544,7 +544,7 @@ LROs.prototype.put202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -779,7 +779,7 @@ LROs.prototype.put201CreatingSucceeded200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1032,7 +1032,7 @@ LROs.prototype.put200UpdatingSucceeded204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1268,7 +1268,7 @@ LROs.prototype.put201CreatingFailed200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1521,7 +1521,7 @@ LROs.prototype.put200Acceptedcanceled200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1756,7 +1756,7 @@ LROs.prototype.putNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -1990,7 +1990,7 @@ LROs.prototype.putAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2224,7 +2224,7 @@ LROs.prototype.putAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2458,7 +2458,7 @@ LROs.prototype.putAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2692,7 +2692,7 @@ LROs.prototype.putAsyncNoRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -2926,7 +2926,7 @@ LROs.prototype.putAsyncNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3156,7 +3156,7 @@ LROs.prototype.putNonResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3382,7 +3382,7 @@ LROs.prototype.putAsyncNonResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3606,7 +3606,7 @@ LROs.prototype.putSubResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -3828,7 +3828,7 @@ LROs.prototype.putAsyncSubResource = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4049,7 +4049,7 @@ LROs.prototype.deleteProvisioning202Accepted200Succeeded = function (options, ca initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4271,7 +4271,7 @@ LROs.prototype.deleteProvisioning202DeletingFailed200 = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4493,7 +4493,7 @@ LROs.prototype.deleteProvisioning202Deletingcanceled200 = function (options, cal initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4711,7 +4711,7 @@ LROs.prototype.delete204Succeeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -4880,7 +4880,7 @@ LROs.prototype.delete202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5083,7 +5083,7 @@ LROs.prototype.delete202NoRetry204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5285,7 +5285,7 @@ LROs.prototype.deleteNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5455,7 +5455,7 @@ LROs.prototype.deleteAsyncNoHeaderInRetry = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5625,7 +5625,7 @@ LROs.prototype.deleteAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5795,7 +5795,7 @@ LROs.prototype.deleteAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -5965,7 +5965,7 @@ LROs.prototype.deleteAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6135,7 +6135,7 @@ LROs.prototype.deleteAsyncRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6306,7 +6306,7 @@ LROs.prototype.post200WithPayload = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6533,7 +6533,7 @@ LROs.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6734,7 +6734,7 @@ LROs.prototype.post202NoRetry204 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -6967,7 +6967,7 @@ LROs.prototype.postAsyncRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7201,7 +7201,7 @@ LROs.prototype.postAsyncNoRetrySucceeded = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7434,7 +7434,7 @@ LROs.prototype.postAsyncRetryFailed = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7635,7 +7635,7 @@ LROs.prototype.postAsyncRetrycanceled = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -7787,4 +7787,4 @@ LROs.prototype.beginPostAsyncRetrycanceled = function (options, callback) { }; -module.exports = LROs; +module.exports = LROs; \ No newline at end of file diff --git a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js index 3d4d296e68aaa..0c25e2df3bb0c 100644 --- a/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js +++ b/AutoRest/Generators/NodeJS/Azure.NodeJS.Tests/Expected/AcceptanceTests/Lro/operations/lROsCustomHeader.js @@ -82,7 +82,7 @@ LROsCustomHeader.prototype.putAsyncRetrySucceeded = function (options, callback) initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -320,7 +320,7 @@ LROsCustomHeader.prototype.put201CreatingSucceeded200 = function (options, callb initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -573,7 +573,7 @@ LROsCustomHeader.prototype.post202Retry200 = function (options, callback) { initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -777,7 +777,7 @@ LROsCustomHeader.prototype.postAsyncRetrySucceeded = function (options, callback initialResult.request = httpRequest; initialResult.response = response; initialResult.body = response.body; - client.getLongRunningOperationResult(initialResult, options, function (err, pollingResult) { + client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) { if (err) return callback(err); // Create Result @@ -931,4 +931,4 @@ LROsCustomHeader.prototype.beginPostAsyncRetrySucceeded = function (options, cal }; -module.exports = LROsCustomHeader; +module.exports = LROsCustomHeader; \ No newline at end of file diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index e0207511c4c34..fcc09299d1c03 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -57,7 +57,27 @@ function AzureServiceClient(credentials, options) { util.inherits(AzureServiceClient, msRest.ServiceClient); /** - * Poll Azure long running GET, PATCH, POST or DELETE operations. + * Poll Azure long running PUT or PATCH operation. (Deprecated, new version of the code-gen will generate code to call getLongRunningOperationResult) + * @param {object} [resultOfInitialRequest] - Response of the initial request for the long running operation. + * @param {object} [options] + * @param {object} [options.customHeaders] headers that will be added to request + */ +AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { + return this.getLongRunningOperationResult(resultOfInitialRequest, options, callback); +} + +/** + * Poll Azure long running POST or DELETE operations. (Deprecated, new version of the code-gen will generate code to call getLongRunningOperationResult) + * @param {object} [resultOfInitialRequest] - result of the initial request. + * @param {object} [options] + * @param {object} [options.customHeaders] headers that will be added to request + */ +AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { + return this.getLongRunningOperationResult(resultOfInitialRequest, options, callback); +} + +/** + * Poll Azure long running PUT, PATCH, POST or DELETE operations. * @param {object} [resultOfInitialRequest] - result of the initial request. * @param {object} [options] * @param {object} [options.customHeaders] headers that will be added to request @@ -80,14 +100,25 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI if (!resultOfInitialRequest.response) { return callback(new Error('Missing resultOfInitialRequest.response')); } + + if (!resultOfInitialRequest.request) { + return callback(new Error('Missing resultOfInitialRequest.request')); + } + + if (!resultOfInitialRequest.request.method) { + return callback(new Error('Missing resultOfInitialRequest.request.method')); + } - if (this._checkInitialRequestResponseStatusCodeFailed(resultOfInitialRequest)) { + var initialRequestMethod = resultOfInitialRequest.request.method; + + if (this._checkResponseStatusCodeFailed(resultOfInitialRequest)) { return callback(new Error(util.format('Unexpected polling status code from long running operation \'%s\' for method \'%s\'', resultOfInitialRequest.response.statusCode, - resultOfInitialRequest.request.method))); + initialRequestMethod))); } var pollingState = null; + try { pollingState = new PollingState(resultOfInitialRequest, this.longRunningOperationRetryTimeout); } catch (error) { @@ -110,10 +141,10 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI return callback(err); }); } else if (pollingState.locationHeaderLink) { - self._updateStateFromLocationHeader(resultOfInitialRequest.request.method, pollingState, function(err) { + self._updateStateFromLocationHeader(initialRequestMethod, pollingState, function(err) { return callback(err); }); - } else if (resultOfInitialRequest.request.method === 'PUT') { + } else if (initialRequestMethod === 'PUT') { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err); }); @@ -125,7 +156,8 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI //when done function (err) { if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && resultOfInitialRequest.request.method !== 'DELETE' && resultOfInitialRequest.request.method !== 'POST') { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) + && (initialRequestMethod === 'PUT' || initialRequestMethod === 'PATCH')) { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); @@ -138,7 +170,7 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI }); }; -AzureServiceClient.prototype._checkInitialRequestResponseStatusCodeFailed = function (initialRequest) { +AzureServiceClient.prototype._checkResponseStatusCodeFailed = function (initialRequest) { var statusCode = initialRequest.response.statusCode; var method = initialRequest.request.method; if (statusCode === 200 || statusCode === 202 || diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index 3a56e378e4d9c..954032749dcfd 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -94,7 +94,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.statusCode = 201; it('throw on not Lro related status code', function (done) { - client.getLongRunningOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { + client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -103,7 +103,7 @@ describe('AzureServiceClient', function () { it('works by polling from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); done(); @@ -118,7 +118,7 @@ describe('AzureServiceClient', function () { 'testCustomField': testCustomFieldValue } }; - client.getLongRunningOperationResult(resultOfInitialRequest, options, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, options, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); result.response.testCustomField.should.equal(testCustomFieldValue); @@ -129,7 +129,7 @@ describe('AzureServiceClient', function () { it('works by polling from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); JSON.parse(result.body).name.should.equal(testResourceName); should.exist(result.response.randomFieldFromPollLocationHeader); @@ -140,7 +140,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -149,7 +149,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPutOrPatchOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -205,7 +205,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; it('throw on not Lro related status code', function (done) { - client.getLongRunningOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { + client.getPostOrDeleteOperationResult({ response: { statusCode: 201 }, request: {url: url_resource, method: 'POST'}}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -215,7 +215,7 @@ describe('AzureServiceClient', function () { resultOfInitialRequest.response.headers['azure-asyncoperation'] = urlFromAzureAsyncOPHeader_Return200; resultOfInitialRequest.response.headers['location'] = ''; resultOfInitialRequest.request.method = 'POST'; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollAsyncOpHeader); done(); @@ -225,7 +225,7 @@ describe('AzureServiceClient', function () { it('works by polling from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = urlFromLocationHeader_Return200; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { should.not.exist(err); should.exist(result.response.randomFieldFromPollLocationHeader); JSON.parse(result.body).name.should.equal(testResourceName); @@ -236,7 +236,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the azure-asyncoperation header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = url_ReturnError; resultOfInitialRequest.response.headers['location'] = ''; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); @@ -245,7 +245,7 @@ describe('AzureServiceClient', function () { it('returns error if failed to poll from the location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; resultOfInitialRequest.response.headers['location'] = url_ReturnError; - client.getLongRunningOperationResult(resultOfInitialRequest, function (err, result) { + client.getPostOrDeleteOperationResult(resultOfInitialRequest, function (err, result) { err.message.should.containEql(testError); done(); }); From 1a6bf4e79d9daa64ecf3fc4d6e9492ab7cc57b44 Mon Sep 17 00:00:00 2001 From: Qinyuan Wan Date: Wed, 27 Apr 2016 10:36:56 -0700 Subject: [PATCH 13/19] code revise --- .../NodeJS/ms-rest-azure/lib/azureServiceClient.js | 8 ++++---- .../NodeJS/ms-rest-azure/test/azureServiceClientTests.js | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js index fcc09299d1c03..ca4413b85a00b 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/lib/azureServiceClient.js @@ -64,7 +64,7 @@ util.inherits(AzureServiceClient, msRest.ServiceClient); */ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfInitialRequest, options, callback) { return this.getLongRunningOperationResult(resultOfInitialRequest, options, callback); -} +}; /** * Poll Azure long running POST or DELETE operations. (Deprecated, new version of the code-gen will generate code to call getLongRunningOperationResult) @@ -74,7 +74,7 @@ AzureServiceClient.prototype.getPutOrPatchOperationResult = function (resultOfIn */ AzureServiceClient.prototype.getPostOrDeleteOperationResult = function (resultOfInitialRequest, options, callback) { return this.getLongRunningOperationResult(resultOfInitialRequest, options, callback); -} +}; /** * Poll Azure long running PUT, PATCH, POST or DELETE operations. @@ -156,8 +156,8 @@ AzureServiceClient.prototype.getLongRunningOperationResult = function (resultOfI //when done function (err) { if (pollingState.status === LroStates.Succeeded) { - if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) - && (initialRequestMethod === 'PUT' || initialRequestMethod === 'PATCH')) { + if ((pollingState.azureAsyncOperationHeaderLink || !pollingState.resource) && + (initialRequestMethod === 'PUT' || initialRequestMethod === 'PATCH')) { self._updateStateFromGetResourceOperation(resourceUrl, pollingState, function(err) { return callback(err, pollingState.getOperationResponse()); }); diff --git a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js index 954032749dcfd..8e11e689690b7 100644 --- a/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js +++ b/ClientRuntimes/NodeJS/ms-rest-azure/test/azureServiceClientTests.js @@ -92,9 +92,10 @@ describe('AzureServiceClient', function () { describe('Put', function () { resultOfInitialRequest.response.statusCode = 201; + resultOfInitialRequest.request.method = 'PUT'; it('throw on not Lro related status code', function (done) { - client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo" }}, function (err, result) { + client.getPutOrPatchOperationResult({ response: {statusCode: 10000}, request: { url:"http://foo", method:'PUT' }}, function (err, result) { err.message.should.containEql('Unexpected polling status code from long running operation'); done(); }); @@ -159,6 +160,7 @@ describe('AzureServiceClient', function () { describe('Patch', function () { resultOfInitialRequest.response.statusCode = 202; resultOfInitialRequest.body.properties.provisioningState = LroStates.Succeeded; + resultOfInitialRequest.request.method = 'PATCH'; it('works by polling from location header', function (done) { resultOfInitialRequest.response.headers['azure-asyncoperation'] = ''; From 37a536990d655307b3deb44d4f3de78eee4935de Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Fri, 29 Apr 2016 16:51:42 -0700 Subject: [PATCH 14/19] UnixTime in node.js (#987) * Enhancement to x-ms-parameterized-host extension * positionInOperation defaults to first * fixed setting default value for a complex object containing constant properties. * result of executing gulp regenerate:expected * Fixed fxcop warnings * remove null check validation for unixtime as they are treated as long in java * unixTime in node.js * modification * UnixTime tests * FxCop warnings --- .../AcceptanceTests/acceptanceTests.ts | 30 +++++++++++++++++++ .../BodyInteger/operations/index.d.ts | 18 +++++------ .../BodyInteger/operations/intModel.js | 23 +++++++------- .../operations/index.d.ts | 18 +++++------ .../operations/intModel.js | 23 +++++++------- .../AcceptanceTests/Url/operations/index.d.ts | 6 ++-- .../AcceptanceTests/Url/operations/paths.js | 11 +++---- .../NodeJS/NodeJS/ClientModelExtensions.cs | 26 +++++++++++----- .../NodeJS/NodeJS/GlobalSuppressions.cs | 1 + .../NodeJS/NodeJS/NodeJsCodeNamer.cs | 8 ++--- ClientRuntimes/NodeJS/ms-rest/README.md | 3 +- .../NodeJS/ms-rest/lib/serialization.js | 30 +++++++++++++++++-- .../NodeJS/ms-rest/test/serializationTests.js | 6 ++++ 13 files changed, 141 insertions(+), 62 deletions(-) diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/AcceptanceTests/acceptanceTests.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/AcceptanceTests/acceptanceTests.ts index 0a81b3420068b..db5042f716ed3 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/AcceptanceTests/acceptanceTests.ts +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/AcceptanceTests/acceptanceTests.ts @@ -199,6 +199,29 @@ describe('nodejs', function () { }); }); }); + + it('should put and get UnixTime date correctly', function (done) { + var d = new Date('2016-04-13T00:00:00.000Z'); + testClient.intModel.putUnixTimeDate(d, function (error, result) { + should.not.exist(error); + testClient.intModel.getUnixTime(function (error, result) { + should.not.exist(error); + assert.deepEqual(result, d); + done(); + }); + }); + }); + + it('should throw an error for invalid UnixTime date anf get null value for UnixTime', function (done) { + testClient.intModel.getInvalidUnixTime(function (error, result) { + should.exist(error); + testClient.intModel.getNullUnixTime(function (error, result) { + should.not.exist(error); + should.not.exist(result); + done(); + }); + }); + }); }); describe('CompositeBoolInt Client', function () { @@ -1891,6 +1914,13 @@ describe('nodejs', function () { }); }); + it('should work when path has a paramaeter in UnixTime format', function (done) { + testClient.paths.unixTimeUrl(new Date('2016-04-13T00:00:00.000Z'), function (error, result) { + should.not.exist(error); + done(); + }); + }); + it('should work when path has datetime', function (done) { testClient.paths.dateTimeValid(new Date('2012-01-01T01:01:01Z'), function (error, result) { should.not.exist(error); diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/BodyInteger/operations/index.d.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/BodyInteger/operations/index.d.ts index 1b00b43d81429..6fddcb9d06757 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/BodyInteger/operations/index.d.ts +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/BodyInteger/operations/index.d.ts @@ -179,13 +179,13 @@ export interface IntModel { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - getUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - getUnixTime(callback: ServiceCallback): void; + getUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + getUnixTime(callback: ServiceCallback): void; /** * Put datetime encoded as Unix time * - * @param {number} intBody + * @param {date} intBody * * @param {object} [options] Optional Parameters. * @@ -195,8 +195,8 @@ export interface IntModel { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - putUnixTimeDate(intBody: number, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - putUnixTimeDate(intBody: number, callback: ServiceCallback): void; + putUnixTimeDate(intBody: Date, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + putUnixTimeDate(intBody: Date, callback: ServiceCallback): void; /** * Get invalid Unix time value @@ -209,8 +209,8 @@ export interface IntModel { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - getInvalidUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - getInvalidUnixTime(callback: ServiceCallback): void; + getInvalidUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + getInvalidUnixTime(callback: ServiceCallback): void; /** * Get null Unix time value @@ -223,6 +223,6 @@ export interface IntModel { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - getNullUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - getNullUnixTime(callback: ServiceCallback): void; + getNullUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + getNullUnixTime(callback: ServiceCallback): void; } diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/BodyInteger/operations/intModel.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/BodyInteger/operations/intModel.js index b1ed3fbf470cf..290a93e9b35ef 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/BodyInteger/operations/intModel.js +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/BodyInteger/operations/intModel.js @@ -1210,7 +1210,7 @@ IntModel.prototype.putMin64 = function (intBody, options, callback) { * * {Error} err - The Error object if an error occurred, null otherwise. * - * {number} [result] - The deserialized result object. + * {date} [result] - The deserialized result object. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -1293,7 +1293,7 @@ IntModel.prototype.getUnixTime = function (options, callback) { required: false, serializedName: 'parsedResponse', type: { - name: 'Number' + name: 'UnixTime' } }; result = client.deserialize(resultMapper, parsedResponse, 'result'); @@ -1313,7 +1313,7 @@ IntModel.prototype.getUnixTime = function (options, callback) { /** * Put datetime encoded as Unix time * - * @param {number} intBody + * @param {date} intBody * * @param {object} [options] Optional Parameters. * @@ -1343,9 +1343,10 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) { } // Validate try { - if (intBody === null || intBody === undefined || typeof intBody !== 'number') { - throw new Error('intBody cannot be null or undefined and it must be of type number.'); - } + if(!intBody || !(intBody instanceof Date || + (typeof intBody.valueOf() === 'string' && !isNaN(Date.parse(intBody))))) { + throw new Error('intBody cannot be null or undefined and it must be of type date.'); + } } catch (error) { return callback(error); } @@ -1380,7 +1381,7 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) { required: true, serializedName: 'intBody', type: { - name: 'Number' + name: 'UnixTime' } }; requestModel = client.serialize(requestModelMapper, intBody, 'intBody'); @@ -1445,7 +1446,7 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) { * * {Error} err - The Error object if an error occurred, null otherwise. * - * {number} [result] - The deserialized result object. + * {date} [result] - The deserialized result object. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -1528,7 +1529,7 @@ IntModel.prototype.getInvalidUnixTime = function (options, callback) { required: false, serializedName: 'parsedResponse', type: { - name: 'Number' + name: 'UnixTime' } }; result = client.deserialize(resultMapper, parsedResponse, 'result'); @@ -1559,7 +1560,7 @@ IntModel.prototype.getInvalidUnixTime = function (options, callback) { * * {Error} err - The Error object if an error occurred, null otherwise. * - * {number} [result] - The deserialized result object. + * {date} [result] - The deserialized result object. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -1642,7 +1643,7 @@ IntModel.prototype.getNullUnixTime = function (options, callback) { required: false, serializedName: 'parsedResponse', type: { - name: 'Number' + name: 'UnixTime' } }; result = client.deserialize(resultMapper, parsedResponse, 'result'); diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/operations/index.d.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/operations/index.d.ts index ac60442293ccf..507488a58f3f6 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/operations/index.d.ts +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/operations/index.d.ts @@ -276,13 +276,13 @@ export interface IntModel { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - getUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - getUnixTime(callback: ServiceCallback): void; + getUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + getUnixTime(callback: ServiceCallback): void; /** * Put datetime encoded as Unix time * - * @param {number} intBody + * @param {date} intBody * * @param {object} [options] Optional Parameters. * @@ -292,8 +292,8 @@ export interface IntModel { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - putUnixTimeDate(intBody: number, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - putUnixTimeDate(intBody: number, callback: ServiceCallback): void; + putUnixTimeDate(intBody: Date, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + putUnixTimeDate(intBody: Date, callback: ServiceCallback): void; /** * Get invalid Unix time value @@ -306,8 +306,8 @@ export interface IntModel { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - getInvalidUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - getInvalidUnixTime(callback: ServiceCallback): void; + getInvalidUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + getInvalidUnixTime(callback: ServiceCallback): void; /** * Get null Unix time value @@ -320,6 +320,6 @@ export interface IntModel { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - getNullUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - getNullUnixTime(callback: ServiceCallback): void; + getNullUnixTime(options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + getNullUnixTime(callback: ServiceCallback): void; } diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/operations/intModel.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/operations/intModel.js index 42f1d72ab3f7f..d00f8cb625a0c 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/operations/intModel.js +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/CompositeBoolIntClient/operations/intModel.js @@ -1210,7 +1210,7 @@ IntModel.prototype.putMin64 = function (intBody, options, callback) { * * {Error} err - The Error object if an error occurred, null otherwise. * - * {number} [result] - The deserialized result object. + * {date} [result] - The deserialized result object. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -1293,7 +1293,7 @@ IntModel.prototype.getUnixTime = function (options, callback) { required: false, serializedName: 'parsedResponse', type: { - name: 'Number' + name: 'UnixTime' } }; result = client.deserialize(resultMapper, parsedResponse, 'result'); @@ -1313,7 +1313,7 @@ IntModel.prototype.getUnixTime = function (options, callback) { /** * Put datetime encoded as Unix time * - * @param {number} intBody + * @param {date} intBody * * @param {object} [options] Optional Parameters. * @@ -1343,9 +1343,10 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) { } // Validate try { - if (intBody === null || intBody === undefined || typeof intBody !== 'number') { - throw new Error('intBody cannot be null or undefined and it must be of type number.'); - } + if(!intBody || !(intBody instanceof Date || + (typeof intBody.valueOf() === 'string' && !isNaN(Date.parse(intBody))))) { + throw new Error('intBody cannot be null or undefined and it must be of type date.'); + } } catch (error) { return callback(error); } @@ -1380,7 +1381,7 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) { required: true, serializedName: 'intBody', type: { - name: 'Number' + name: 'UnixTime' } }; requestModel = client.serialize(requestModelMapper, intBody, 'intBody'); @@ -1445,7 +1446,7 @@ IntModel.prototype.putUnixTimeDate = function (intBody, options, callback) { * * {Error} err - The Error object if an error occurred, null otherwise. * - * {number} [result] - The deserialized result object. + * {date} [result] - The deserialized result object. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -1528,7 +1529,7 @@ IntModel.prototype.getInvalidUnixTime = function (options, callback) { required: false, serializedName: 'parsedResponse', type: { - name: 'Number' + name: 'UnixTime' } }; result = client.deserialize(resultMapper, parsedResponse, 'result'); @@ -1559,7 +1560,7 @@ IntModel.prototype.getInvalidUnixTime = function (options, callback) { * * {Error} err - The Error object if an error occurred, null otherwise. * - * {number} [result] - The deserialized result object. + * {date} [result] - The deserialized result object. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -1642,7 +1643,7 @@ IntModel.prototype.getNullUnixTime = function (options, callback) { required: false, serializedName: 'parsedResponse', type: { - name: 'Number' + name: 'UnixTime' } }; result = client.deserialize(resultMapper, parsedResponse, 'result'); diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/Url/operations/index.d.ts b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/Url/operations/index.d.ts index 3f5e24643883c..36fd5ba34f312 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/Url/operations/index.d.ts +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/Url/operations/index.d.ts @@ -398,7 +398,7 @@ export interface Paths { /** * Get the date 2016-04-13 encoded value as '1460505600' (Unix time) * - * @param {number} unixTimeUrlPath Unix time encoded value + * @param {date} unixTimeUrlPath Unix time encoded value * * @param {object} [options] Optional Parameters. * @@ -408,8 +408,8 @@ export interface Paths { * @param {ServiceCallback} [callback] callback function; see ServiceCallback * doc in ms-rest index.d.ts for details */ - unixTimeUrl(unixTimeUrlPath: number, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - unixTimeUrl(unixTimeUrlPath: number, callback: ServiceCallback): void; + unixTimeUrl(unixTimeUrlPath: Date, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + unixTimeUrl(unixTimeUrlPath: Date, callback: ServiceCallback): void; } /** diff --git a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/Url/operations/paths.js b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/Url/operations/paths.js index 4039b0ce9664a..2b5ff16d6bf66 100644 --- a/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/Url/operations/paths.js +++ b/AutoRest/Generators/NodeJS/NodeJS.Tests/Expected/AcceptanceTests/Url/operations/paths.js @@ -2461,7 +2461,7 @@ Paths.prototype.arrayCsvInPath = function (arrayPath, options, callback) { /** * Get the date 2016-04-13 encoded value as '1460505600' (Unix time) * - * @param {number} unixTimeUrlPath Unix time encoded value + * @param {date} unixTimeUrlPath Unix time encoded value * * @param {object} [options] Optional Parameters. * @@ -2491,9 +2491,10 @@ Paths.prototype.unixTimeUrl = function (unixTimeUrlPath, options, callback) { } // Validate try { - if (unixTimeUrlPath === null || unixTimeUrlPath === undefined || typeof unixTimeUrlPath !== 'number') { - throw new Error('unixTimeUrlPath cannot be null or undefined and it must be of type number.'); - } + if(!unixTimeUrlPath || !(unixTimeUrlPath instanceof Date || + (typeof unixTimeUrlPath.valueOf() === 'string' && !isNaN(Date.parse(unixTimeUrlPath))))) { + throw new Error('unixTimeUrlPath cannot be null or undefined and it must be of type date.'); + } } catch (error) { return callback(error); } @@ -2501,7 +2502,7 @@ Paths.prototype.unixTimeUrl = function (unixTimeUrlPath, options, callback) { // Construct URL var requestUrl = this.client.baseUri + '//paths/int/1460505600/{unixTimeUrlPath}'; - requestUrl = requestUrl.replace('{unixTimeUrlPath}', encodeURIComponent(unixTimeUrlPath.toString())); + requestUrl = requestUrl.replace('{unixTimeUrlPath}', encodeURIComponent(client.serialize({required: true, serializedName: 'unixTimeUrlPath', type: {name: 'UnixTime'}}, unixTimeUrlPath, 'unixTimeUrlPath'))); // trim all duplicate forward slashes in the url var regex = /([^:]\/)\/+/gi; requestUrl = requestUrl.replace(regex, '$1'); diff --git a/AutoRest/Generators/NodeJS/NodeJS/ClientModelExtensions.cs b/AutoRest/Generators/NodeJS/NodeJS/ClientModelExtensions.cs index 8f36adeec8742..ba3a24c17bf8f 100644 --- a/AutoRest/Generators/NodeJS/NodeJS/ClientModelExtensions.cs +++ b/AutoRest/Generators/NodeJS/NodeJS/ClientModelExtensions.cs @@ -131,6 +131,12 @@ public static string ToString(this IType type, string reference) return string.Format(CultureInfo.InvariantCulture, "client.serialize({{required: true, serializedName: '{0}', type: {{name: 'Base64Url'}}}}, {0}, '{0}')", reference); } + + if (known.Type == KnownPrimaryType.UnixTime) + { + return string.Format(CultureInfo.InvariantCulture, + "client.serialize({{required: true, serializedName: '{0}', type: {{name: 'UnixTime'}}}}, {0}, '{0}')", reference); + } } return string.Format(CultureInfo.InvariantCulture, "{0}.toString()", reference); @@ -195,8 +201,7 @@ private static string ValidatePrimaryType(this PrimaryType primary, IScopeProvid primary.Type == KnownPrimaryType.Decimal || primary.Type == KnownPrimaryType.Int || primary.Type == KnownPrimaryType.Long || - primary.Type == KnownPrimaryType.Object || - primary.Type == KnownPrimaryType.UnixTime) + primary.Type == KnownPrimaryType.Object) { if (isRequired) { @@ -254,7 +259,8 @@ private static string ValidatePrimaryType(this PrimaryType primary, IScopeProvid builder.AppendLine("if ({0} && !Buffer.isBuffer({0})) {{", valueReference, lowercaseTypeName); return ConstructValidationCheck(builder, typeErrorMessage, valueReference, primary.Name).ToString(); } - else if (primary.Type == KnownPrimaryType.DateTime || primary.Type == KnownPrimaryType.Date || primary.Type == KnownPrimaryType.DateTimeRfc1123) + else if (primary.Type == KnownPrimaryType.DateTime || primary.Type == KnownPrimaryType.Date || + primary.Type == KnownPrimaryType.DateTimeRfc1123 || primary.Type == KnownPrimaryType.UnixTime) { if (isRequired) { @@ -303,11 +309,13 @@ private static string PrimaryTSType(this PrimaryType primary) if (primary.Type == KnownPrimaryType.Boolean) return "boolean"; - else if (primary.Type == KnownPrimaryType.Double || primary.Type == KnownPrimaryType.Decimal || primary.Type == KnownPrimaryType.Int || primary.Type == KnownPrimaryType.Long || primary.Type == KnownPrimaryType.UnixTime) + else if (primary.Type == KnownPrimaryType.Double || primary.Type == KnownPrimaryType.Decimal || + primary.Type == KnownPrimaryType.Int || primary.Type == KnownPrimaryType.Long) return "number"; else if (primary.Type == KnownPrimaryType.String || primary.Type == KnownPrimaryType.Uuid) return "string"; - else if (primary.Type == KnownPrimaryType.Date || primary.Type == KnownPrimaryType.DateTime || primary.Type == KnownPrimaryType.DateTimeRfc1123) + else if (primary.Type == KnownPrimaryType.Date || primary.Type == KnownPrimaryType.DateTime || + primary.Type == KnownPrimaryType.DateTimeRfc1123 || primary.Type == KnownPrimaryType.UnixTime) return "Date"; else if (primary.Type == KnownPrimaryType.Object) return "any"; // TODO: test this @@ -747,8 +755,8 @@ public static string ConstructMapper(this IType type, string serializedName, IPa { builder.AppendLine("type: {").Indent().AppendLine("name: 'Boolean'").Outdent().AppendLine("}"); } - else if(primary.Type == KnownPrimaryType.Int || primary.Type == KnownPrimaryType.Long || primary.Type == KnownPrimaryType.Decimal || - primary.Type == KnownPrimaryType.Double || primary.Type == KnownPrimaryType.UnixTime) + else if (primary.Type == KnownPrimaryType.Int || primary.Type == KnownPrimaryType.Long || + primary.Type == KnownPrimaryType.Decimal || primary.Type == KnownPrimaryType.Double) { builder.AppendLine("type: {").Indent().AppendLine("name: 'Number'").Outdent().AppendLine("}"); } @@ -784,6 +792,10 @@ public static string ConstructMapper(this IType type, string serializedName, IPa { builder.AppendLine("type: {").Indent().AppendLine("name: 'TimeSpan'").Outdent().AppendLine("}"); } + else if (primary.Type == KnownPrimaryType.UnixTime) + { + builder.AppendLine("type: {").Indent().AppendLine("name: 'UnixTime'").Outdent().AppendLine("}"); + } else if (primary.Type == KnownPrimaryType.Object) { builder.AppendLine("type: {").Indent().AppendLine("name: 'Object'").Outdent().AppendLine("}"); diff --git a/AutoRest/Generators/NodeJS/NodeJS/GlobalSuppressions.cs b/AutoRest/Generators/NodeJS/NodeJS/GlobalSuppressions.cs index a0c9b570f4d8c..9fecaab118c8e 100644 --- a/AutoRest/Generators/NodeJS/NodeJS/GlobalSuppressions.cs +++ b/AutoRest/Generators/NodeJS/NodeJS/GlobalSuppressions.cs @@ -193,4 +193,5 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "readOnly", Scope = "member", Target = "Microsoft.Rest.Generator.NodeJS.TemplateModels.ClientModelExtensions.#ConstructMapper(Microsoft.Rest.Generator.ClientModel.IType,System.String,Microsoft.Rest.Generator.ClientModel.IParameter,System.Boolean,System.Boolean)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Scope = "member", Target = "Microsoft.Rest.Generator.NodeJS.TemplateModels.ClientModelExtensions.#ValidatePrimaryType(Microsoft.Rest.Generator.ClientModel.PrimaryType,Microsoft.Rest.Generator.Utilities.IScopeProvider,System.String,System.Boolean)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode", Scope = "member", Target = "Microsoft.Rest.Generator.NodeJS.TemplateModels.ClientModelExtensions.#ConstructMapper(Microsoft.Rest.Generator.ClientModel.IType,System.String,Microsoft.Rest.Generator.ClientModel.IParameter,System.Boolean,System.Boolean)")] +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "UnixTime", Scope = "member", Target = "Microsoft.Rest.Generator.NodeJS.TemplateModels.ClientModelExtensions.#ConstructMapper(Microsoft.Rest.Generator.ClientModel.IType,System.String,Microsoft.Rest.Generator.ClientModel.IParameter,System.Boolean,System.Boolean)")] diff --git a/AutoRest/Generators/NodeJS/NodeJS/NodeJsCodeNamer.cs b/AutoRest/Generators/NodeJS/NodeJS/NodeJsCodeNamer.cs index d2f43a402f589..2dc7c2f0edd6a 100644 --- a/AutoRest/Generators/NodeJS/NodeJS/NodeJsCodeNamer.cs +++ b/AutoRest/Generators/NodeJS/NodeJS/NodeJsCodeNamer.cs @@ -365,6 +365,10 @@ private static IType NormalizePrimaryType(PrimaryType primaryType) { primaryType.Name = "Date"; } + else if (primaryType.Type == KnownPrimaryType.UnixTime) + { + primaryType.Name = "Date"; + } else if (primaryType.Type == KnownPrimaryType.Double) { primaryType.Name = "Number"; @@ -393,10 +397,6 @@ private static IType NormalizePrimaryType(PrimaryType primaryType) { primaryType.Name = "moment.duration"; } - else if (primaryType.Type == KnownPrimaryType.UnixTime) - { - primaryType.Name = "Number"; - } else if (primaryType.Type == KnownPrimaryType.Uuid) { primaryType.Name = "Uuid"; diff --git a/ClientRuntimes/NodeJS/ms-rest/README.md b/ClientRuntimes/NodeJS/ms-rest/README.md index cb4aca73ab405..1da52bff1ac92 100644 --- a/ClientRuntimes/NodeJS/ms-rest/README.md +++ b/ClientRuntimes/NodeJS/ms-rest/README.md @@ -18,7 +18,7 @@ var msrest = require('ms-rest'); ## Serialization/Deserialization Features - Type checking - - (String, Number, Boolean, ByteArray, Date, DateTime, Enum, TimeSpan, DateTimeRfc1123, Object, Stream, Sequence, Dictionary, Composite, Uuid(as a string)) + - (String, Number, Boolean, ByteArray, Base64Url, Date, DateTime, Enum, TimeSpan, DateTimeRfc1123, UnixTime, Object, Stream, Sequence, Dictionary, Composite, Uuid(as a string)) - Validation of specified constraints - ExclusiveMaximum, ExclusiveMinimum, InclusiveMaximum, InclusiveMinimum, MaxItems, MaxLength, MinItems, MinLength, MultipleOf, Pattern, UniqueItems - Flattening/Unflattening properties @@ -26,6 +26,7 @@ Features - Model Properties marked as constant are set during serialization, irrespective of they being provided or not - Required check (If a model or property is marked required and is not provided in the object then an error is thrown) - Readonly check (If a model or property is marked readonly then it is not sent on the wire during, serialization) +- Serializing Constant values - serialize an array of dictionary of primitive values ```javascript diff --git a/ClientRuntimes/NodeJS/ms-rest/lib/serialization.js b/ClientRuntimes/NodeJS/ms-rest/lib/serialization.js index de8d0778efd92..671292b9f43ba 100644 --- a/ClientRuntimes/NodeJS/ms-rest/lib/serialization.js +++ b/ClientRuntimes/NodeJS/ms-rest/lib/serialization.js @@ -74,7 +74,7 @@ exports.serialize = function (mapper, object, objectName) { payload = serializeBasicTypes.call(this, mapperType, objectName, object); } else if (mapperType.match(/^Enum$/ig) !== null) { payload = serializeEnumType.call(this, objectName, mapper.type.allowedValues, object); - } else if (mapperType.match(/^(Date|DateTime|TimeSpan|DateTimeRfc1123)$/ig) !== null) { + } else if (mapperType.match(/^(Date|DateTime|TimeSpan|DateTimeRfc1123|UnixTime)$/ig) !== null) { payload = serializeDateTypes.call(this, mapperType, object, objectName); } else if (mapperType.match(/^ByteArray$/ig) !== null) { payload = serializeBufferType.call(this, objectName, object); @@ -370,6 +370,13 @@ function serializeDateTypes(typeName, value, objectName) { throw new Error(util.format('%s must be an instanceof Date or a string in RFC-1123 format.', objectName)); } value = (value instanceof Date) ? value.toUTCString() : new Date(value).toUTCString(); + } else if (typeName.match(/^UnixTime$/ig) !== null) { + if (!(value instanceof Date || + (typeof value.valueOf() === 'string' && !isNaN(Date.parse(value))))) { + throw new Error(util.format('%s must be an instanceof Date or a string in RFC-1123/ISO8601 format ' + + 'for it to be serialized in UnixTime/Epoch format.', objectName)); + } + value = dateToUnixTime(value); } else if (typeName.match(/^TimeSpan$/ig) !== null) { if (!moment.isDuration(value)) { throw new Error(util.format('%s must be a TimeSpan/Duration.', objectName)); @@ -402,8 +409,10 @@ exports.deserialize = function (mapper, responseBody, objectName) { payload = responseBody; } else if (mapperType.match(/^(Date|DateTime|DateTimeRfc1123)$/ig) !== null) { payload = new Date(responseBody); - } else if (mapperType.match(/^(TimeSpan)$/ig) !== null) { + } else if (mapperType.match(/^TimeSpan$/ig) !== null) { payload = moment.duration(responseBody); + } else if (mapperType.match(/^UnixTime$/ig) !== null) { + payload = unixTimeToDate(responseBody); } else if (mapperType.match(/^ByteArray$/ig) !== null) { payload = new Buffer(responseBody, 'base64'); } else if (mapperType.match(/^Base64Url$/ig) !== null) { @@ -595,4 +604,21 @@ function base64UrlToBuffer(str) { return new Buffer(str, 'base64'); } +function dateToUnixTime(d) { + if (!d) { + return null; + } + if (typeof d.valueOf() === 'string') { + d = new Date(d); + } + return parseInt(d.getTime() / 1000); +} + +function unixTimeToDate(n) { + if (!n) { + return null; + } + return new Date(n*1000); +} + exports = module.exports; \ No newline at end of file diff --git a/ClientRuntimes/NodeJS/ms-rest/test/serializationTests.js b/ClientRuntimes/NodeJS/ms-rest/test/serializationTests.js index d9be4bd39fba9..32c89671d37cf 100644 --- a/ClientRuntimes/NodeJS/ms-rest/test/serializationTests.js +++ b/ClientRuntimes/NodeJS/ms-rest/test/serializationTests.js @@ -195,6 +195,12 @@ describe('msrest', function () { serializedDateString.should.equal('+010000-01-01T11:59:59.000Z'); done(); }); + it('should correctly serialize a Date object with max value and format UnixTime', function (done) { + mapper = { type : { name: 'UnixTime' } }; + var serializedDate = msRest.serialize(mapper, new Date('9999-12-31T23:59:59-12:00'), 'dateTimeObj'); + serializedDate.should.equal(253402343999); + done(); + }); it('should correctly serialize a string in DateTimeRfc1123', function (done) { mapper = { type : { name: 'DateTimeRfc1123' } }; var rfc = new Date('Mon, 01 Jan 0001 00:00:00 GMT'); From 78ce979446012ac718636397282e573baeb9e5eb Mon Sep 17 00:00:00 2001 From: John Hart Date: Fri, 29 Apr 2016 18:54:15 -0700 Subject: [PATCH 15/19] Updated the UserAgent ProductInfoHeaderValue to use the AssemblyInformationalVersion or the AssemblyFileVersion, if neither attribute is available it will default to the Assembly Version. (#979) --- .../CSharp/CSharp.Tests/AcceptanceTests.cs | 3 ++ .../CSharp.Tests/Properties/AssemblyInfo.cs | 1 + .../ServiceClient.cs | 54 ++++++++++++++----- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs b/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs index 804db915e6111..bdd10a6f30136 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/AcceptanceTests.cs @@ -1366,6 +1366,9 @@ public void HeaderTests() SwaggerPath("header.json"), ExpectedPath("Header")); using (var client = new AutoRestSwaggerBATHeaderService(Fixture.Uri)) { + // Check the UserAgent ProductInfoHeaderValue + Assert.Equal("1.5.0.1", client.UserAgent.Select(c => c.Product.Version.ToString()).FirstOrDefault()); + // POST param/prim/integer client.Header.ParamInteger("positive", 1); client.Header.ParamInteger("negative", -2); diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/Properties/AssemblyInfo.cs b/AutoRest/Generators/CSharp/CSharp.Tests/Properties/AssemblyInfo.cs index 68d34505c6d76..61dbf33914dc9 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/Properties/AssemblyInfo.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/Properties/AssemblyInfo.cs @@ -17,3 +17,4 @@ [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyInformationalVersion("1.5.0.1")] diff --git a/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime/ServiceClient.cs b/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime/ServiceClient.cs index e80afc887e0f8..6763f4e6641fa 100644 --- a/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime/ServiceClient.cs +++ b/ClientRuntimes/CSharp/Microsoft.Rest.ClientRuntime/ServiceClient.cs @@ -208,25 +208,53 @@ protected void InitializeHttpClient(HttpClientHandler httpClientHandler, params HttpClient = newClient; Type type = this.GetType(); HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(type.FullName, - GetAssemblyVersion())); + GetClientVersion())); } /// - /// Get the assembly version of a service client. + /// Gets the AssemblyInformationalVersion if available + /// if not it gets the AssemblyFileVerion + /// if neither are available it will default to the Assembly Version of a service client. /// - /// The assembly version of the client. - private string GetAssemblyVersion() + /// The version of the client. + private string GetClientVersion() { + + string version = String.Empty; Type type = this.GetType(); - string version = - type - .GetTypeInfo() - .Assembly - .FullName - .Split(',') - .Select(c => c.Trim()) - .First(c => c.StartsWith("Version=", StringComparison.OrdinalIgnoreCase)) - .Substring("Version=".Length); + Assembly assembly = type.GetTypeInfo().Assembly; + + try + { + // try to get AssemblyInformationalVersion first + AssemblyInformationalVersionAttribute aivAttribute = + assembly.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; + version = aivAttribute?.InformationalVersion; + + // if not available try to get AssemblyFileVersion + if (String.IsNullOrEmpty(version)) + { + AssemblyFileVersionAttribute fvAttribute = + assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute; + version = fvAttribute?.Version; + } + } + catch (AmbiguousMatchException) + { + // in case there are more then one attribute of the type + } + + // no usable version attribute found so default to Assembly Version + if (String.IsNullOrEmpty(version)) + { + version = + assembly + .FullName + .Split(',') + .Select(c => c.Trim()) + .First(c => c.StartsWith("Version=", StringComparison.OrdinalIgnoreCase)) + .Substring("Version=".Length); + } return version; } } From 1f4cc357f631f24ba0e837c236cd0e75d23946d9 Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Fri, 29 Apr 2016 18:54:24 -0700 Subject: [PATCH 16/19] msrest/msrestazure 0.3.0 (#982) --- .../Azure.Python/AzurePythonCodeGenerator.cs | 2 +- .../AzureServiceClientTemplateModel.cs | 2 +- .../Python/Python/PythonCodeGenerator.cs | 2 +- ClientRuntimes/Python/msrest/doc/conf.py | 4 ++-- ClientRuntimes/Python/msrest/msrest/version.py | 2 +- ClientRuntimes/Python/msrest/readme.rst | 15 ++++++++++++++- ClientRuntimes/Python/msrest/setup.py | 2 +- ClientRuntimes/Python/msrestazure/doc/conf.py | 4 ++-- .../Python/msrestazure/msrestazure/version.py | 2 +- ClientRuntimes/Python/msrestazure/readme.rst | 15 +++++++++++++++ ClientRuntimes/Python/msrestazure/setup.py | 4 ++-- 11 files changed, 41 insertions(+), 13 deletions(-) diff --git a/AutoRest/Generators/Python/Azure.Python/AzurePythonCodeGenerator.cs b/AutoRest/Generators/Python/Azure.Python/AzurePythonCodeGenerator.cs index 0ad15558928b5..eeb311593bb52 100644 --- a/AutoRest/Generators/Python/Azure.Python/AzurePythonCodeGenerator.cs +++ b/AutoRest/Generators/Python/Azure.Python/AzurePythonCodeGenerator.cs @@ -19,7 +19,7 @@ namespace Microsoft.Rest.Generator.Azure.Python { public class AzurePythonCodeGenerator : PythonCodeGenerator { - private const string ClientRuntimePackage = "msrestazure version 0.2.1"; + private const string ClientRuntimePackage = "msrestazure version 0.3.0"; // page extensions class dictionary. private IList pageModels; diff --git a/AutoRest/Generators/Python/Azure.Python/TemplateModels/AzureServiceClientTemplateModel.cs b/AutoRest/Generators/Python/Azure.Python/TemplateModels/AzureServiceClientTemplateModel.cs index f56bc3935547a..0a3b44b0e6446 100644 --- a/AutoRest/Generators/Python/Azure.Python/TemplateModels/AzureServiceClientTemplateModel.cs +++ b/AutoRest/Generators/Python/Azure.Python/TemplateModels/AzureServiceClientTemplateModel.cs @@ -97,7 +97,7 @@ public override string SetupRequires { get { - return "\"msrest>=0.2.0\", \"msrestazure>=0.2.1\""; + return "\"msrest>=0.3.0\", \"msrestazure>=0.3.0\""; } } diff --git a/AutoRest/Generators/Python/Python/PythonCodeGenerator.cs b/AutoRest/Generators/Python/Python/PythonCodeGenerator.cs index d987055d49f6f..8131b8cba6d34 100644 --- a/AutoRest/Generators/Python/Python/PythonCodeGenerator.cs +++ b/AutoRest/Generators/Python/Python/PythonCodeGenerator.cs @@ -16,7 +16,7 @@ namespace Microsoft.Rest.Generator.Python { public class PythonCodeGenerator : CodeGenerator { - private const string ClientRuntimePackage = "msrest version 0.2.0"; + private const string ClientRuntimePackage = "msrest version 0.3.0"; public PythonCodeGenerator(Settings settings) : base(settings) { diff --git a/ClientRuntimes/Python/msrest/doc/conf.py b/ClientRuntimes/Python/msrest/doc/conf.py index 1dfe56981ffc9..169d6053b55f8 100644 --- a/ClientRuntimes/Python/msrest/doc/conf.py +++ b/ClientRuntimes/Python/msrest/doc/conf.py @@ -57,9 +57,9 @@ # built documents. # # The short X.Y version. -version = '0.2.0' +version = '0.3.0' # The full version, including alpha/beta/rc tags. -release = '0.2.0' +release = '0.3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/ClientRuntimes/Python/msrest/msrest/version.py b/ClientRuntimes/Python/msrest/msrest/version.py index 11739ebc3606c..527b2a717c20b 100644 --- a/ClientRuntimes/Python/msrest/msrest/version.py +++ b/ClientRuntimes/Python/msrest/msrest/version.py @@ -25,4 +25,4 @@ # -------------------------------------------------------------------------- -msrest_version = "0.2.0" +msrest_version = "0.3.0" diff --git a/ClientRuntimes/Python/msrest/readme.rst b/ClientRuntimes/Python/msrest/readme.rst index 77e50e0da4bb2..b65e1bf5b13a5 100644 --- a/ClientRuntimes/Python/msrest/readme.rst +++ b/ClientRuntimes/Python/msrest/readme.rst @@ -15,6 +15,19 @@ To install: Release History --------------- +2016-04-26 Version 0.3.0 +++++++++++++++++++++++++ + +**Bugfixes** + +- Read only values are no longer in __init__ or sent to the server (https://github.com/Azure/autorest/pull/959) +- Useless kwarg removed + +**Behaviour changes** + +- Needs Autorest > 0.16.0 Nightly 20160426 + + 2016-03-25 Version 0.2.0 ++++++++++++++++++++++++ @@ -23,7 +36,7 @@ Release History - Manage integer enum values (https://github.com/Azure/autorest/pull/879) - Add missing application/json Accept HTTP header (https://github.com/Azure/azure-sdk-for-python/issues/553) -**Beheviour changes** +**Behaviour changes** - Needs Autorest > 0.16.0 Nightly 20160324 diff --git a/ClientRuntimes/Python/msrest/setup.py b/ClientRuntimes/Python/msrest/setup.py index b3dca9089b534..02bdd49b71aab 100644 --- a/ClientRuntimes/Python/msrest/setup.py +++ b/ClientRuntimes/Python/msrest/setup.py @@ -28,7 +28,7 @@ setup( name='msrest', - version='0.2.0', + version='0.3.0', author='Microsoft Corporation', packages=['msrest'], url=("https://github.com/xingwu1/autorest/tree/python/" diff --git a/ClientRuntimes/Python/msrestazure/doc/conf.py b/ClientRuntimes/Python/msrestazure/doc/conf.py index 9a76b3204d5c2..1225f72e6ec9d 100644 --- a/ClientRuntimes/Python/msrestazure/doc/conf.py +++ b/ClientRuntimes/Python/msrestazure/doc/conf.py @@ -58,9 +58,9 @@ # built documents. # # The short X.Y version. -version = '0.2.1' +version = '0.3.0' # The full version, including alpha/beta/rc tags. -release = '0.2.1' +release = '0.3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/ClientRuntimes/Python/msrestazure/msrestazure/version.py b/ClientRuntimes/Python/msrestazure/msrestazure/version.py index 23c80b2514da3..edb859f0a87d2 100644 --- a/ClientRuntimes/Python/msrestazure/msrestazure/version.py +++ b/ClientRuntimes/Python/msrestazure/msrestazure/version.py @@ -24,4 +24,4 @@ # # -------------------------------------------------------------------------- -msrestazure_version = "0.2.1" +msrestazure_version = "0.3.0" diff --git a/ClientRuntimes/Python/msrestazure/readme.rst b/ClientRuntimes/Python/msrestazure/readme.rst index 18a49a8035f2b..7ba256b12c10a 100644 --- a/ClientRuntimes/Python/msrestazure/readme.rst +++ b/ClientRuntimes/Python/msrestazure/readme.rst @@ -15,6 +15,21 @@ To install: Release History --------------- +2016-04-26 Version 0.3.0 +++++++++++++++++++++++++ + +Update msrest dependency to 0.3.0 + +**Bugfixes** + +- Read only values are no longer in __init__ or sent to the server (https://github.com/Azure/autorest/pull/959) +- Useless kwarg removed + +**Behaviour changes** + +- Needs Autorest > 0.16.0 Nightly 20160426 + + 2016-03-31 Version 0.2.1 ++++++++++++++++++++++++ diff --git a/ClientRuntimes/Python/msrestazure/setup.py b/ClientRuntimes/Python/msrestazure/setup.py index d25ce47f33493..7778b0185d42b 100644 --- a/ClientRuntimes/Python/msrestazure/setup.py +++ b/ClientRuntimes/Python/msrestazure/setup.py @@ -28,7 +28,7 @@ setup( name='msrestazure', - version='0.2.1', + version='0.3.0', author='Microsoft Corporation', packages=['msrestazure'], url=('https://github.com/xingwu1/autorest/tree/python/' @@ -49,5 +49,5 @@ 'License :: OSI Approved :: MIT License', 'Topic :: Software Development'], install_requires=[ - "msrest>=0.2.0"], + "msrest>=0.3.0"], ) From 47753e5c3b665d2a8033bf0d82cb6bad65b39ceb Mon Sep 17 00:00:00 2001 From: Dan Schulte Date: Fri, 29 Apr 2016 18:54:41 -0700 Subject: [PATCH 17/19] Fix AzureResourceSchema projects (#956) * Automatically detect MSBuild tools version in Windows platform * Add initial AzureResourceSchema project and test project * Update AzureResourceSchema projects and add initial c# files * Add AzureResourceSchema to configuration file * AzureResourceSchemaCodeGenerator shows up in AutoRest help and tests pass * Almost have Storage schema generating from swagger spec * Fix AzureResourceSchema project * Can generate storage schema from swagger * Fix FXCopy issues --- AutoRest.sln | 10 +- AutoRest/AutoRest.Core/AutoRest.nuspec | 1 + AutoRest/AutoRest/AutoRest.Release.json | 3 + AutoRest/AutoRest/AutoRest.json | 3 + ...Generator.AzureResourceSchema.Tests.csproj | 31 ++- .../AzureResourceSchemaCodeGeneratorTests.cs | 155 +++++++++++++ .../AzureResourceSchema.Tests/packages.config | 1 + ...oRest.Generator.AzureResourceSchema.csproj | 50 +++- .../AzureResourceSchemaCodeGenerator.cs | 218 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 6 +- .../AzureResourceSchema/Resource.cs | 56 +++++ .../AzureResourceSchema/ResourceProperty.cs | 50 ++++ .../AzureResourceSchema/ResourceSchema.cs | 171 ++++++++++++++ .../AzureResourceSchema/packages.config | 4 + CodeGenerator.sln | 27 ++- 15 files changed, 771 insertions(+), 15 deletions(-) create mode 100644 AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AzureResourceSchemaCodeGeneratorTests.cs create mode 100644 AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/AzureResourceSchemaCodeGenerator.cs create mode 100644 AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/Resource.cs create mode 100644 AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/ResourceProperty.cs create mode 100644 AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/ResourceSchema.cs create mode 100644 AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/packages.config diff --git a/AutoRest.sln b/AutoRest.sln index b11b89d798ca5..e9e2ddf312323 100644 --- a/AutoRest.sln +++ b/AutoRest.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRest.Core", "AutoRest\AutoRest.Core\AutoRest.Core.csproj", "{C876085F-9DC3-41F0-B7B4-17022CD84684}" EndProject @@ -372,6 +372,14 @@ Global {DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU {DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU {DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU + {654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Debug|Any CPU {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Debug|Any CPU {654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/AutoRest/AutoRest.Core/AutoRest.nuspec b/AutoRest/AutoRest.Core/AutoRest.nuspec index 0451285cb520a..2af544a885822 100644 --- a/AutoRest/AutoRest.Core/AutoRest.nuspec +++ b/AutoRest/AutoRest.Core/AutoRest.nuspec @@ -31,6 +31,7 @@ + diff --git a/AutoRest/AutoRest/AutoRest.Release.json b/AutoRest/AutoRest/AutoRest.Release.json index b488b12ca1fc8..f368702db7a63 100644 --- a/AutoRest/AutoRest/AutoRest.Release.json +++ b/AutoRest/AutoRest/AutoRest.Release.json @@ -29,6 +29,9 @@ }, "Azure.Python": { "type": "AzurePythonCodeGenerator, AutoRest.Generator.Azure.Python" + }, + "AzureResourceSchema": { + "type": "AzureResourceSchemaCodeGenerator, AutoRest.Generator.AzureResourceSchema" } }, "modelers": { diff --git a/AutoRest/AutoRest/AutoRest.json b/AutoRest/AutoRest/AutoRest.json index b488b12ca1fc8..f368702db7a63 100644 --- a/AutoRest/AutoRest/AutoRest.json +++ b/AutoRest/AutoRest/AutoRest.json @@ -29,6 +29,9 @@ }, "Azure.Python": { "type": "AzurePythonCodeGenerator, AutoRest.Generator.Azure.Python" + }, + "AzureResourceSchema": { + "type": "AzureResourceSchemaCodeGenerator, AutoRest.Generator.AzureResourceSchema" } }, "modelers": { diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj index 01522ea89f2b4..be1ade26d44d8 100644 --- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj +++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/AutoRest.Generator.AzureResourceSchema.Tests.csproj @@ -1,6 +1,7 @@  - - + + + Debug @@ -8,6 +9,7 @@ {1C3B4A33-E045-4C8F-9202-1B651A686567} Library Properties + Microsoft.Rest.Generator.AzureResourceSchema.Tests AutoRest.Generator.AzureResourceSchema.Tests AutoRest.Generator.AzureResourceSchema.Tests v4.5.2 @@ -33,6 +35,10 @@ 4 + + ..\..\..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True + @@ -42,25 +48,32 @@ - ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll + ..\..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll True - ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll + ..\..\..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll True - ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll + ..\..\..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll True - ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll + ..\..\..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll True + + + + {c876085f-9dc3-41f0-b7b4-17022cd84684} + AutoRest.Core + + PreserveNewest @@ -72,12 +85,16 @@ AutoRest.Generator.AzureResourceSchema + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + +