-
Notifications
You must be signed in to change notification settings - Fork 72
/
acceptanceTests.ts
2612 lines (2447 loc) · 120 KB
/
acceptanceTests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
'use strict';
import * as should from 'should';
import * as util from 'util';
import * as assert from 'assert';
import * as msRest from 'ms-rest-js';
import * as moment from 'moment';
import * as fs from 'fs';
import stream = require('stream');
import { AutoRestBoolTestService } from '../Expected/AcceptanceTests/BodyBoolean/autoRestBoolTestService';
import { AutoRestSwaggerBATService, AutoRestSwaggerBATServiceModels } from '../Expected/AcceptanceTests/BodyString/autoRestSwaggerBATService';
import { AutoRestIntegerTestService } from '../Expected/AcceptanceTests/BodyInteger/autoRestIntegerTestService';
import { CompositeBoolInt } from '../Expected/AcceptanceTests/CompositeBoolIntClient/compositeBoolInt';
import { AutoRestNumberTestService } from '../Expected/AcceptanceTests/BodyNumber/autoRestNumberTestService';
import { AutoRestSwaggerBATByteService } from '../Expected/AcceptanceTests/BodyByte/autoRestSwaggerBATByteService';
import { AutoRestDateTestService } from '../Expected/AcceptanceTests/BodyDate/autoRestDateTestService';
import { AutoRestDateTimeTestService } from '../Expected/AcceptanceTests/BodyDateTime/autoRestDateTimeTestService';
import { AutoRestRFC1123DateTimeTestService } from '../Expected/AcceptanceTests/BodyDateTimeRfc1123/autoRestRFC1123DateTimeTestService';
import { AutoRestDurationTestService } from '../Expected/AcceptanceTests/BodyDuration/autoRestDurationTestService';
import { AutoRestUrlTestService, AutoRestUrlTestServiceModels } from '../Expected/AcceptanceTests/Url/autoRestUrlTestService';
import { AutoRestSwaggerBATFileService } from '../Expected/AcceptanceTests/BodyFile/autoRestSwaggerBATFileService';
import { AutoRestSwaggerBATArrayService } from '../Expected/AcceptanceTests/BodyArray/autoRestSwaggerBATArrayService';
import { AutoRestSwaggerBATdictionaryService, AutoRestSwaggerBATdictionaryServiceModels } from '../Expected/AcceptanceTests/BodyDictionary/autoRestSwaggerBATdictionaryService';
import { AutoRestHttpInfrastructureTestService } from '../Expected/AcceptanceTests/Http/autoRestHttpInfrastructureTestService';
import { AutoRestSwaggerBATFormDataService } from '../Expected/AcceptanceTests/BodyFormData/autoRestSwaggerBATFormDataService';
import { AutoRestParameterizedHostTestClient } from '../Expected/AcceptanceTests/CustomBaseUri/autoRestParameterizedHostTestClient';
import { AutoRestParameterizedCustomHostTestClient } from '../Expected/AcceptanceTests/CustomBaseUriMoreOptions/autoRestParameterizedCustomHostTestClient';
// TODO: Check types
var readStreamToBuffer = function (strm: stream.Readable, callback: (err: Error, result: Buffer) => void) {
var bufs: Buffer[] = [];
strm.on('data', function (d: Buffer) {
bufs.push(d);
});
strm.on('end', function () {
callback(null, Buffer.concat(bufs));
});
};
var readStreamCountBytes = function (stream: stream.Readable, callback: (err: Error, result: number) => void) {
var bytesRead = 0;
stream.on('data', function (d: Buffer) {
bytesRead = bytesRead + d.length;
});
stream.on('end', function () {
callback(null, bytesRead);
});
}
var clientOptions: msRest.ServiceClientOptions = {};
var baseUri = 'http://localhost:3000';
describe('typescript', function () {
describe('Swagger BAT', function () {
describe('Custom BaseUri Client', function () {
var customOptions = {
host: 'host:3000'
};
var testClient = new AutoRestParameterizedHostTestClient(customOptions);
it('should return 200', function (done) {
testClient.paths.getEmpty('local', function (error, result, request, response) {
should.not.exist(error);
response.status.should.equal(200);
done();
});
});
it('should throw due to bad "host", bad "account" and missing account', function (done) {
testClient.host = 'nonexistent';
testClient.paths.getEmpty('local', function (error, result, request, response) {
should.exist(error);
should.not.exist(result);
testClient.host = 'host:3000';
testClient.paths.getEmpty('bad', function (error, result, request, response) {
should.exist(error);
should.not.exist(result);
testClient.paths.getEmpty(null, function (error, result, request, response) {
should.exist(error);
should.not.exist(result);
done();
});
});
});
});
});
describe('Custom BaseUri Client with more options', function () {
var customOptions = {
dnsSuffix: 'host:3000'
};
var testClient = new AutoRestParameterizedCustomHostTestClient('test12', customOptions);
it('should return 200', function (done) {
testClient.paths.getEmpty('http://lo', 'cal', 'key1', function (error, result, request, response) {
should.not.exist(error);
response.status.should.equal(200);
done();
});
});
});
describe('Bool Client', function () {
var testClient = new AutoRestBoolTestService(baseUri, clientOptions);
it('should get valid boolean values', function (done) {
testClient.bool.getTrue(function (error, result) {
should.not.exist(error);
result.should.equal(true);
testClient.bool.getFalse(function (error, result) {
should.not.exist(error);
result.should.equal(false);
done();
});
});
});
it('should put valid boolean values', function (done) {
testClient.bool.putTrue(true, function (error, result) {
should.not.exist(error);
testClient.bool.putFalse(false, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should get null and invalid boolean value', function (done) {
testClient.bool.getNull(function (error, result) {
should.not.exist(result);
testClient.bool.getInvalid(function (error, result) {
should.exist(error);
should.not.exist(result);
done();
});
});
});
});
describe('Integer Client', function () {
var testClient = new AutoRestIntegerTestService(baseUri, clientOptions);
it('should put max value for 32 and 64 bit Integers', function (done) {
testClient.intModel.putMax32((Math.pow(2, 32 - 1) - 1), function (error, result) {
should.not.exist(error);
testClient.intModel.putMax64(9223372036854776000, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should put min value for 32 and 64 bit Integers', function (done) {
testClient.intModel.putMin32(-Math.pow(2, 32 - 1), function (error, result) {
should.not.exist(error);
testClient.intModel.putMin64(-9223372036854776000, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should get null and invalid integer value', function (done) {
testClient.intModel.getNull(function (error, result) {
should.not.exist(result);
testClient.intModel.getInvalid(function (error, result) {
should.exist(error);
should.not.exist(result);
done();
});
});
});
it('should get overflow and underflow for 32 bit integer value', function (done) {
testClient.intModel.getOverflowInt32(function (error, result) {
should.not.exist(error);
result.should.equal(2147483656);
testClient.intModel.getUnderflowInt32(function (error, result) {
should.not.exist(error);
result.should.equal(-2147483656);
done();
});
});
});
it('should get overflow and underflow for 64 bit integer value', function (done) {
testClient.intModel.getOverflowInt64(function (error, result) {
should.not.exist(error);
result.should.equal(9223372036854775910);
testClient.intModel.getUnderflowInt64(function (error, result) {
should.not.exist(error);
result.should.equal(-9223372036854775910);
done();
});
});
});
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 () {
var testClient = new CompositeBoolInt(baseUri, clientOptions);
it('should get valid boolean values', function (done) {
testClient.bool.getTrue(function (error, result) {
should.not.exist(error);
result.should.equal(true);
testClient.bool.getFalse(function (error, result) {
should.not.exist(error);
result.should.equal(false);
done();
});
});
});
it('should put valid boolean values', function (done) {
testClient.bool.putTrue(true, function (error, result) {
should.not.exist(error);
testClient.bool.putFalse(false, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should get null and invalid boolean value', function (done) {
testClient.bool.getNull(function (error, result) {
should.not.exist(result);
testClient.bool.getInvalid(function (error, result) {
should.exist(error);
should.not.exist(result);
done();
});
});
});
it('should put max value for 32 and 64 bit Integers', function (done) {
testClient.intModel.putMax32((Math.pow(2, 32 - 1) - 1), function (error, result) {
should.not.exist(error);
testClient.intModel.putMax64(9223372036854776000, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should put min value for 32 and 64 bit Integers', function (done) {
testClient.intModel.putMin32(-Math.pow(2, 32 - 1), function (error, result) {
should.not.exist(error);
testClient.intModel.putMin64(-9223372036854776000, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should get null and invalid integer value', function (done) {
testClient.intModel.getNull(function (error, result) {
should.not.exist(result);
testClient.intModel.getInvalid(function (error, result) {
should.exist(error);
should.not.exist(result);
done();
});
});
});
it('should get overflow and underflow for 32 bit integer value', function (done) {
testClient.intModel.getOverflowInt32(function (error, result) {
should.not.exist(error);
result.should.equal(2147483656);
testClient.intModel.getUnderflowInt32(function (error, result) {
should.not.exist(error);
result.should.equal(-2147483656);
done();
});
});
});
it('should get overflow and underflow for 64 bit integer value', function (done) {
testClient.intModel.getOverflowInt64(function (error, result) {
should.not.exist(error);
result.should.equal(9223372036854775910);
testClient.intModel.getUnderflowInt64(function (error, result) {
should.not.exist(error);
result.should.equal(-9223372036854775910);
done();
});
});
});
});
describe('Number Client', function () {
var testClient = new AutoRestNumberTestService(baseUri, clientOptions);
it('should put big float and double values', function (done) {
testClient.number.putBigFloat(3.402823e+20, function (error, result) {
should.not.exist(error);
testClient.number.putBigDouble(2.5976931e+101, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should get big float and double value', function (done) {
testClient.number.getBigFloat(function (error, result) {
should.not.exist(error);
result.should.equal(3.402823e+20);
testClient.number.getBigDouble(function (error, result) {
should.not.exist(error);
result.should.equal(2.5976931e+101);
done();
});
});
});
it('should put small float and double values', function (done) {
testClient.number.putSmallFloat(3.402823e-20, function (error, result) {
should.not.exist(error);
testClient.number.putSmallDouble(2.5976931e-101, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should get small float and double value', function (done) {
testClient.number.getSmallFloat(function (error, result) {
should.not.exist(error);
result.should.equal(3.402823e-20);
testClient.number.getSmallDouble(function (error, result) {
should.not.exist(error);
result.should.equal(2.5976931e-101);
done();
});
});
});
it('should put big positive and negative double value', function (done) {
testClient.number.putBigDoublePositiveDecimal(99999999.99, function (error, result) {
should.not.exist(error);
testClient.number.putBigDoubleNegativeDecimal(-99999999.99, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should get big positive and negative double value', function (done) {
testClient.number.getBigDoublePositiveDecimal(function (error, result) {
should.not.exist(error);
result.should.equal(99999999.99);
testClient.number.getBigDoubleNegativeDecimal(function (error, result) {
should.not.exist(error);
result.should.equal(-99999999.99);
done();
});
});
});
it('should get null and invalid float and double values', function (done) {
testClient.number.getNull(function (error, result) {
should.not.exist(result);
testClient.number.getInvalidFloat(function (error, result) {
should.exist(error);
should.not.exist(result);
testClient.number.getInvalidDouble(function (error, result) {
should.exist(error);
should.not.exist(result);
done();
});
});
});
});
});
describe('String Client', function () {
var testClient = new AutoRestSwaggerBATService(baseUri, clientOptions);
it('should support valid null value', function (done) {
testClient.string.getNull(function (error, result) {
should.not.exist(result);
testClient.string.putNull({ stringBody: AutoRestSwaggerBATServiceModels.StringBody.Null }, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should support valid empty string value', function (done) {
testClient.string.putEmpty(AutoRestSwaggerBATServiceModels.StringBody1.EmptyString, function (error, result) {
should.not.exist(error);
testClient.string.getEmpty(function (error, result) {
result.should.equal('');
done();
});
});
});
it('should support valid MBC string value', function (done) {
testClient.string.putMbcs(AutoRestSwaggerBATServiceModels.StringBody2.啊齄丂狛狜隣郎隣兀﨩ˊーぁんァヶΑАЯаяāɡㄅㄩɑɡ䜣, function (error, result) {
should.not.exist(error);
testClient.string.getMbcs(function (error, result) {
result.should.equal(AutoRestSwaggerBATServiceModels.GetMbcsOKResponse.啊齄丂狛狜隣郎隣兀﨩ˊーぁんァヶΑАЯаяāɡㄅㄩɑɡ䜣);
done();
});
});
});
it('should support whitespace string value', function (done) {
testClient.string.putWhitespace(AutoRestSwaggerBATServiceModels.StringBody3.Nowisthetimeforallgoodmentocometotheaidoftheircountry, function (error, result) {
should.not.exist(error);
testClient.string.getWhitespace(function (error, result) {
result.should.equal(AutoRestSwaggerBATServiceModels.GetWhitespaceOKResponse.Nowisthetimeforallgoodmentocometotheaidoftheircountry);
done();
});
});
});
it('should support not provided value', function (done) {
testClient.string.getNotProvided(function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
it('should support valid enum valid value', function (done) {
testClient.enumModel.getNotExpandable(function (error, result) {
should.not.exist(error);
result.should.equal(AutoRestSwaggerBATServiceModels.Colors.Redcolor);
testClient.enumModel.putNotExpandable(AutoRestSwaggerBATServiceModels.Colors.Redcolor, function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should correctly handle invalid values for enum', function (done) {
testClient.enumModel.putNotExpandable(<AutoRestSwaggerBATServiceModels.Colors>'orange color', function (error, result) {
should.exist(error);
error.message.should.match(/.*is not a valid value.*/ig);
done();
});
});
it('should correctly deserialize base64 encoded string', function (done) {
testClient.string.getBase64Encoded(function (error, result) {
should.not.exist(error);
should.exist(result);
result.toString('utf8').should.equal('a string that gets encoded with base64');
done();
});
});
it('should correctly handle null base64url encoded string', function (done) {
testClient.string.getNullBase64UrlEncoded(function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
it('should correctly serialize and deserialize base64url encoded string', function (done) {
testClient.string.getBase64UrlEncoded(function (error, result) {
should.not.exist(error);
should.exist(result);
result.toString('utf8').should.equal('a string that gets encoded with base64url');
var buff = new Buffer('a string that gets encoded with base64url', 'utf8');
testClient.string.putBase64UrlEncoded(buff, function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
});
});
describe('Byte Client', function () {
var testClient = new AutoRestSwaggerBATByteService(baseUri, clientOptions);
var bytes = new Buffer([255, 254, 253, 252, 251, 250, 249, 248, 247, 246]);
it('should support valid null and empty value', function (done) {
testClient.byteModel.getNull(function (error, result) {
should.not.exist(result);
should.not.exist(error);
testClient.byteModel.getEmpty(function (error, result) {
should.not.exist(error);
assert.deepEqual(result, new Buffer('', 'base64'));
done();
});
});
});
//TODO Client does not consider the string as invalid byte
it('should get invalid byte value', function (done) {
testClient.byteModel.getInvalid(function (error, result) {
should.not.exist(error);
assert.deepEqual(result, new Buffer(':::SWAGGER::::', 'base64'));
done();
});
});
it('should support valid non Ascii byte values', function (done) {
testClient.byteModel.putNonAscii(bytes, function (error, result) {
should.not.exist(error);
testClient.byteModel.getNonAscii(function (error, result) {
should.not.exist(error);
assert.deepEqual(result, bytes);
done();
});
});
});
});
describe('Date Client', function () {
var testClient = new AutoRestDateTestService(baseUri, clientOptions);
it('should get min and max date', function (done) {
testClient.dateModel.getMinDate(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(1);
date.getUTCMonth().should.equal(0);
date.getUTCDate().should.equal(1);
date.getUTCHours().should.equal(0);
date.getUTCMinutes().should.equal(0);
date.getUTCSeconds().should.equal(0);
date.getUTCMilliseconds().should.equal(0);
testClient.dateModel.getMaxDate(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(9999);
date.getUTCMonth().should.equal(11);
date.getUTCDate().should.equal(31);
date.getUTCHours().should.equal(0);
date.getUTCMinutes().should.equal(0);
date.getUTCSeconds().should.equal(0);
date.getUTCMilliseconds().should.equal(0);
done();
});
});
});
it('should properly handle underflow and overflow date', function (done) {
testClient.dateModel.getUnderflowDate(function (error, result) {
isNaN(result.valueOf()).should.equal(true);
should.not.exist(error);
testClient.dateModel.getOverflowDate(function (error, result) {
isNaN(result.valueOf()).should.equal(true);
should.not.exist(error);
done();
});
});
});
it('should properly handle null value for Date', function (done) {
testClient.dateModel.getNull(function (error, result) {
should.not.exist(result);
should.not.exist(error);
done();
});
});
it('should properly handle invalid Date value', function (done) {
testClient.dateModel.getInvalidDate(function (error, result) {
isNaN(result.valueOf()).should.equal(true);
should.not.exist(error);
done();
});
});
it('should put min and max date', function (done) {
testClient.dateModel.putMinDate(new Date('0001-01-01'), function (error, result) {
should.not.exist(error);
should.not.exist(result);
testClient.dateModel.putMaxDate(new Date('9999-12-31'), function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
});
});
describe('DateTime Client', function () {
var testClient = new AutoRestDateTimeTestService(baseUri, clientOptions);
it('should properly handle null value for DateTime', function (done) {
testClient.datetime.getNull(function (error, result) {
should.not.exist(result);
should.not.exist(error);
done();
});
});
it('should properly handle invalid dateTime value', function (done) {
testClient.datetime.getInvalid(function (error, result) {
isNaN(result.valueOf()).should.equal(true);
should.not.exist(error);
done();
});
});
it('should get uppercase and lowercase UTC max date time', function (done) {
testClient.datetime.getUtcUppercaseMaxDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(9999);
date.getUTCMonth().should.equal(11);
date.getUTCDate().should.equal(31);
date.getUTCHours().should.equal(23);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
date.getUTCMilliseconds().should.equal(999);
testClient.datetime.getUtcLowercaseMaxDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(9999);
date.getUTCMonth().should.equal(11);
date.getUTCDate().should.equal(31);
date.getUTCHours().should.equal(23);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
done();
});
});
});
it('should get UTC min dateTime value', function (done) {
testClient.datetime.getUtcMinDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(1);
date.getUTCMonth().should.equal(0);
date.getUTCDate().should.equal(1);
date.getUTCHours().should.equal(0);
date.getUTCMinutes().should.equal(0);
date.getUTCSeconds().should.equal(0);
date.getUTCMilliseconds().should.equal(0);
done();
});
});
it('should get local negative and positive offset Min DateTime value', function (done) {
testClient.datetime.getLocalNegativeOffsetMinDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(1);
date.getUTCMonth().should.equal(0);
date.getUTCDate().should.equal(1);
date.getUTCHours().should.equal(14);
date.getUTCMinutes().should.equal(0);
date.getUTCSeconds().should.equal(0);
date.getUTCMilliseconds().should.equal(0);
testClient.datetime.getLocalPositiveOffsetMinDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(0);
date.getUTCMonth().should.equal(11);
date.getUTCDate().should.equal(31);
date.getUTCHours().should.equal(10);
date.getUTCMinutes().should.equal(0);
date.getUTCSeconds().should.equal(0);
date.getUTCMilliseconds().should.equal(0);
done();
});
});
});
it('should get local negative offset lowercase and uppercase Max DateTime', function (done) {
testClient.datetime.getLocalNegativeOffsetLowercaseMaxDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
assert.deepEqual(result, new Date('9999-12-31t23:59:59.9999999-14:00'));
var date = result;
date.getUTCFullYear().should.equal(10000);
date.getUTCMonth().should.equal(0);
date.getUTCDate().should.equal(1);
date.getUTCHours().should.equal(13);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
date.getUTCMilliseconds().should.equal(999);
testClient.datetime.getLocalNegativeOffsetUppercaseMaxDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
assert.deepEqual(result, new Date('9999-12-31T23:59:59.9999999-14:00'));
var date = result;
date.getUTCFullYear().should.equal(10000);
date.getUTCMonth().should.equal(0);
date.getUTCDate().should.equal(1);
date.getUTCHours().should.equal(13);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
date.getUTCMilliseconds().should.equal(999);
done();
});
});
});
it('should get local positive offset lowercase and uppercase Max DateTime', function (done) {
testClient.datetime.getLocalPositiveOffsetLowercaseMaxDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
assert.deepEqual(result, new Date('9999-12-31t23:59:59.9999999+14:00'));
var date = result;
date.getUTCFullYear().should.equal(9999);
date.getUTCMonth().should.equal(11);
date.getUTCDate().should.equal(31);
date.getUTCHours().should.equal(9);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
date.getUTCMilliseconds().should.equal(999);
testClient.datetime.getLocalPositiveOffsetUppercaseMaxDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
assert.deepEqual(result, new Date('9999-12-31T23:59:59.9999999+14:00'));
var date = result;
date.getUTCFullYear().should.equal(9999);
date.getUTCMonth().should.equal(11);
date.getUTCDate().should.equal(31);
date.getUTCHours().should.equal(9);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
date.getUTCMilliseconds().should.equal(999);
done();
});
});
});
it('should get overflow and underflow', function (done) {
testClient.datetime.getOverflow(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(10000);
date.getUTCMonth().should.equal(0);
date.getUTCDate().should.equal(1);
date.getUTCHours().should.equal(13);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
date.getUTCMilliseconds().should.equal(999);
testClient.datetime.getUnderflow(function (error, result) {
isNaN(result.valueOf()).should.equal(true);
should.not.exist(error);
done();
});
});
});
it('should put UTC min and max date time', function (done) {
testClient.datetime.putUtcMinDateTime('0001-01-01T00:00:00Z', function (error, result) {
should.not.exist(error);
should.not.exist(result);
testClient.datetime.putUtcMaxDateTime('9999-12-31T23:59:59.9999999Z', function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
});
it('should put local negative and positive offset min DateTime', function (done) {
testClient.datetime.putLocalNegativeOffsetMinDateTime('0001-01-01T00:00:00-14:00', function (error, result) {
should.not.exist(error);
should.not.exist(result);
testClient.datetime.putLocalPositiveOffsetMinDateTime('0001-01-01T00:00:00+14:00', function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
});
it('should put local negative offset max DateTime', function (done) {
testClient.datetime.putLocalNegativeOffsetMaxDateTime('9999-12-31T23:59:59.9999999-14:00', function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
it('should put local positive offset max Date', function (done) {
testClient.datetime.putLocalPositiveOffsetMaxDateTime('9999-12-31t23:59:59.9999999+14:00', function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
});
describe('DateTimeRfc1123 Client', function () {
var testClient = new AutoRestRFC1123DateTimeTestService(baseUri, clientOptions);
it('should properly handle null value for DateTimeRfc1123', function (done) {
testClient.datetimerfc1123.getNull(function (error, result) {
should.not.exist(result);
should.not.exist(error);
done();
});
});
it('should properly handle invalid dateTimeRfc1123 value', function (done) {
testClient.datetimerfc1123.getInvalid(function (error, result) {
isNaN(result.valueOf()).should.equal(true);
should.not.exist(error);
done();
});
});
it('should get uppercase and lowercase UTC max date time dateTimeRfc1123', function (done) {
testClient.datetimerfc1123.getUtcUppercaseMaxDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(9999);
date.getUTCMonth().should.equal(11);
date.getUTCDate().should.equal(31);
date.getUTCHours().should.equal(23);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
testClient.datetimerfc1123.getUtcLowercaseMaxDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(9999);
date.getUTCMonth().should.equal(11);
date.getUTCDate().should.equal(31);
date.getUTCHours().should.equal(23);
date.getUTCMinutes().should.equal(59);
date.getUTCSeconds().should.equal(59);
done();
});
});
});
it('should get UTC min dateTimeRfc1123 value', function (done) {
testClient.datetimerfc1123.getUtcMinDateTime(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
done();
//TODO: NodeJS doesn't deserialize this time correctly
var dateFormat = 'ddd, DD MMM YYYY HH:mm:ss';
var myMoment = moment.utc('Mon, 01 Jan 0001 00:00:00 GMT', dateFormat);
should.not.exist(myMoment.toDate().toUTCString());
date.getUTCFullYear().should.equal(1);
date.getUTCMonth().should.equal(0);
date.getUTCDate().should.equal(1);
date.getUTCHours().should.equal(0);
date.getUTCMinutes().should.equal(0);
date.getUTCSeconds().should.equal(0);
date.getUTCMilliseconds().should.equal(0);
done();
});
});
it('should get overflow and underflow', function (done) {
testClient.datetimerfc1123.getOverflow(function (error, result) {
should.not.exist(error);
should.exist(result);
var date = result;
date.getUTCFullYear().should.equal(10000);
date.getUTCMonth().should.equal(0);
date.getUTCDate().should.equal(1);
date.getUTCHours().should.equal(0);
date.getUTCMinutes().should.equal(0);
date.getUTCSeconds().should.equal(0);
testClient.datetimerfc1123.getUnderflow(function (error, result) {
isNaN(result.valueOf()).should.equal(true);
should.not.exist(error);
done();
});
});
});
it('should put UTC min and max dateTimeRfc1123', function (done) {
testClient.datetimerfc1123.putUtcMinDateTime(new Date('Mon, 01 Jan 0001 00:00:00 GMT'), function (error, result) {
should.not.exist(error);
should.not.exist(result);
testClient.datetimerfc1123.putUtcMaxDateTime(new Date('Fri, 31 Dec 9999 23:59:59 GMT'), function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
});
});
describe('Duration Client', function () {
var testClient = new AutoRestDurationTestService(baseUri, clientOptions);
it('should properly handle null value for Duration', function (done) {
testClient.duration.getNull(function (error, result) {
should.not.exist(result);
should.not.exist(error);
done();
});
});
it('should properly handle invalid value for Duration', function (done) {
testClient.duration.getInvalid(function (error, result) {
//For some reason moment.js allows non-ISO strings and will just construct a duration of length 0, so we don't expect an error here, but the result
//should be duration of length 0
should.not.exist(error);
should.equal(result.asSeconds(), 0);
done();
});
});
it('should properly handle positive value for Duration', function (done) {
testClient.duration.getPositiveDuration(function (error, result) {
should.exist(result);
should.not.exist(error);
should.equal(result.asSeconds(), moment.duration('P3Y6M4DT12H30M5S').asSeconds());
done();
});
});
it('should properly put positive value for Duration', function (done) {
var duration = moment.duration({ days: 123, hours: 22, minutes: 14, seconds: 12, milliseconds: 11 });
testClient.duration.putPositiveDuration(duration, function (error, result) {
should.not.exist(error);
should.not.exist(result);
done();
});
});
});
describe('Array Client', function () {
describe('for primitive types', function () {
var testClient = new AutoRestSwaggerBATArrayService(baseUri, clientOptions);
it('should get and put empty arrays', function (done) {
testClient.arrayModel.getEmpty(function (error, result) {
should.not.exist(error);
assert.deepEqual(result, []);
testClient.arrayModel.putEmpty([], function (error, result) {
should.not.exist(error);
done();
});
});
});
it('should handle null and invalid value for arrays', function (done) {
testClient.arrayModel.getNull(function (error, result) {
should.not.exist(error);
assert.equal(result, null);
testClient.arrayModel.getInvalid(function (error, result) {
should.exist(error);
should.not.exist(result);
done();
});
});
});
it('should get base64url arrays', function (done) {
var base64Url1 = new Buffer('a string that gets encoded with base64url', 'utf8');
var base64Url2 = new Buffer('test string', 'utf8');
var base64Url3 = new Buffer('Lorem ipsum', 'utf8');
var arr = [base64Url1, base64Url2, base64Url3];
testClient.arrayModel.getBase64Url(function (error, result) {
should.not.exist(error);
should.exist(result);
assert.deepEqual(result, arr);
done();
});
});
it('should get and put boolean arrays', function (done) {
var boolArray = [true, false, false, true];
testClient.arrayModel.getBooleanTfft(function (error, result) {
should.not.exist(error);
assert.deepEqual(result, boolArray);
testClient.arrayModel.putBooleanTfft(boolArray, function (error, result) {
should.not.exist(error);
testClient.arrayModel.getBooleanInvalidNull(function (error, result) {
should.not.exist(error);
assert.deepEqual(result, [true, null, false]);