forked from RehanSaeed/Schema.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValuesJsonConverterTest.cs
590 lines (527 loc) · 22 KB
/
ValuesJsonConverterTest.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
namespace Schema.NET.Test;
using System;
using System.Linq;
using System.Text.Json.Serialization;
using Xunit;
public class ValuesJsonConverterTest
{
[Fact]
public void WriteJson_Values_ZeroCountWritesNull()
{
var value = default(Values<int?, string>);
var json = SerializeObject(value);
Assert.Equal("{}", json);
}
[Fact]
public void WriteJson_Values_OneCountWritesSingle()
{
var value = new Values<int?, string>("One Value");
var json = SerializeObject(value);
Assert.Equal("{\"Property\":\"One Value\"}", json);
}
[Fact]
public void WriteJson_Values_GreaterThanOneCountWritesArray()
{
var value = new Values<int?, string>(new[] { "A", "B" });
var json = SerializeObject(value);
Assert.Equal("{\"Property\":[\"A\",\"B\"]}", json);
}
[Fact]
public void WriteJson_Values_MixedValueTypes()
{
var value = new Values<int?, string>(new object[] { 123, "B" });
var json = SerializeObject(value);
Assert.Equal("{\"Property\":[123,\"B\"]}", json);
}
[Fact]
public void WriteJson_OneOrMany_ZeroCountWritesNull()
{
var value = default(OneOrMany<string>);
var json = SerializeObject(value);
Assert.Equal("{}", json);
}
[Fact]
public void WriteJson_OneOrMany_OneCountWritesSingle()
{
var value = new OneOrMany<string>("One Value");
var json = SerializeObject(value);
Assert.Equal("{\"Property\":\"One Value\"}", json);
}
[Fact]
public void WriteJson_OneOrMany_GreaterThanOneCountWritesArray()
{
var value = new OneOrMany<string>(new[] { "A", "B" });
var json = SerializeObject(value);
Assert.Equal("{\"Property\":[\"A\",\"B\"]}", json);
}
[Fact]
public void WriteJson_DateTime_ISO8601_DateTime()
{
var value = new OneOrMany<DateTime>(new DateTime(2000, 1, 1, 12, 34, 56));
var json = SerializeObject(value);
Assert.Equal("{\"Property\":\"2000-01-01T12:34:56\"}", json);
}
[Fact]
public void WriteJson_DateTimeOffset_ISO8601_DateTimeWithTimeOffset()
{
var value = new OneOrMany<DateTimeOffset>(new DateTimeOffset(2000, 1, 1, 12, 34, 56, TimeSpan.FromHours(1)));
var json = SerializeObject(value);
Assert.Equal("{\"Property\":\"2000-01-01T12:34:56+01:00\"}", json);
}
[Fact]
public void WriteJson_TimeSpan_ISO8601_TimeOfDay()
{
var value = new OneOrMany<TimeSpan>(new TimeSpan(12, 34, 56));
var json = SerializeObject(value);
Assert.Equal("{\"Property\":\"12:34:56\"}", json);
}
[Fact]
public void ReadJson_Values_SingleValue_String()
{
var json = "{\"Property\":\"Test String\"}";
var result = DeserializeObject<Values<int, string>>(json);
Assert.Equal("Test String", result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_IntegerAsString()
{
var json = "{\"Property\":\"123\"}";
var result = DeserializeObject<Values<string, int>>(json);
Assert.Equal(123, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_LongAsString()
{
var json = "{\"Property\":\"8294967295\"}";
var result = DeserializeObject<Values<string, long>>(json);
Assert.Equal(8294967295, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_FloatAsString()
{
var json = "{\"Property\":\"123.45\"}";
var result = DeserializeObject<Values<string, float>>(json);
Assert.Equal(123.45f, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DoubleAsString()
{
var json = "{\"Property\":\"123.45\"}";
var result = DeserializeObject<Values<string, double>>(json);
Assert.Equal(123.45, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_BooleanAsString()
{
var json = "{\"Property\":\"true\"}";
var result = DeserializeObject<Values<string, bool>>(json);
Assert.True(result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_GuidAsString()
{
var json = "{\"Property\":\"13ec75b3-250c-48a2-8bd0-dfee62852bd4\"}";
var result = DeserializeObject<Values<string, Guid>>(json);
Assert.Equal(new Guid("13ec75b3-250c-48a2-8bd0-dfee62852bd4"), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_NullablePrimitiveAsString()
{
var json = "{\"Property\":\"123\"}";
var result = DeserializeObject<Values<string, int?>>(json);
Assert.Equal(123, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_Primitive()
{
var json = "{\"Property\":123}";
var result = DeserializeObject<Values<string, int>>(json);
Assert.Equal(123, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DecimalAsString()
{
var json = "{\"Property\":\"123.456\"}";
var result = DeserializeObject<Values<string, decimal>>(json);
Assert.Equal(123.456m, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_Decimal()
{
var json = "{\"Property\":123.456}";
var result = DeserializeObject<Values<string, decimal>>(json);
Assert.Equal(123.456m, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DateTimeAsISO8601String()
{
var json = "{\"Property\":\"2000-01-01T12:34\"}";
var result = DeserializeObject<Values<string, DateTime>>(json);
Assert.Equal(new DateTime(2000, 1, 1, 12, 34, 0), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DateTimeAsMicrosoftDateTimeString()
{
var json = "{\"Property\":\"\\/Date(946730040000)\\/\"}";
var result = DeserializeObject<Values<string, DateTime>>(json);
Assert.Equal(new DateTime(2000, 1, 1, 12, 34, 0), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DateTimeNegativeOffsetAsMicrosoftDateTimeString()
{
var json = "{\"Property\":\"\\/Date(946730040000-0100)\\/\"}";
var result = DeserializeObject<Values<string, DateTimeOffset>>(json);
Assert.Equal(new DateTimeOffset(2000, 1, 1, 12, 34, 0, TimeSpan.FromHours(-1)), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DateTimePositiveOffsetAsMicrosoftDateTimeString()
{
var json = "{\"Property\":\"\\/Date(946730040000+0100)\\/\"}";
var result = DeserializeObject<Values<string, DateTimeOffset>>(json);
Assert.Equal(new DateTimeOffset(2000, 1, 1, 12, 34, 0, TimeSpan.FromHours(1)), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DateTimeOffsetAsISO8601String()
{
var json = "{\"Property\":\"2000-01-01T12:34:00+01:00\"}";
var result = DeserializeObject<Values<string, DateTimeOffset>>(json);
Assert.Equal(new DateTimeOffset(2000, 1, 1, 12, 34, 0, TimeSpan.FromHours(1)), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DateTimeOffsetFallback_DateTimeAsISO8601String_NoOffset()
{
var json = "{\"Property\":\"2000-01-01T12:34:00\"}";
var result = DeserializeObject<Values<DateTime, DateTimeOffset>>(json);
Assert.Equal(new DateTime(2000, 1, 1, 12, 34, 0), result.Value1.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DateTimeOffsetNoFallback_DateTimeAsISO8601String_ZOffset()
{
var json = "{\"Property\":\"2000-01-01T12:34:00Z\"}";
var result = DeserializeObject<Values<DateTime, DateTimeOffset>>(json);
Assert.Equal(new DateTimeOffset(2000, 1, 1, 12, 34, 0, TimeSpan.FromHours(0)), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_DateTimeOffsetNoFallback_DateTimeAsISO8601String_TimeOffset()
{
var json = "{\"Property\":\"2000-01-01T12:34:00+01:00\"}";
var result = DeserializeObject<Values<DateTime, DateTimeOffset>>(json);
Assert.Equal(new DateTimeOffset(2000, 1, 1, 12, 34, 0, TimeSpan.FromHours(1)), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_TimeSpanAsISO8601TimeOfDayString()
{
var json = "{\"Property\":\"12:34\"}";
var result = DeserializeObject<Values<string, TimeSpan>>(json);
Assert.Equal(new TimeSpan(12, 34, 0), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_TimeSpanAsISO8601DurationString()
{
var json = "{\"Property\":\"PT12H34M\"}";
var result = DeserializeObject<Values<string, TimeSpan>>(json);
Assert.Equal(new TimeSpan(12, 34, 0), result.Value2.First());
}
[Fact]
public void ReadJson_ParseValueToken_UriAsString()
{
var json = "{\"Property\":\"https://schema.org/Thing\"}";
var result = DeserializeObject<Values<string, Uri>>(json);
Assert.Equal(new Uri("https://schema.org/Thing"), result.Value2.First());
}
[Fact]
public void ReadJson_ParseValueToken_RelativeUriAsString()
{
var json = "{\"Property\":\"thing\"}";
var result = DeserializeObject<Values<string, Uri>>(json);
Assert.Equal(new Uri("thing", UriKind.Relative), result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_ThingInterface()
{
var json = "{\"Property\":" +
"{" +
"\"@context\":\"https://schema.org\"," +
"\"@type\":\"Book\"," +
"\"@id\":\"https://example.com/book/1\"," +
"\"name\":\"The Catcher in the Rye\"," +
"\"url\":\"https://www.barnesandnoble.com/store/info/offer/JDSalinger\"," +
"\"image\":\"book1.jpg\"," +
"\"author\":{" +
"\"@type\":\"Person\"," +
"\"name\":\"J.D. Salinger\"" +
"}" +
"}" +
"}";
var result = DeserializeObject<Values<string, IBook>>(json);
var actual = result.Value2.First();
Assert.Equal(new Uri("https://example.com/book/1"), ((Book)actual).Id);
Assert.Equal("The Catcher in the Rye", actual.Name);
Assert.Equal(new Uri("https://www.barnesandnoble.com/store/info/offer/JDSalinger"), (Uri)actual.Url!);
Assert.Equal(new Uri("book1.jpg", UriKind.Relative), (Uri)actual.Image!);
var author = Assert.Single(actual.Author.Value2);
Assert.Equal("J.D. Salinger", author.Name);
}
[Fact]
public void ReadJson_Values_SingleValue_ThingActual()
{
var json = "{\"Property\":" +
"{" +
"\"@context\":\"https://schema.org\"," +
"\"@type\":\"Book\"," +
"\"@id\":\"https://example.com/book/1\"," +
"\"name\":\"The Catcher in the Rye\"," +
"\"url\":\"https://www.barnesandnoble.com/store/info/offer/JDSalinger\"," +
"\"author\":{" +
"\"@type\":\"Person\"," +
"\"name\":\"J.D. Salinger\"" +
"}" +
"}" +
"}";
var result = DeserializeObject<Values<string, Book>>(json);
var actual = result.Value2.First();
Assert.Equal(new Uri("https://example.com/book/1"), actual.Id);
Assert.Equal("The Catcher in the Rye", actual.Name);
Assert.Equal(new Uri("https://www.barnesandnoble.com/store/info/offer/JDSalinger"), (Uri)actual.Url!);
var author = Assert.Single(actual.Author.Value2);
Assert.Equal("J.D. Salinger", author.Name);
}
[Fact]
public void ReadJson_Values_SingleValue_ThingInterfaceWithNoTypeToken()
{
var json = "{\"Property\":" +
"{" +
"\"@context\":\"https://schema.org\"," +
"\"@id\":\"https://example.com/book/1\"," +
"\"name\":\"The Catcher in the Rye\"," +
"\"url\":\"https://www.barnesandnoble.com/store/info/offer/JDSalinger\"," +
"\"author\":{" +
"\"@type\":\"Person\"," +
"\"name\":\"J.D. Salinger\"" +
"}" +
"}" +
"}";
var result = DeserializeObject<Values<string, IBook>>(json);
var actual = result.Value2.First();
Assert.Equal(new Uri("https://example.com/book/1"), ((Book)actual).Id);
Assert.Equal("The Catcher in the Rye", actual.Name);
Assert.Equal(new Uri("https://www.barnesandnoble.com/store/info/offer/JDSalinger"), (Uri)actual.Url!);
var author = Assert.Single(actual.Author.Value2);
Assert.Equal("J.D. Salinger", author.Name);
}
[Fact]
public void ReadJson_Values_SingleValue_ThingActualWithNoTypeToken()
{
var json = "{\"Property\":" +
"{" +
"\"@context\":\"https://schema.org\"," +
"\"@id\":\"https://example.com/book/1\"," +
"\"name\":\"The Catcher in the Rye\"," +
"\"url\":\"https://www.barnesandnoble.com/store/info/offer/JDSalinger\"," +
"\"author\":{" +
"\"@type\":\"Person\"," +
"\"name\":\"J.D. Salinger\"" +
"}" +
"}" +
"}";
var result = DeserializeObject<Values<string, Book>>(json);
var actual = result.Value2.First();
Assert.Equal(new Uri("https://example.com/book/1"), actual.Id);
Assert.Equal("The Catcher in the Rye", actual.Name);
Assert.Equal(new Uri("https://www.barnesandnoble.com/store/info/offer/JDSalinger"), (Uri)actual.Url!);
var author = Assert.Single(actual.Author.Value2);
Assert.Equal("J.D. Salinger", author.Name);
}
[Fact]
public void ReadJson_Values_SingleValue_Enum_NoUrl()
{
var json = "{\"Property\":\"InStock\"}";
var result = DeserializeObject<Values<string, ItemAvailability>>(json);
Assert.Equal(ItemAvailability.InStock, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_Enum_HttpSchema()
{
var json = "{\"Property\":\"https://schema.org/InStock\"}";
var result = DeserializeObject<Values<string, ItemAvailability>>(json);
Assert.Equal(ItemAvailability.InStock, result.Value2.First());
}
[Fact]
public void ReadJson_Values_SingleValue_Enum_HttpsSchema()
{
var json = "{\"Property\":\"https://schema.org/InStock\"}";
var result = DeserializeObject<Values<string, ItemAvailability>>(json);
Assert.Equal(ItemAvailability.InStock, result.Value2.First());
}
[Fact]
public void ReadJson_Values_MultiValue_SameType()
{
var json = "{\"Property\":[\"A\",\"B\"]}";
var result = DeserializeObject<Values<int, string>>(json);
Assert.Equal(new[] { "A", "B" }, result.Value2);
}
[Fact]
public void ReadJson_Values_MultiValue_SameType_ArgumentsSwapped()
{
var json = "{\"Property\":[\"A\",\"B\"]}";
var result = DeserializeObject<Values<string, int>>(json);
Assert.Equal(new[] { "A", "B" }, result.Value1);
}
[Fact]
public void ReadJson_Values_MultiValue_MixedType()
{
var json = "{\"Property\":[1,\"B\"]}";
var result = DeserializeObject<Values<int, string>>(json);
Assert.Equal(new[] { 1 }, result.Value1);
Assert.Equal(new[] { "B" }, result.Value2);
}
[Fact]
public void ReadJson_Values_MultiValue_NullablePrimitiveAsString()
{
var json = "{\"Property\":[\"123\",\"456\"]}";
var result = DeserializeObject<Values<string, int?>>(json);
Assert.Equal(new int?[] { 123, 456 }, result.Value2);
}
[Fact]
public void ReadJson_Values_MultiValue_ThingInterface()
{
var json = "{\"Property\":[" +
"{" +
"\"@context\":\"https://schema.org\"," +
"\"@type\":\"Book\"," +
"\"@id\":\"https://example.com/book/1\"," +
"\"name\":\"The Catcher in the Rye\"," +
"\"url\":\"https://www.barnesandnoble.com/store/info/offer/JDSalinger\"," +
"\"author\":{" +
"\"@type\":\"Person\"," +
"\"name\":\"J.D. Salinger\"" +
"}" +
"}," +
"{" +
"\"@context\":\"https://schema.org\"," +
"\"@type\":\"Book\"," +
"\"@id\":\"https://example.com/book/2\"," +
"\"name\":\"The Lord of the Rings\"," +
"\"url\":\"https://www.barnesandnoble.com/store/info/offer/JRRTolkien\"," +
"\"author\":{" +
"\"@type\":\"Person\"," +
"\"name\":\"J.R.R. Tolkien\"" +
"}" +
"}" +
"]}";
var result = DeserializeObject<Values<string, IBook>>(json);
var actual = result.Value2.ToArray();
Assert.Equal(new Uri("https://example.com/book/1"), ((Book)actual[0]).Id);
Assert.Equal("The Catcher in the Rye", actual[0].Name);
Assert.Equal(new Uri("https://www.barnesandnoble.com/store/info/offer/JDSalinger"), (Uri)actual[0].Url!);
var author1 = Assert.Single(actual[0].Author.Value2);
Assert.Equal("J.D. Salinger", author1.Name);
Assert.Equal(new Uri("https://example.com/book/2"), ((Book)actual[1]).Id);
Assert.Equal("The Lord of the Rings", actual[1].Name);
Assert.Equal(new Uri("https://www.barnesandnoble.com/store/info/offer/JRRTolkien"), (Uri)actual[1].Url!);
var author2 = Assert.Single(actual[1].Author.Value2);
Assert.Equal("J.R.R. Tolkien", author2.Name);
}
[Fact]
public void ReadJson_OneOrMany_SingleValue_String()
{
var json = "{\"Property\":\"Test String\"}";
var result = DeserializeObject<OneOrMany<string>>(json);
Assert.Equal("Test String", result.First());
}
[Fact]
public void ReadJson_OneOrMany_MultiValue_String()
{
var json = "{\"Property\":[\"A\",\"B\"]}";
var result = DeserializeObject<OneOrMany<string>>(json);
Assert.Equal(new[] { "A", "B" }, result);
}
[Fact]
public void ReadJson_OneOrMany_SingleValue_NullablePrimitiveAsString()
{
var json = "{\"Property\":\"123\"}";
var result = DeserializeObject<OneOrMany<int?>>(json);
Assert.Equal(123, result.First());
}
[Fact]
public void ReadJson_OneOrMany_MultiValue_NullablePrimitiveAsString()
{
var json = "{\"Property\":[\"123\",\"456\"]}";
var result = DeserializeObject<OneOrMany<int?>>(json);
Assert.Equal(new int?[] { 123, 456 }, result);
}
[Fact]
public void ReadJson_ExplicitExternalTypes_AllowCustomNamespace()
{
var json = "{\"Property\":[" +
"{" +
"\"@type\":\"ExternalSchemaModelCustomNamespace, Schema.NET.Test\"," +
"\"name\":\"Property from Thing\"," +
"\"myCustomProperty\":\"My Test String\"" +
"}" +
"]}";
var result = DeserializeObject<Values<string, SomeCustomNamespace.ExternalSchemaModelCustomNamespace>>(json);
var actual = Assert.Single(result.Value2);
Assert.Equal(new[] { "Property from Thing" }, actual.Name);
Assert.Equal(new[] { "My Test String" }, actual.MyCustomProperty);
}
[Fact]
public void ReadJson_ExplicitExternalTypes_AllowSharedNamespace()
{
var json = "{\"Property\":[" +
"{" +
"\"@type\":\"ExternalSchemaModelSharedNamespace, Schema.NET.Test\"," +
"\"name\":\"Property from Thing\"," +
"\"myCustomProperty\":\"My Test String\"" +
"}" +
"]}";
var result = DeserializeObject<Values<string, ExternalSchemaModelSharedNamespace>>(json);
var actual = Assert.Single(result.Value2);
Assert.Equal(new[] { "Property from Thing" }, actual.Name);
Assert.Equal(new[] { "My Test String" }, actual.MyCustomProperty);
}
[Fact]
public void ReadJson_ImplicitExternalTypes_AllowCustomNamespace()
{
var json = "{\"Property\":[" +
"{" +
"\"@type\":\"SomeCustomNamespace.ExternalSchemaModelCustomNamespace, Schema.NET.Test\"," +
"\"name\":\"Property from Thing\"," +
"\"myCustomProperty\":\"My Test String\"" +
"}" +
"]}";
var result = DeserializeObject<Values<string, IThing>>(json);
var actual = Assert.Single(result.Value2);
Assert.IsType<SomeCustomNamespace.ExternalSchemaModelCustomNamespace>(actual);
Assert.Equal(new[] { "Property from Thing" }, actual.Name);
Assert.Equal(new[] { "My Test String" }, ((SomeCustomNamespace.ExternalSchemaModelCustomNamespace)actual).MyCustomProperty);
}
[Fact]
public void ReadJson_ImplicitExternalTypes_AllowSharedNamespace()
{
var json = "{\"Property\":[" +
"{" +
"\"@type\":\"Schema.NET.ExternalSchemaModelSharedNamespace, Schema.NET.Test\"," +
"\"name\":\"Property from Thing\"," +
"\"myCustomProperty\":\"My Test String\"" +
"}" +
"]}";
var result = DeserializeObject<Values<string, IThing>>(json);
var actual = Assert.Single(result.Value2);
Assert.IsType<ExternalSchemaModelSharedNamespace>(actual);
Assert.Equal(new[] { "Property from Thing" }, actual.Name);
Assert.Equal(new[] { "My Test String" }, ((ExternalSchemaModelSharedNamespace)actual).MyCustomProperty);
}
private static string SerializeObject<T>(T value)
where T : struct, IValues
=> SchemaSerializer.SerializeObject(new TestModel<T> { Property = value });
private static T DeserializeObject<T>(string json)
where T : struct, IValues
=> SchemaSerializer.DeserializeObject<TestModel<T>>(json)!.Property;
private class TestModel<T>
where T : struct, IValues
{
[JsonConverter(typeof(ValuesJsonConverter))]
public T Property { get; set; }
}
}