forked from Azure/autorest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAcceptanceTests.cs
2506 lines (2347 loc) · 130 KB
/
AcceptanceTests.cs
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.
//
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AutoRest.CSharp.Tests.Utilities;
using Fixtures.AcceptanceTestsBodyArray;
using Fixtures.AcceptanceTestsBodyBoolean;
using Fixtures.AcceptanceTestsBodyByte;
using Fixtures.AcceptanceTestsBodyComplex;
using Fixtures.AcceptanceTestsBodyComplex.Models;
using Fixtures.AcceptanceTestsBodyDate;
using Fixtures.AcceptanceTestsBodyDateTime;
using Fixtures.AcceptanceTestsBodyDateTimeRfc1123;
using Fixtures.AcceptanceTestsBodyDictionary;
using Fixtures.AcceptanceTestsBodyDictionary.Models;
using Fixtures.AcceptanceTestsBodyDuration;
using Fixtures.AcceptanceTestsBodyFile;
using Fixtures.AcceptanceTestsBodyFormData;
using Fixtures.AcceptanceTestsBodyInteger;
using Fixtures.AcceptanceTestsBodyNumber;
using Fixtures.AcceptanceTestsBodyString;
using Fixtures.AcceptanceTestsBodyString.Models;
using Fixtures.AcceptanceTestsCompositeBoolIntClient;
using Fixtures.AcceptanceTestsCustomBaseUri;
using Fixtures.AcceptanceTestsCustomBaseUriMoreOptions;
using Fixtures.AcceptanceTestsHeader;
using Fixtures.AcceptanceTestsHeader.Models;
using Fixtures.AcceptanceTestsHttp;
using Fixtures.AcceptanceTestsHttp.Models;
using Fixtures.AcceptanceTestsModelFlattening;
using Fixtures.AcceptanceTestsModelFlattening.Models;
using Fixtures.AcceptanceTestsReport;
using Fixtures.AcceptanceTestsRequiredOptional;
using Fixtures.AcceptanceTestsUrl;
using Fixtures.AcceptanceTestsUrl.Models;
using Fixtures.AcceptanceTestsUrlMultiCollectionFormat;
using Fixtures.AcceptanceTestsValidation;
using Fixtures.AcceptanceTestsValidation.Models;
using Fixtures.InternalCtors;
using Fixtures.PetstoreV2;
using Microsoft.Extensions.Logging;
using Microsoft.Rest;
using Microsoft.Rest.Serialization;
using Newtonsoft.Json;
using Xunit;
using Error = Fixtures.AcceptanceTestsHttp.Models.Error;
using ErrorException = Fixtures.AcceptanceTestsHttp.Models.ErrorException;
using SwaggerPetstoreV2Extensions = Fixtures.PetstoreV2AllSync.SwaggerPetstoreV2Extensions;
using System.Net.Http.Headers;
using System.Reflection;
namespace AutoRest.CSharp.Tests
{
[Collection("AutoRest Tests")]
[TestCaseOrderer("AutoRest.CSharp.Tests.AcceptanceTestOrderer",
"AutoRest.Generator.CSharp.Tests")]
public class AcceptanceTests : IClassFixture<ServiceController>, IDisposable
{
private static readonly TestTracingInterceptor _interceptor;
private readonly string dummyFile;
static AcceptanceTests()
{
_interceptor = new TestTracingInterceptor();
ServiceClientTracing.AddTracingInterceptor(_interceptor);
}
public AcceptanceTests(ServiceController data)
{
Fixture = data;
Fixture.TearDown = EnsureTestCoverage;
ServiceClientTracing.IsEnabled = false;
dummyFile = Path.GetTempFileName();
File.WriteAllText(dummyFile, "Test file");
}
public ServiceController Fixture { get; set; }
private static string ExpectedPath(string file)
{
return Path.Combine("Expected", "AcceptanceTests", file);
}
private static string SwaggerPath(string file)
{
return Path.Combine("Swagger", file);
}
[Fact]
public void ValidationTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("validation.json"),
ExpectedPath("Validation"));
var client = new AutoRestValidationTest(Fixture.Uri);
client.SubscriptionId = "abc123";
client.ApiVersion = "12-34-5678";
var exception = Assert.Throws<ValidationException>(() => client.ValidationOfMethodParameters("1", 100));
Assert.Equal(ValidationRules.MinLength, exception.Rule);
Assert.Equal("resourceGroupName", exception.Target);
exception = Assert.Throws<ValidationException>(() => client.ValidationOfMethodParameters("1234567890A", 100));
Assert.Equal(ValidationRules.MaxLength, exception.Rule);
Assert.Equal("resourceGroupName", exception.Target);
exception = Assert.Throws<ValidationException>(() => client.ValidationOfMethodParameters("!@#$", 100));
Assert.Equal(ValidationRules.Pattern, exception.Rule);
Assert.Equal("resourceGroupName", exception.Target);
exception = Assert.Throws<ValidationException>(() => client.ValidationOfMethodParameters("123", 105));
Assert.Equal(ValidationRules.MultipleOf, exception.Rule);
Assert.Equal("id", exception.Target);
exception = Assert.Throws<ValidationException>(() => client.ValidationOfMethodParameters("123", 0));
Assert.Equal(ValidationRules.InclusiveMinimum, exception.Rule);
Assert.Equal("id", exception.Target);
exception = Assert.Throws<ValidationException>(() => client.ValidationOfMethodParameters("123", 2000));
Assert.Equal(ValidationRules.InclusiveMaximum, exception.Rule);
Assert.Equal("id", exception.Target);
exception = Assert.Throws<ValidationException>(() => client.ValidationOfBody("123", 150, new Product
{
Capacity = 0
}));
Assert.Equal(ValidationRules.ExclusiveMinimum, exception.Rule);
Assert.Equal("Capacity", exception.Target);
exception = Assert.Throws<ValidationException>(() => client.ValidationOfBody("123", 150, new Product
{
Capacity = 100
}));
Assert.Equal(ValidationRules.ExclusiveMaximum, exception.Rule);
Assert.Equal("Capacity", exception.Target);
exception = Assert.Throws<ValidationException>(() => client.ValidationOfBody("123", 150, new Product
{
DisplayNames = new List<string>
{
"item1",
"item2",
"item3",
"item4",
"item5",
"item6",
"item7"
}
}));
Assert.Equal(ValidationRules.MaxItems, exception.Rule);
Assert.Equal("DisplayNames", exception.Target);
var client2 = new AutoRestValidationTest(Fixture.Uri);
client2.SubscriptionId = "abc123";
client2.ApiVersion = "abc";
exception = Assert.Throws<ValidationException>(() => client2.ValidationOfMethodParameters("123", 150));
Assert.Equal(ValidationRules.Pattern, exception.Rule);
Assert.Equal("ApiVersion", exception.Target);
}
[Fact]
public void ConstantValuesTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("validation.json"),
ExpectedPath("Validation"));
var client = new AutoRestValidationTest(Fixture.Uri);
client.SubscriptionId = "abc123";
client.ApiVersion = "12-34-5678";
client.GetWithConstantInPath();
var product = client.PostWithConstantInBody(new Product());
Assert.NotNull(product);
}
[Fact]
public void ConstructorWithCredentialsTests()
{
var client = new SwaggerPetstoreV2(new TokenCredentials("123"));
client.Dispose();
}
[Fact]
public void BoolTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-boolean.json"),
ExpectedPath("BodyBoolean"));
var client = new AutoRestBoolTestService(Fixture.Uri);
Assert.False(client.BoolModel.GetFalse());
Assert.True(client.BoolModel.GetTrue());
client.BoolModel.PutTrue(true);
client.BoolModel.PutFalse(false);
client.BoolModel.GetNull();
Assert.Throws<SerializationException>(() => client.BoolModel.GetInvalid());
}
[Fact]
public void IntegerTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-integer.json"),
ExpectedPath("BodyInteger"));
var client = new AutoRestIntegerTestService(Fixture.Uri);
client.IntModel.PutMax32(int.MaxValue);
client.IntModel.PutMin32(int.MinValue);
client.IntModel.PutMax64(long.MaxValue);
client.IntModel.PutMin64(long.MinValue);
client.IntModel.PutUnixTimeDate(new DateTime(2016, 4, 13, 0, 0, 0));
client.IntModel.GetNull();
Assert.Throws<SerializationException>(() => client.IntModel.GetInvalid());
Assert.Throws<SerializationException>(() => client.IntModel.GetOverflowInt32());
Assert.Throws<SerializationException>(() => client.IntModel.GetOverflowInt64());
Assert.Throws<SerializationException>(() => client.IntModel.GetUnderflowInt32());
Assert.Throws<SerializationException>(() => client.IntModel.GetUnderflowInt64());
Assert.Throws<SerializationException>(() => client.IntModel.GetInvalidUnixTime());
Assert.Null(client.IntModel.GetNullUnixTime());
Assert.Equal(new DateTime(2016, 4, 13, 0, 0, 0), client.IntModel.GetUnixTime());
}
[Fact]
public void CompositeBoolIntTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("composite-swagger.json"),
ExpectedPath("CompositeBoolIntClient"));
var client = new CompositeBoolInt(Fixture.Uri);
Assert.False(client.BoolModel.GetFalse());
Assert.True(client.BoolModel.GetTrue());
client.BoolModel.PutTrue(true);
client.BoolModel.PutFalse(false);
client.BoolModel.GetNull();
Assert.Throws<SerializationException>(() => client.BoolModel.GetInvalid());
client.IntModel.PutMax32(int.MaxValue);
client.IntModel.PutMin32(int.MinValue);
client.IntModel.PutMax64(long.MaxValue);
client.IntModel.PutMin64(long.MinValue);
client.IntModel.GetNull();
Assert.Throws<SerializationException>(() => client.IntModel.GetInvalid());
Assert.Throws<SerializationException>(() => client.IntModel.GetOverflowInt32());
Assert.Throws<SerializationException>(() => client.IntModel.GetOverflowInt64());
Assert.Throws<SerializationException>(() => client.IntModel.GetUnderflowInt32());
Assert.Throws<SerializationException>(() => client.IntModel.GetUnderflowInt64());
}
[Fact]
public void NumberTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-number.json"), ExpectedPath("BodyNumber"));
var client = new AutoRestNumberTestService(Fixture.Uri);
client.Number.PutBigFloat(3.402823e+20);
client.Number.PutSmallFloat(3.402823e-20);
client.Number.PutBigDouble(2.5976931e+101);
client.Number.PutSmallDouble(2.5976931e-101);
client.Number.PutBigDoubleNegativeDecimal(-99999999.99);
client.Number.PutBigDoublePositiveDecimal(99999999.99);
client.Number.GetNull();
Assert.Equal(3.402823e+20, client.Number.GetBigFloat());
Assert.Equal(3.402823e-20, client.Number.GetSmallFloat());
Assert.Equal(2.5976931e+101, client.Number.GetBigDouble());
Assert.Equal(2.5976931e-101, client.Number.GetSmallDouble());
Assert.Equal(-99999999.99, client.Number.GetBigDoubleNegativeDecimal());
Assert.Equal(99999999.99, client.Number.GetBigDoublePositiveDecimal());
Assert.Throws<SerializationException>(() => client.Number.GetInvalidDouble());
Assert.Throws<SerializationException>(() => client.Number.GetInvalidFloat());
}
[Fact]
public void StringTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-string.json"), ExpectedPath("BodyString"));
using (var client = new AutoRestSwaggerBATService(Fixture.Uri))
{
Assert.Null(client.StringModel.GetNull());
client.StringModel.PutNull(null);
Assert.Equal(string.Empty, client.StringModel.GetEmpty());
client.StringModel.PutEmpty("");
Assert.Equal("啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€",
client.StringModel.GetMbcs());
client.StringModel.PutMbcs("啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€");
Assert.Equal(" Now is the time for all good men to come to the aid of their country ",
client.StringModel.GetWhitespace());
client.StringModel.PutWhitespace(
" Now is the time for all good men to come to the aid of their country ");
Assert.Null(client.StringModel.GetNotProvided());
Assert.Equal(Colors.Redcolor, client.EnumModel.GetNotExpandable());
client.EnumModel.PutNotExpandable(Colors.Redcolor);
Assert.Equal(Colors.Redcolor, client.EnumModel.GetReferenced());
client.EnumModel.PutReferenced(Colors.Redcolor);
Assert.Equal(RefColorConstant.ColorConstant, "green-color");
Assert.Equal("Sample String", client.EnumModel.GetReferencedConstant().Field1);
client.EnumModel.PutReferencedConstant();
var base64UrlEncodedString = client.StringModel.GetBase64UrlEncoded();
var base64EncodedString = client.StringModel.GetBase64Encoded();
Assert.Equal(Encoding.UTF8.GetString(base64UrlEncodedString),
"a string that gets encoded with base64url");
Assert.Equal(Encoding.UTF8.GetString(base64EncodedString), "a string that gets encoded with base64");
Assert.Null(client.StringModel.GetNullBase64UrlEncoded());
client.StringModel.PutBase64UrlEncoded(
Encoding.UTF8.GetBytes("a string that gets encoded with base64url"));
}
}
[Fact]
public void ByteTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-byte.json"), ExpectedPath("BodyByte"));
using (var client = new AutoRestSwaggerBATByteService(Fixture.Uri))
{
var bytes = new byte[] {0x0FF, 0x0FE, 0x0FD, 0x0FC, 0x0FB, 0x0FA, 0x0F9, 0x0F8, 0x0F7, 0x0F6};
client.ByteModel.PutNonAscii(bytes);
Assert.Equal(bytes, client.ByteModel.GetNonAscii());
Assert.Null(client.ByteModel.GetNull());
Assert.Empty(client.ByteModel.GetEmpty());
Assert.Throws<FormatException>(() => client.ByteModel.GetInvalid());
}
}
[Fact]
public void FileTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-file.json"), ExpectedPath("BodyFile"));
using (var client = new AutoRestSwaggerBATFileService(Fixture.Uri))
{
using (var stream = client.Files.GetFile())
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
Assert.Equal(8725, ms.Length);
}
using (var emptyStream = client.Files.GetEmptyFile())
using (var ms = new MemoryStream())
{
emptyStream.CopyTo(ms);
Assert.Equal(0, ms.Length);
}
using (var largeFileStream = client.Files.GetFileLarge())
{
//Read the stream into memory a bit at a time to avoid OOM
var bytesRead = 0;
long totalBytesRead = 0;
var buffer = new byte[1024*1024];
while ((bytesRead = largeFileStream.Read(buffer, 0, buffer.Length)) > 0)
{
totalBytesRead += bytesRead;
}
Assert.Equal(3000L*1024*1024, totalBytesRead);
}
}
}
[Fact(Skip = "Travis: Cannot access a closed Stream.")]
public void FormDataFileUploadStreamTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-formdata.json"), ExpectedPath("BodyFormData"));
using (var client = new AutoRestSwaggerBATFormDataService(Fixture.Uri))
{
const string testString = "Upload file test case";
var testBytes = new UnicodeEncoding().GetBytes(testString);
using (Stream memStream = new MemoryStream(100))
{
memStream.Write(testBytes, 0, testBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
using (
var reader = new StreamReader(client.Formdata.UploadFile(memStream, "UploadFile.txt"),
Encoding.Unicode))
{
var actual = reader.ReadToEnd();
Assert.Equal(testString, actual);
}
}
}
}
[Fact(Skip = "Travis: Cannot access a closed Stream.")]
public void FormDataFileUploadFileStreamTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-formdata.json"), ExpectedPath("BodyFormData"));
using (var client = new AutoRestSwaggerBATFormDataService(Fixture.Uri))
{
var testString = "Upload file test case";
var testBytes = new UnicodeEncoding().GetBytes(testString);
using (var fileStream = File.OpenRead(dummyFile))
using (var serverStream = new StreamReader(client.Formdata.UploadFile(fileStream, dummyFile)))
{
Assert.Equal(File.ReadAllText(dummyFile), serverStream.ReadToEnd());
}
}
}
[Fact]
public void BodyFileUploadTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-formdata.json"), ExpectedPath("BodyFormData"));
using (var client = new AutoRestSwaggerBATFormDataService(Fixture.Uri))
{
const string testString = "Upload file test case";
var testBytes = new UnicodeEncoding().GetBytes(testString);
using (Stream memStream = new MemoryStream(100))
{
memStream.Write(testBytes, 0, testBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
using (var reader = new StreamReader(client.Formdata.UploadFileViaBody(memStream), Encoding.Unicode)
)
{
var actual = reader.ReadToEnd();
Assert.Equal(testString, actual);
}
}
}
}
[Fact]
public void DateTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-date.json"), ExpectedPath("BodyDate"));
using (var client = new AutoRestDateTestService(Fixture.Uri))
{
//We need to configure the Json.net serializer to only send date on the wire. This can be done
//by setting the {DateFormatString = "yyyy-MM-dd"} of the serializer. The tricky part is to
//do this only for parameters/properties of format "date" but not "date-time".
client.Date.PutMaxDate(DateTime.MaxValue);
client.Date.PutMinDate(DateTime.MinValue);
client.Date.GetMaxDate();
client.Date.GetMinDate();
client.Date.GetNull();
Assert.Throws<SerializationException>(() => client.Date.GetInvalidDate());
Assert.Throws<SerializationException>(() => client.Date.GetOverflowDate());
Assert.Throws<SerializationException>(() => client.Date.GetUnderflowDate());
}
}
[Fact]
public void DateTimeTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-datetime.json"), ExpectedPath("BodyDateTime"));
using (var client = new AutoRestDateTimeTestService(Fixture.Uri))
{
client.Datetime.GetUtcLowercaseMaxDateTime();
client.Datetime.GetUtcUppercaseMaxDateTime();
client.Datetime.GetUtcMinDateTime();
client.Datetime.GetLocalNegativeOffsetMinDateTime();
//overflow-for-dotnet
Assert.Throws<SerializationException>(() => client.Datetime.GetLocalNegativeOffsetLowercaseMaxDateTime());
client.Datetime.GetLocalNegativeOffsetUppercaseMaxDateTime();
//underflow-for-dotnet
client.Datetime.GetLocalPositiveOffsetMinDateTime();
client.Datetime.GetLocalPositiveOffsetLowercaseMaxDateTime();
client.Datetime.GetLocalPositiveOffsetUppercaseMaxDateTime();
client.Datetime.GetNull();
client.Datetime.GetOverflow();
Assert.Throws<SerializationException>(() => client.Datetime.GetInvalid());
Assert.Throws<SerializationException>(() => client.Datetime.GetUnderflow());
//The following two calls fail as datetimeoffset are always sent as local time i.e (+00:00) and not Z
client.Datetime.PutUtcMaxDateTime(DateTime.MaxValue.ToUniversalTime());
client.Datetime.PutUtcMinDateTime(DateTime.Parse("0001-01-01T00:00:00Z",
CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal));
//underflow-for-dotnet
client.Datetime.PutLocalPositiveOffsetMinDateTime(DateTime.Parse("0001-01-01T00:00:00+14:00",
CultureInfo.InvariantCulture));
client.Datetime.PutLocalNegativeOffsetMinDateTime(DateTime.Parse("0001-01-01T00:00:00-14:00",
CultureInfo.InvariantCulture));
//overflow-for-dotnet
Assert.Throws<FormatException>(
() =>
client.Datetime.PutLocalNegativeOffsetMaxDateTime(
DateTime.Parse("9999-12-31T23:59:59.9999999-14:00",
CultureInfo.InvariantCulture)));
}
}
[Fact]
public void DateTimeRfc1123Tests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-datetime-rfc1123.json"), ExpectedPath("BodyDateTimeRfc1123"));
using (var client = new AutoRestRFC1123DateTimeTestService(Fixture.Uri))
{
Assert.Null(client.Datetimerfc1123.GetNull());
Assert.Throws<SerializationException>(() => client.Datetimerfc1123.GetInvalid());
Assert.Throws<SerializationException>(() => client.Datetimerfc1123.GetUnderflow());
Assert.Throws<SerializationException>(() => client.Datetimerfc1123.GetOverflow());
var d = client.Datetimerfc1123.GetUtcLowercaseMaxDateTime();
Assert.Equal(DateTimeKind.Utc, d.Value.Kind);
client.Datetimerfc1123.GetUtcUppercaseMaxDateTime();
client.Datetimerfc1123.GetUtcMinDateTime();
client.Datetimerfc1123.PutUtcMaxDateTime(DateTime.MaxValue.ToUniversalTime());
client.Datetimerfc1123.PutUtcMinDateTime(DateTime.Parse("0001-01-01T00:00:00Z",
CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal));
}
}
[Fact]
public void DurationTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-duration.json"), ExpectedPath("BodyDuration"));
using (var client = new AutoRestDurationTestService(Fixture.Uri))
{
Assert.Null(client.Duration.GetNull());
Assert.Throws<FormatException>(() => client.Duration.GetInvalid());
client.Duration.GetPositiveDuration();
client.Duration.PutPositiveDuration(new TimeSpan(123, 22, 14, 12, 11));
}
}
[Fact]
public void ArrayTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-array.json"), ExpectedPath("BodyArray"));
using (var client =
new AutoRestSwaggerBATArrayService(Fixture.Uri))
{
Assert.Empty(client.Array.GetEmpty());
Assert.Null(client.Array.GetNull());
client.Array.PutEmpty(new List<string>());
Assert.True(new List<bool?> {true, false, false, true}.SequenceEqual(client.Array.GetBooleanTfft()));
client.Array.PutBooleanTfft(new List<bool?> {true, false, false, true});
Assert.True(new List<int?> {1, -1, 3, 300}.SequenceEqual(client.Array.GetIntegerValid()));
client.Array.PutIntegerValid(new List<int?> {1, -1, 3, 300});
Assert.True(new List<long?> {1L, -1, 3, 300}.SequenceEqual(client.Array.GetLongValid()));
client.Array.PutLongValid(new List<long?> {1, -1, 3, 300});
Assert.True(new List<double?> {0, -0.01, -1.2e20}.SequenceEqual(client.Array.GetFloatValid()));
client.Array.PutFloatValid(new List<double?> {0, -0.01, -1.2e20});
Assert.True(new List<double?> {0, -0.01, -1.2e20}.SequenceEqual(client.Array.GetDoubleValid()));
client.Array.PutDoubleValid(new List<double?> {0, -0.01, -1.2e20});
Assert.True(new List<string> {"foo1", "foo2", "foo3"}.SequenceEqual(client.Array.GetStringValid()));
client.Array.PutStringValid(new List<string> {"foo1", "foo2", "foo3"});
Assert.True(new List<string> {"foo", null, "foo2"}.SequenceEqual(client.Array.GetStringWithNull()));
Assert.True(new List<string> {"foo", "123", "foo2"}.SequenceEqual(client.Array.GetStringWithInvalid()));
var date1 = new DateTimeOffset(2000, 12, 01, 0, 0, 0, TimeSpan.Zero).UtcDateTime;
var date2 = new DateTimeOffset(1980, 1, 2, 0, 0, 0, TimeSpan.Zero).UtcDateTime;
var date3 = new DateTimeOffset(1492, 10, 12, 0, 0, 0, TimeSpan.Zero).UtcDateTime;
var datetime1 = new DateTimeOffset(2000, 12, 01, 0, 0, 1, TimeSpan.Zero).UtcDateTime;
var datetime2 = new DateTimeOffset(1980, 1, 2, 0, 11, 35, TimeSpan.Zero).UtcDateTime;
var datetime3 = new DateTimeOffset(1492, 10, 12, 10, 15, 1, TimeSpan.Zero).UtcDateTime;
var dateArray = client.Array.GetDateValid();
var duration1 = new TimeSpan(123, 22, 14, 12, 11);
var duration2 = new TimeSpan(5, 1, 0, 0, 0);
Assert.Equal(new List<DateTime?> {date1, date2, date3}, dateArray);
client.Array.PutDateValid(new List<DateTime?> {date1, date2, date3});
Assert.Equal(
new List<DateTime?> {datetime1, datetime2, datetime3}, client.Array.GetDateTimeValid());
client.Array.PutDateTimeValid(new List<DateTime?> {datetime1, datetime2, datetime3});
dateArray = client.Array.GetDateTimeRfc1123Valid();
Assert.Equal(new List<DateTime?> {datetime1, datetime2, datetime3}, dateArray);
client.Array.PutDateTimeRfc1123Valid(dateArray);
Assert.Equal(new List<TimeSpan?> {duration1, duration2}, client.Array.GetDurationValid());
client.Array.PutDurationValid(new List<TimeSpan?> {duration1, duration2});
var bytes1 = new byte[] {0x0FF, 0x0FF, 0x0FF, 0x0FA};
var bytes2 = new byte[] {0x01, 0x02, 0x03};
var bytes3 = new byte[] {0x025, 0x029, 0x043};
var bytes4 = new byte[] {0x0AB, 0x0AC, 0x0AD};
client.Array.PutByteValid(new List<byte[]> {bytes1, bytes2, bytes3});
var bytesResult = client.Array.GetByteValid();
Assert.True(new List<byte[]> {bytes1, bytes2, bytes3}.SequenceEqual(bytesResult,
new ByteArrayEqualityComparer()));
bytesResult = client.Array.GetByteInvalidNull();
Assert.True(new List<byte[]> {bytes4, null}.SequenceEqual(bytesResult, new ByteArrayEqualityComparer()));
var testProduct1 = new Fixtures.AcceptanceTestsBodyArray.Models.Product
{
Integer = 1,
StringProperty = "2"
};
var testProduct2 = new Fixtures.AcceptanceTestsBodyArray.Models.Product
{
Integer = 3,
StringProperty = "4"
};
var testProduct3 = new Fixtures.AcceptanceTestsBodyArray.Models.Product
{
Integer = 5,
StringProperty = "6"
};
var testList1 = new List<Fixtures.AcceptanceTestsBodyArray.Models.Product>
{
testProduct1,
testProduct2,
testProduct3
};
Assert.Null(client.Array.GetComplexNull());
Assert.Empty(client.Array.GetComplexEmpty());
client.Array.PutComplexValid(testList1);
Assert.True(testList1.SequenceEqual(client.Array.GetComplexValid(), new ProductEqualityComparer()));
var listList = new List<IList<string>>
{
new List<string> {"1", "2", "3"},
new List<string> {"4", "5", "6"},
new List<string> {"7", "8", "9"}
};
client.Array.PutArrayValid(listList);
Assert.True(listList.SequenceEqual(client.Array.GetArrayValid(), new ListEqualityComparer<string>()));
var listDictionary = new List<IDictionary<string, string>>
{
new Dictionary<string, string> {{"1", "one"}, {"2", "two"}, {"3", "three"}},
new Dictionary<string, string> {{"4", "four"}, {"5", "five"}, {"6", "six"}},
new Dictionary<string, string> {{"7", "seven"}, {"8", "eight"}, {"9", "nine"}}
};
client.Array.PutDictionaryValid(listDictionary);
Assert.True(listDictionary.SequenceEqual(client.Array.GetDictionaryValid(),
new DictionaryEqualityComparer<string>()));
Assert.Null(client.Array.GetComplexNull());
Assert.Empty(client.Array.GetComplexEmpty());
var productList2 = new List<Fixtures.AcceptanceTestsBodyArray.Models.Product>
{
testProduct1,
null,
testProduct3
};
Assert.True(productList2.SequenceEqual(client.Array.GetComplexItemNull(), new ProductEqualityComparer()));
var productList3 = new List<Fixtures.AcceptanceTestsBodyArray.Models.Product>
{
testProduct1,
new Fixtures.AcceptanceTestsBodyArray.Models.Product(),
testProduct3
};
var emptyComplex = client.Array.GetComplexItemEmpty();
Assert.True(productList3.SequenceEqual(emptyComplex, new ProductEqualityComparer()));
Assert.Null(client.Array.GetArrayNull());
Assert.Empty(client.Array.GetArrayEmpty());
var listList2 = new List<List<string>>
{
new List<string> {"1", "2", "3"},
null,
new List<string> {"7", "8", "9"}
};
Assert.True(listList2.SequenceEqual(client.Array.GetArrayItemNull(), new ListEqualityComparer<string>()));
var listList3 = new List<List<string>>
{
new List<string> {"1", "2", "3"},
new List<string>(0),
new List<string> {"7", "8", "9"}
};
Assert.True(listList3.SequenceEqual(client.Array.GetArrayItemEmpty(), new ListEqualityComparer<string>()));
Assert.Null(client.Array.GetDictionaryNull());
Assert.Empty(client.Array.GetDictionaryEmpty());
var listDictionary2 = new List<Dictionary<string, string>>
{
new Dictionary<string, string> {{"1", "one"}, {"2", "two"}, {"3", "three"}},
null,
new Dictionary<string, string> {{"7", "seven"}, {"8", "eight"}, {"9", "nine"}}
};
Assert.True(listDictionary2.SequenceEqual(client.Array.GetDictionaryItemNull(),
new DictionaryEqualityComparer<string>()));
var listDictionary3 = new List<Dictionary<string, string>>
{
new Dictionary<string, string> {{"1", "one"}, {"2", "two"}, {"3", "three"}},
new Dictionary<string, string>(0),
new Dictionary<string, string> {{"7", "seven"}, {"8", "eight"}, {"9", "nine"}}
};
Assert.True(listDictionary3.SequenceEqual(client.Array.GetDictionaryItemEmpty(),
new DictionaryEqualityComparer<string>()));
Assert.Null(client.Array.GetArrayNull());
Assert.Throws<SerializationException>(() => client.Array.GetInvalid());
Assert.True(client.Array.GetBooleanInvalidNull().SequenceEqual(new List<bool?> {true, null, false}));
Assert.Throws<SerializationException>(() => client.Array.GetBooleanInvalidString());
Assert.True(client.Array.GetIntInvalidNull().SequenceEqual(new List<int?> {1, null, 0}));
Assert.Throws<SerializationException>(() => client.Array.GetIntInvalidString());
Assert.True(client.Array.GetLongInvalidNull().SequenceEqual(new List<long?> {1, null, 0}));
Assert.Throws<SerializationException>(() => client.Array.GetLongInvalidString());
Assert.True(client.Array.GetFloatInvalidNull().SequenceEqual(new List<double?> {0.0, null, -1.2e20}));
Assert.Throws<SerializationException>(() => client.Array.GetFloatInvalidString());
Assert.True(client.Array.GetDoubleInvalidNull().SequenceEqual(new List<double?> {0.0, null, -1.2e20}));
Assert.Throws<SerializationException>(() => client.Array.GetDoubleInvalidString());
Assert.True(client.Array.GetStringWithInvalid().SequenceEqual(new List<string> {"foo", "123", "foo2"}));
var dateNullArray = client.Array.GetDateInvalidNull();
Assert.True(dateNullArray.SequenceEqual(new List<DateTime?>
{
DateTime.Parse("2012-01-01",
CultureInfo.InvariantCulture),
null,
DateTime.Parse("1776-07-04", CultureInfo.InvariantCulture)
}));
Assert.Throws<SerializationException>(() => client.Array.GetDateInvalidChars());
var dateTimeNullArray = client.Array.GetDateTimeInvalidNull();
Assert.True(dateTimeNullArray.SequenceEqual(new List<DateTime?>
{
DateTime.Parse("2000-12-01t00:00:01z",
CultureInfo.InvariantCulture).ToUniversalTime(),
null
}));
Assert.Throws<SerializationException>(() => client.Array.GetDateTimeInvalidChars());
var guid1 = new Guid("6DCC7237-45FE-45C4-8A6B-3A8A3F625652");
var guid2 = new Guid("D1399005-30F7-40D6-8DA6-DD7C89AD34DB");
var guid3 = new Guid("F42F6AA1-A5BC-4DDF-907E-5F915DE43205");
Assert.Equal(new List<Guid?> {guid1, guid2, guid3}, client.Array.GetUuidValid());
client.Array.PutUuidValid(new List<Guid?> {guid1, guid2, guid3});
Assert.Throws<SerializationException>(() => client.Array.GetUuidInvalidChars());
var base64Url1 = Encoding.UTF8.GetBytes("a string that gets encoded with base64url");
var base64Url2 = Encoding.UTF8.GetBytes("test string");
var base64Url3 = Encoding.UTF8.GetBytes("Lorem ipsum");
Assert.Equal(new List<byte[]> {base64Url1, base64Url2, base64Url3}, client.Array.GetBase64Url());
}
}
[Fact]
public void DictionaryTests()
{
SwaggerSpecRunner.RunTests(
SwaggerPath("body-dictionary.json"), ExpectedPath("BodyDictionary"));
using (var client =
new AutoRestSwaggerBATdictionaryService(Fixture.Uri))
{
TestBasicDictionaryParsing(client);
TestDictionaryPrimitiveTypes(client);
TestDictionaryComposedTypes(client);
}
}
private static void TestDictionaryComposedTypes(AutoRestSwaggerBATdictionaryService client)
{
var testProduct1 = new Widget {Integer = 1, StringProperty = "2"};
var testProduct2 = new Widget {Integer = 3, StringProperty = "4"};
var testProduct3 = new Widget {Integer = 5, StringProperty = "6"};
var testDictionary1 = new Dictionary<string, Widget>
{
{"0", testProduct1},
{"1", testProduct2},
{"2", testProduct3}
};
// GET complex/null
Assert.Null(client.Dictionary.GetComplexNull());
// GET complex/empty
Assert.Empty(client.Dictionary.GetComplexEmpty());
// PUT complex/valid
client.Dictionary.PutComplexValid(testDictionary1);
// GET complex/valid
var complexResult = client.Dictionary.GetComplexValid();
foreach (var key in testDictionary1.Keys)
{
Assert.True(complexResult.ContainsKey(key));
Assert.Equal(testDictionary1[key], complexResult[key], new WidgetEqualityComparer());
}
var listDictionary = new Dictionary<string, IList<string>>
{
{"0", new List<string> {"1", "2", "3"}},
{"1", new List<string> {"4", "5", "6"}},
{"2", new List<string> {"7", "8", "9"}}
};
// PUT array/valid
client.Dictionary.PutArrayValid(listDictionary);
// GET array/valid
var arrayResult = client.Dictionary.GetArrayValid();
foreach (var key in listDictionary.Keys)
{
Assert.True(arrayResult.ContainsKey(key));
Assert.Equal(listDictionary[key], arrayResult[key], new ListEqualityComparer<string>());
}
var dictionaryDictionary = new Dictionary<string, IDictionary<string, string>>
{
{"0", new Dictionary<string, string> {{"1", "one"}, {"2", "two"}, {"3", "three"}}},
{"1", new Dictionary<string, string> {{"4", "four"}, {"5", "five"}, {"6", "six"}}},
{"2", new Dictionary<string, string> {{"7", "seven"}, {"8", "eight"}, {"9", "nine"}}}
};
// PUT dictionary/valid
client.Dictionary.PutDictionaryValid(dictionaryDictionary);
// GET dictionary/valid
var dictionaryResult = client.Dictionary.GetDictionaryValid();
foreach (var key in dictionaryDictionary.Keys)
{
Assert.True(dictionaryResult.ContainsKey(key));
Assert.Equal(dictionaryDictionary[key], dictionaryResult[key],
new DictionaryEqualityComparer<string>());
}
// GET dictionary/null
Assert.Null(client.Dictionary.GetComplexNull());
// GET dictionary/empty
Assert.Empty(client.Dictionary.GetComplexEmpty());
var productDictionary2 = new Dictionary<string, Widget>
{
{"0", testProduct1},
{"1", null},
{"2", testProduct3}
};
// GET complex/itemnull
complexResult = client.Dictionary.GetComplexItemNull();
foreach (var key in productDictionary2.Keys)
{
Assert.True(complexResult.ContainsKey(key));
Assert.Equal(productDictionary2[key], complexResult[key], new WidgetEqualityComparer());
}
// GET complex/itemempty
var productList3 = new Dictionary<string, Widget>
{
{"0", testProduct1},
{"1", new Widget()},
{"2", testProduct3}
};
complexResult = client.Dictionary.GetComplexItemEmpty();
foreach (var key in productList3.Keys)
{
Assert.True(complexResult.ContainsKey(key));
Assert.Equal(productList3[key], complexResult[key], new WidgetEqualityComparer());
}
// GET array/null
Assert.Null(client.Dictionary.GetArrayNull());
// GET array/empty
Assert.Empty(client.Dictionary.GetArrayEmpty());
listDictionary = new Dictionary<string, IList<string>>
{
{"0", new List<string> {"1", "2", "3"}},
{"1", null},
{"2", new List<string> {"7", "8", "9"}}
};
// GET array/itemnull
arrayResult = client.Dictionary.GetArrayItemNull();
foreach (var key in listDictionary.Keys)
{
Assert.True(arrayResult.ContainsKey(key));
Assert.Equal(listDictionary[key], arrayResult[key], new ListEqualityComparer<string>());
}
listDictionary = new Dictionary<string, IList<string>>
{
{"0", new List<string> {"1", "2", "3"}},
{"1", new List<string>(0)},
{"2", new List<string> {"7", "8", "9"}}
};
// GET array/itemempty
arrayResult = client.Dictionary.GetArrayItemEmpty();
foreach (var key in listDictionary.Keys)
{
Assert.True(arrayResult.ContainsKey(key));
Assert.Equal(listDictionary[key], arrayResult[key], new ListEqualityComparer<string>());
}
// GET dictionary/null
Assert.Null(client.Dictionary.GetDictionaryNull());
// GET dictionary/empty
Assert.Empty(client.Dictionary.GetDictionaryEmpty());
dictionaryDictionary = new Dictionary<string, IDictionary<string, string>>
{
{"0", new Dictionary<string, string> {{"1", "one"}, {"2", "two"}, {"3", "three"}}},
{"1", null},
{"2", new Dictionary<string, string> {{"7", "seven"}, {"8", "eight"}, {"9", "nine"}}}
};
// GET dictionary/itemnull
dictionaryResult = client.Dictionary.GetDictionaryItemNull();
foreach (var key in dictionaryDictionary.Keys)
{
Assert.True(dictionaryResult.ContainsKey(key));
Assert.Equal(dictionaryDictionary[key], dictionaryResult[key],
new DictionaryEqualityComparer<string>());
}
dictionaryDictionary = new Dictionary<string, IDictionary<string, string>>
{
{"0", new Dictionary<string, string> {{"1", "one"}, {"2", "two"}, {"3", "three"}}},
{"1", new Dictionary<string, string>(0)},
{"2", new Dictionary<string, string> {{"7", "seven"}, {"8", "eight"}, {"9", "nine"}}}
};
// GET dictionary/itemempty
dictionaryResult = client.Dictionary.GetDictionaryItemEmpty();
foreach (var key in dictionaryDictionary.Keys)
{
Assert.True(dictionaryResult.ContainsKey(key));
Assert.Equal(dictionaryDictionary[key], dictionaryResult[key],
new DictionaryEqualityComparer<string>());
}
}
private static void TestDictionaryPrimitiveTypes(AutoRestSwaggerBATdictionaryService client)
{
var tfft = new Dictionary<string, bool?> {{"0", true}, {"1", false}, {"2", false}, {"3", true}};
// GET prim/boolean/tfft
Assert.Equal(tfft, client.Dictionary.GetBooleanTfft());
// PUT prim/boolean/tfft
client.Dictionary.PutBooleanTfft(tfft);
var invalidNullDict = new Dictionary<string, bool?>
{
{"0", true},
{"1", null},
{"2", false}
};
Assert.Equal(invalidNullDict, client.Dictionary.GetBooleanInvalidNull());
Assert.Throws<SerializationException>(() => client.Dictionary.GetBooleanInvalidString());
var intValid = new Dictionary<string, int?> {{"0", 1}, {"1", -1}, {"2", 3}, {"3", 300}};
// GET prim/integer/1.-1.3.300
Assert.Equal(intValid, client.Dictionary.GetIntegerValid());
// PUT prim/integer/1.-1.3.300
client.Dictionary.PutIntegerValid(intValid);
var intNullDict = new Dictionary<string, int?> {{"0", 1}, {"1", null}, {"2", 0}};
Assert.Equal(intNullDict, client.Dictionary.GetIntInvalidNull());
Assert.Throws<SerializationException>(() => client.Dictionary.GetIntInvalidString());
var longValid = new Dictionary<string, long?> {{"0", 1L}, {"1", -1}, {"2", 3}, {"3", 300}};
// GET prim/long/1.-1.3.300
Assert.Equal(longValid, client.Dictionary.GetLongValid());
// PUT prim/long/1.-1.3.300
client.Dictionary.PutLongValid(longValid);
var longNullDict = new Dictionary<string, long?> {{"0", 1}, {"1", null}, {"2", 0}};
Assert.Equal(longNullDict, client.Dictionary.GetLongInvalidNull());
Assert.Throws<SerializationException>(() => client.Dictionary.GetLongInvalidString());
var floatValid = new Dictionary<string, double?> {{"0", 0}, {"1", -0.01}, {"2", -1.2e20}};
// GET prim/float/0--0.01-1.2e20
Assert.Equal(floatValid, client.Dictionary.GetFloatValid());
// PUT prim/float/0--0.01-1.2e20
client.Dictionary.PutFloatValid(floatValid);
var floatNullDict = new Dictionary<string, double?> {{"0", 0.0}, {"1", null}, {"2", -1.2e20}};
Assert.Equal(floatNullDict, client.Dictionary.GetFloatInvalidNull());
Assert.Throws<SerializationException>(() => client.Dictionary.GetFloatInvalidString());
var doubleValid = new Dictionary<string, double?> {{"0", 0}, {"1", -0.01}, {"2", -1.2e20}};
// GET prim/double/0--0.01-1.2e20
Assert.Equal(doubleValid, client.Dictionary.GetDoubleValid());
// PUT prim/double/0--0.01-1.2e20
client.Dictionary.PutDoubleValid(doubleValid);
floatNullDict = new Dictionary<string, double?> {{"0", 0.0}, {"1", null}, {"2", -1.2e20}};
Assert.Equal(floatNullDict, client.Dictionary.GetDoubleInvalidNull());
Assert.Throws<SerializationException>(() => client.Dictionary.GetDoubleInvalidString());
var stringValid = new Dictionary<string, string> {{"0", "foo1"}, {"1", "foo2"}, {"2", "foo3"}};
// GET prim/string/foo1.foo2.foo3
Assert.Equal(stringValid, client.Dictionary.GetStringValid());
// PUT prim/string/foo1.foo2.foo3
client.Dictionary.PutStringValid(stringValid);
var stringNullDict = new Dictionary<string, string> {{"0", "foo"}, {"1", null}, {"2", "foo2"}};
var stringInvalidDict = new Dictionary<string, string> {{"0", "foo"}, {"1", "123"}, {"2", "foo2"}};
Assert.Equal(stringNullDict, client.Dictionary.GetStringWithNull());
Assert.Equal(stringInvalidDict, client.Dictionary.GetStringWithInvalid());
var date1 = new DateTimeOffset(2000, 12, 01, 0, 0, 0, TimeSpan.FromHours(0)).UtcDateTime;
var date2 = new DateTimeOffset(1980, 1, 2, 0, 0, 0, TimeSpan.FromHours(0)).UtcDateTime;
var date3 = new DateTimeOffset(1492, 10, 12, 0, 0, 0, TimeSpan.FromHours(0)).UtcDateTime;
var datetime1 = new DateTimeOffset(2000, 12, 01, 0, 0, 1, TimeSpan.Zero).UtcDateTime;
var datetime2 = new DateTimeOffset(1980, 1, 2, 0, 11, 35, TimeSpan.FromHours(1)).UtcDateTime;
var datetime3 = new DateTimeOffset(1492, 10, 12, 10, 15, 1, TimeSpan.FromHours(-8)).UtcDateTime;
var rfcDatetime1 = new DateTimeOffset(2000, 12, 01, 0, 0, 1, TimeSpan.Zero).UtcDateTime;
var rfcDatetime2 = new DateTimeOffset(1980, 1, 2, 0, 11, 35, TimeSpan.Zero).UtcDateTime;
var rfcDatetime3 = new DateTimeOffset(1492, 10, 12, 10, 15, 1, TimeSpan.Zero).UtcDateTime;
var duration1 = new TimeSpan(123, 22, 14, 12, 11);
var duration2 = new TimeSpan(5, 1, 0, 0, 0);
// GET prim/date/valid
var dateDictionary = client.Dictionary.GetDateValid();
Assert.Equal(new Dictionary<string, DateTime?> {{"0", date1}, {"1", date2}, {"2", date3}},
dateDictionary);
client.Dictionary.PutDateValid(new Dictionary<string, DateTime?>
{
{"0", date1},
{"1", date2},
{"2", date3}
});
var dateNullDict = new Dictionary<string, DateTime?>
{
{"0", new DateTime(2012, 1, 1, 0, 0, 0, DateTimeKind.Utc)},
{"1", null},
{"2", new DateTime(1776, 7, 4, 0, 0, 0, DateTimeKind.Utc)}
};
Assert.Equal(dateNullDict, client.Dictionary.GetDateInvalidNull());
Assert.Throws<SerializationException>(() => client.Dictionary.GetDateInvalidChars());
// GET prim/datetime/valid
Assert.Equal(new Dictionary<string, DateTime?> {{"0", datetime1}, {"1", datetime2}, {"2", datetime3}},
client.Dictionary.GetDateTimeValid());
client.Dictionary.PutDateTimeValid(new Dictionary<string, DateTime?>
{
{"0", datetime1},
{"1", datetime2},
{"2", datetime3}
});
var datetimeNullDict = new Dictionary<string, DateTime?>
{
{"0", new DateTime(2000, 12, 1, 0, 0, 1, DateTimeKind.Utc)},
{"1", null}
};
Assert.Equal(datetimeNullDict, client.Dictionary.GetDateTimeInvalidNull());
Assert.Throws<SerializationException>(() => client.Dictionary.GetDateTimeInvalidChars());
// GET prim/datetimerfc1123/valid
Assert.Equal(
new Dictionary<string, DateTime?> {{"0", rfcDatetime1}, {"1", rfcDatetime2}, {"2", rfcDatetime3}},
client.Dictionary.GetDateTimeRfc1123Valid());
client.Dictionary.PutDateTimeRfc1123Valid(new Dictionary<string, DateTime?>
{
{"0", rfcDatetime1},
{"1", rfcDatetime2},
{"2", rfcDatetime3}
});