@@ -37,6 +37,13 @@ public void FieldRoundtrip_Works()
3737 Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
3838 Name = "name" ,
3939 Status = Status . Active ,
40+ ParameterDefinitions =
41+ [
42+ new Dictionary < string , JsonElement > ( )
43+ {
44+ { "foo" , JsonSerializer . SerializeToElement ( "bar" ) } ,
45+ } ,
46+ ] ,
4047 } ;
4148
4249 string expectedID = "id" ;
@@ -60,6 +67,13 @@ public void FieldRoundtrip_Works()
6067 Dictionary < string , string > expectedMetadata = new ( ) { { "foo" , "string" } } ;
6168 string expectedName = "name" ;
6269 ApiEnum < string , Status > expectedStatus = Status . Active ;
70+ List < Dictionary < string , JsonElement > > expectedParameterDefinitions =
71+ [
72+ new Dictionary < string , JsonElement > ( )
73+ {
74+ { "foo" , JsonSerializer . SerializeToElement ( "bar" ) } ,
75+ } ,
76+ ] ;
6377
6478 Assert . Equal ( expectedID , model . ID ) ;
6579 Assert . Equal ( expectedDescription , model . Description ) ;
@@ -73,6 +87,21 @@ public void FieldRoundtrip_Works()
7387 }
7488 Assert . Equal ( expectedName , model . Name ) ;
7589 Assert . Equal ( expectedStatus , model . Status ) ;
90+ Assert . NotNull ( model . ParameterDefinitions ) ;
91+ Assert . Equal ( expectedParameterDefinitions . Count , model . ParameterDefinitions . Count ) ;
92+ for ( int i = 0 ; i < expectedParameterDefinitions . Count ; i ++ )
93+ {
94+ Assert . Equal (
95+ expectedParameterDefinitions [ i ] . Count ,
96+ model . ParameterDefinitions [ i ] . Count
97+ ) ;
98+ foreach ( var item in expectedParameterDefinitions [ i ] )
99+ {
100+ Assert . True ( model . ParameterDefinitions [ i ] . TryGetValue ( item . Key , out var value ) ) ;
101+
102+ Assert . True ( JsonElement . DeepEquals ( value , model . ParameterDefinitions [ i ] [ item . Key ] ) ) ;
103+ }
104+ }
76105 }
77106
78107 [ Fact ]
@@ -102,6 +131,13 @@ public void SerializationRoundtrip_Works()
102131 Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
103132 Name = "name" ,
104133 Status = Status . Active ,
134+ ParameterDefinitions =
135+ [
136+ new Dictionary < string , JsonElement > ( )
137+ {
138+ { "foo" , JsonSerializer . SerializeToElement ( "bar" ) } ,
139+ } ,
140+ ] ,
105141 } ;
106142
107143 string json = JsonSerializer . Serialize ( model , ModelBase . SerializerOptions ) ;
@@ -140,6 +176,13 @@ public void FieldRoundtripThroughSerialization_Works()
140176 Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
141177 Name = "name" ,
142178 Status = Status . Active ,
179+ ParameterDefinitions =
180+ [
181+ new Dictionary < string , JsonElement > ( )
182+ {
183+ { "foo" , JsonSerializer . SerializeToElement ( "bar" ) } ,
184+ } ,
185+ ] ,
143186 } ;
144187
145188 string element = JsonSerializer . Serialize ( model , ModelBase . SerializerOptions ) ;
@@ -170,6 +213,13 @@ public void FieldRoundtripThroughSerialization_Works()
170213 Dictionary < string , string > expectedMetadata = new ( ) { { "foo" , "string" } } ;
171214 string expectedName = "name" ;
172215 ApiEnum < string , Status > expectedStatus = Status . Active ;
216+ List < Dictionary < string , JsonElement > > expectedParameterDefinitions =
217+ [
218+ new Dictionary < string , JsonElement > ( )
219+ {
220+ { "foo" , JsonSerializer . SerializeToElement ( "bar" ) } ,
221+ } ,
222+ ] ;
173223
174224 Assert . Equal ( expectedID , deserialized . ID ) ;
175225 Assert . Equal ( expectedDescription , deserialized . Description ) ;
@@ -183,6 +233,25 @@ public void FieldRoundtripThroughSerialization_Works()
183233 }
184234 Assert . Equal ( expectedName , deserialized . Name ) ;
185235 Assert . Equal ( expectedStatus , deserialized . Status ) ;
236+ Assert . NotNull ( deserialized . ParameterDefinitions ) ;
237+ Assert . Equal ( expectedParameterDefinitions . Count , deserialized . ParameterDefinitions . Count ) ;
238+ for ( int i = 0 ; i < expectedParameterDefinitions . Count ; i ++ )
239+ {
240+ Assert . Equal (
241+ expectedParameterDefinitions [ i ] . Count ,
242+ deserialized . ParameterDefinitions [ i ] . Count
243+ ) ;
244+ foreach ( var item in expectedParameterDefinitions [ i ] )
245+ {
246+ Assert . True (
247+ deserialized . ParameterDefinitions [ i ] . TryGetValue ( item . Key , out var value )
248+ ) ;
249+
250+ Assert . True (
251+ JsonElement . DeepEquals ( value , deserialized . ParameterDefinitions [ i ] [ item . Key ] )
252+ ) ;
253+ }
254+ }
186255 }
187256
188257 [ Fact ]
@@ -212,6 +281,147 @@ public void Validation_Works()
212281 Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
213282 Name = "name" ,
214283 Status = Status . Active ,
284+ ParameterDefinitions =
285+ [
286+ new Dictionary < string , JsonElement > ( )
287+ {
288+ { "foo" , JsonSerializer . SerializeToElement ( "bar" ) } ,
289+ } ,
290+ ] ,
291+ } ;
292+
293+ model . Validate ( ) ;
294+ }
295+
296+ [ Fact ]
297+ public void OptionalNullablePropertiesUnsetAreNotSet_Works ( )
298+ {
299+ var model = new BillableMetric
300+ {
301+ ID = "id" ,
302+ Description = "description" ,
303+ Item = new ( )
304+ {
305+ ID = "id" ,
306+ CreatedAt = DateTimeOffset . Parse ( "2019-12-27T18:11:19.117Z" ) ,
307+ ExternalConnections =
308+ [
309+ new ( )
310+ {
311+ ExternalConnectionName =
312+ ItemExternalConnectionExternalConnectionName . Stripe ,
313+ ExternalEntityID = "external_entity_id" ,
314+ } ,
315+ ] ,
316+ Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
317+ Name = "name" ,
318+ ArchivedAt = DateTimeOffset . Parse ( "2019-12-27T18:11:19.117Z" ) ,
319+ } ,
320+ Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
321+ Name = "name" ,
322+ Status = Status . Active ,
323+ } ;
324+
325+ Assert . Null ( model . ParameterDefinitions ) ;
326+ Assert . False ( model . RawData . ContainsKey ( "parameter_definitions" ) ) ;
327+ }
328+
329+ [ Fact ]
330+ public void OptionalNullablePropertiesUnsetValidation_Works ( )
331+ {
332+ var model = new BillableMetric
333+ {
334+ ID = "id" ,
335+ Description = "description" ,
336+ Item = new ( )
337+ {
338+ ID = "id" ,
339+ CreatedAt = DateTimeOffset . Parse ( "2019-12-27T18:11:19.117Z" ) ,
340+ ExternalConnections =
341+ [
342+ new ( )
343+ {
344+ ExternalConnectionName =
345+ ItemExternalConnectionExternalConnectionName . Stripe ,
346+ ExternalEntityID = "external_entity_id" ,
347+ } ,
348+ ] ,
349+ Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
350+ Name = "name" ,
351+ ArchivedAt = DateTimeOffset . Parse ( "2019-12-27T18:11:19.117Z" ) ,
352+ } ,
353+ Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
354+ Name = "name" ,
355+ Status = Status . Active ,
356+ } ;
357+
358+ model . Validate ( ) ;
359+ }
360+
361+ [ Fact ]
362+ public void OptionalNullablePropertiesSetToNullAreSetToNull_Works ( )
363+ {
364+ var model = new BillableMetric
365+ {
366+ ID = "id" ,
367+ Description = "description" ,
368+ Item = new ( )
369+ {
370+ ID = "id" ,
371+ CreatedAt = DateTimeOffset . Parse ( "2019-12-27T18:11:19.117Z" ) ,
372+ ExternalConnections =
373+ [
374+ new ( )
375+ {
376+ ExternalConnectionName =
377+ ItemExternalConnectionExternalConnectionName . Stripe ,
378+ ExternalEntityID = "external_entity_id" ,
379+ } ,
380+ ] ,
381+ Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
382+ Name = "name" ,
383+ ArchivedAt = DateTimeOffset . Parse ( "2019-12-27T18:11:19.117Z" ) ,
384+ } ,
385+ Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
386+ Name = "name" ,
387+ Status = Status . Active ,
388+
389+ ParameterDefinitions = null ,
390+ } ;
391+
392+ Assert . Null ( model . ParameterDefinitions ) ;
393+ Assert . True ( model . RawData . ContainsKey ( "parameter_definitions" ) ) ;
394+ }
395+
396+ [ Fact ]
397+ public void OptionalNullablePropertiesSetToNullValidation_Works ( )
398+ {
399+ var model = new BillableMetric
400+ {
401+ ID = "id" ,
402+ Description = "description" ,
403+ Item = new ( )
404+ {
405+ ID = "id" ,
406+ CreatedAt = DateTimeOffset . Parse ( "2019-12-27T18:11:19.117Z" ) ,
407+ ExternalConnections =
408+ [
409+ new ( )
410+ {
411+ ExternalConnectionName =
412+ ItemExternalConnectionExternalConnectionName . Stripe ,
413+ ExternalEntityID = "external_entity_id" ,
414+ } ,
415+ ] ,
416+ Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
417+ Name = "name" ,
418+ ArchivedAt = DateTimeOffset . Parse ( "2019-12-27T18:11:19.117Z" ) ,
419+ } ,
420+ Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
421+ Name = "name" ,
422+ Status = Status . Active ,
423+
424+ ParameterDefinitions = null ,
215425 } ;
216426
217427 model . Validate ( ) ;
@@ -244,6 +454,13 @@ public void CopyConstructor_Works()
244454 Metadata = new Dictionary < string , string > ( ) { { "foo" , "string" } } ,
245455 Name = "name" ,
246456 Status = Status . Active ,
457+ ParameterDefinitions =
458+ [
459+ new Dictionary < string , JsonElement > ( )
460+ {
461+ { "foo" , JsonSerializer . SerializeToElement ( "bar" ) } ,
462+ } ,
463+ ] ,
247464 } ;
248465
249466 BillableMetric copied = new ( model ) ;
0 commit comments