GitHub PullRequestReviewCommentEvent at 2014-02-25 20:35:31
Repository: azure-sdk-for-node
Actor: amarzavery
Payload: {"comment":{"url":"https://api.github.com/repos/WindowsAzure/azure-sdk-for-node/pulls/comments/10054483","id":10054483,"diff_hunk":"@@ -0,0 +1,183 @@\n+// \n+// Copyright (c) Microsoft and contributors.  All rights reserved.\n+// \n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//   http://www.apache.org/licenses/LICENSE-2.0\n+// \n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// \n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+// \n+\n+var should = require('should');\n+var testutil = require('../../util/util');\n+var util = require('util');\n+var tc = require('../../stubs/Test.Serialization');\n+var fs = require('fs');\n+var nock = require('nock');\n+var azure = testutil.libRequire('azure');\n+var CertificateCloudCredentials = azure.CertificateCloudCredentials;\n+var TestSerializationClient = tc.TestSerializationClient;\n+\n+// strips the milliseconds from the Date object in ISOString() format\n+//2014-02-22T00:56:09.000Z -> 2014-02-22T00:56:09\n+function stripMilliseconds (time) {\n+  return time.slice(0,-5);\n+}\n+\n+suite('datetime-datatype-deserialization-tests', function () {\n+  var baseUri = 'http://helloworld';\n+  var subscriptionId = \"c9cbd920-c00c-427c-852b-8aaf38badaeb\";\n+  var pemfile = process.env.AZURE_CERTIFICATE_PEM_FILE;\n+  var credentials = new CertificateCloudCredentials({ subscriptionId: subscriptionId, pem: fs.readFileSync(pemfile).toString()});\n+  var testclient = new TestSerializationClient(credentials, baseUri);\n+  \n+  test('GetDateTime with current date time value should deserialize properly', function (done) {\n+    var nowDate = new Date(Date.now());\n+    var isoNowString = stripMilliseconds(nowDate.toISOString());\n+    var utcNowString = nowDate.toUTCString();\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTime\")\n+    .reply(200, \"<DateTimeValue>\" + isoNowString + \"</DateTimeValue>\");\n+    testclient.deserialization.getDateTime(function (error, result) {\n+      should.not.exist(error);\n+      should.exist(result);\n+      var resultDateString = stripMilliseconds(result.dateTimeValue.toISOString());\n+      new Date(resultDateString).valueOf().should.equal(new Date(utcNowString).valueOf());\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTime with max date time value should deserialize properly', function (done) {\n+    var maxDate = new Date(8640000000000000);\n+    var isoMaxstr = stripMilliseconds(maxDate.toISOString());\n+    var utcMaxstr = maxDate.toUTCString();\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTime\")\n+    .reply(200, \"<DateTimeValue>\" + isoMaxstr + \"</DateTimeValue>\");\n+    testclient.deserialization.getDateTime(function (error, result) {\n+      should.not.exist(error);\n+      should.exist(result);\n+      var resultDateString = stripMilliseconds(result.dateTimeValue.toISOString());\n+      new Date(resultDateString).valueOf().should.equal(new Date(utcMaxstr).valueOf());\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTime with min date time value should deserialize properly', function (done) {\n+    var minDate = new Date(-8640000000000000);\n+    var isoMinstr = stripMilliseconds(minDate.toISOString());\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTime\")\n+    .reply(200, \"<DateTimeValue>\" + isoMinstr + \"</DateTimeValue>\");\n+    testclient.deserialization.getDateTime(function (error, result) {\n+      should.not.exist(error);\n+      should.exist(result);\n+      var resultDateString = stripMilliseconds(result.dateTimeValue.toISOString());\n+      new Date(resultDateString).valueOf().should.equal(minDate.valueOf());\n+    });\n+    done();\n+  });\n+    \n+  test('GetDateTime with empty element should throw an error', function (done) {\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTime\")\n+    .reply(200, \"<DateTimeValue></DateTimeValue>\");\n+    testclient.deserialization.getDateTime(function (error, result) {\n+      should.exist(error);\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTime with nil value should throw an error', function (done) {\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTime\")\n+    .reply(200, \"<DateTimeValue xmlns:i=\\\"http://www.w3.org/2001/XMLSchema-instance\\\" i:nil=\\\"true\\\" />\");\n+    testclient.deserialization.getDateTime(function (error, result) {\n+      should.exist(error);\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTime with null element should throw an error', function (done) {\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTime\")\n+    .reply(200, \"<DateTimeValue />\");\n+    testclient.deserialization.getDateTime(function (error, result) {\n+      should.exist(error);\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTimeNilableNullable with a nil value should deserialize into undefined value', function (done) {\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTimeNilableNullable\")\n+    .reply(200, \"<DateTimeValue xmlns:i=\\\"http://www.w3.org/2001/XMLSchema-instance\\\" i:nil=\\\"true\\\" />\");\n+    testclient.deserialization.getDateTimeNilableNullable(function (error, result) {\n+      should.not.exist(error);\n+      should.not.exist(result.dateTimeValue);\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTimeNilableNullable with an empty value should deserialize into undefined', function (done) {\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTimeNilableNullable\")\n+    .reply(200, \"<DateTimeValue></DateTimeValue>\");\n+    testclient.deserialization.getDateTimeNilableNullable(function (error, result) {\n+      should.not.exist(error);\n+      result.dateTimeValue.should.equal(undefined);\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTimeNilableNullable with null element should deserialize into undefined', function (done) {\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTime\")\n+    .reply(200, \"<DateTimeValue />\");\n+    testclient.deserialization.getDateTime(function (error, result) {\n+      should.not.exist(error);\n+      result.dateTimeValue.should.equal(undefined);\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTimeNullable with a nil value should deserialize into undefined value', function (done) {\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTimeNullable\")\n+    .reply(200, \"<DateTimeValue xmlns:i=\\\"http://www.w3.org/2001/XMLSchema-instance\\\" i:nil=\\\"true\\\" />\");\n+    testclient.deserialization.getDateTimeNullable(function (error, result) {\n+      should.not.exist(error);\n+      should.not.exist(result.dateTimeValue);\n+    });\n+    done();\n+  });\n+  \n+  test('GetDateTimeNullable with an empty value should deserialize into null', function (done) {\n+    nock(\"http://helloworld\")\n+    .get(\"/GetDateTimeNilableNullable\")\n+    .reply(200, \"<DateTimeValue></DateTimeValue>\");\n+    testclient.deserialization.GetDateTimeNullable(function (error, result) {\n+      should.not.exist(error);\n+      result.dateTimeValue.should.equal(null);","path":"test/common/deserialization/datetime-datatype-deserialization-tests.js","position":167,"original_position":167,"commit_id":"75cd493a390cf6135858d942c4b27490282c0102","original_commit_id":"75cd493a390cf6135858d942c4b27490282c0102","user":{"login":"amarzavery","id":4521223,"avatar_url":"https://gravatar.com/avatar/cc777c877c918c1e4742271fdf3124ec?d=https%3A%2F%2Fidenticons.github.com%2F908fc2362f19e6fff2c98c174ee254f2.png&r=x","gravatar_id":"cc777c877c918c1e4742271fdf3124ec","url":"https://api.github.com/users/amarzavery","html_url":"https://github.com/amarzavery","followers_url":"https://api.github.com/users/amarzavery/followers","following_url":"https://api.github.com/users/amarzavery/following{/other_user}","gists_url":"https://api.github.com/users/amarzavery/gists{/gist_id}","starred_url":"https://api.github.com/users/amarzavery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amarzavery/subscriptions","organizations_url":"https://api.github.com/users/amarzavery/orgs","repos_url":"https://api.github.com/users/amarzavery/repos","events_url":"https://api.github.com/users/amarzavery/events{/privacy}","received_events_url":"https://api.github.com/users/amarzavery/received_events","type":"User","site_admin":false},"body":"null is not a valid value for DateTime or for any basic data type (bool, int, float, etc.). If we get null for a {DataType}Nullable then it should be fine else throw an error... Right? Does it matter if null is a valid date or not for DateTimeNullable (DateTime?)  ?","created_at":"2014-02-25T20:35:31Z","updated_at":"2014-02-25T20:35:31Z","html_url":"https://github.com/WindowsAzure/azure-sdk-for-node/pull/1164#discussion_r10054483","pull_request_url":"https://api.github.com/repos/WindowsAzure/azure-sdk-for-node/pulls/1164","_links":{"self":{"href":"https://api.github.com/repos/WindowsAzure/azure-sdk-for-node/pulls/comments/10054483"},"html":{"href":"https://github.com/WindowsAzure/azure-sdk-for-node/pull/1164#discussion_r10054483"},"pull_request":{"href":"https://api.github.com/repos/WindowsAzure/azure-sdk-for-node/pulls/1164"}}}}