@@ -156,15 +156,15 @@ public void ReflectionBased_CompleteModel_WithAttribute_WithNullValues()
156156 }
157157
158158 [ Fact ]
159- public void SourceGenerator_WithResolver_WithAttribute_UsingOptions ( )
159+ public void SourceGenerator_WithResolver_WithFormatAttribute_UsingOptions ( )
160160 {
161161 // Arrange
162162 var sourceGenOptions = new JsonSerializerOptions
163163 {
164164 WriteIndented = true ,
165165 TypeInfoResolver = new DateTimeConverterResolver ( ResolverModelJsonSerializerContext . Default )
166166 } ;
167- var originalModel = new SourceGeneratorWithResolverAttributeModel
167+ var originalModel = new SourceGeneratorWithResolverFormatModel
168168 {
169169 DateTimeProperty = new DateTime ( 2023 , 10 , 1 , 12 , 0 , 0 , DateTimeKind . Utc ) ,
170170 NullableDateTimeProperty = new DateTime ( 2023 , 10 , 1 , 12 , 0 , 0 , DateTimeKind . Utc ) ,
@@ -182,42 +182,7 @@ public void SourceGenerator_WithResolver_WithAttribute_UsingOptions()
182182
183183 // Act
184184 var json = JsonSerializer . Serialize ( originalModel , sourceGenOptions ) ;
185- var deserializedModel = JsonSerializer . Deserialize < SourceGeneratorWithResolverAttributeModel > ( json , sourceGenOptions ) ;
186-
187- // Assert
188- Assert . NotNull ( deserializedModel ) ;
189- Assert . Equal ( originalModel . DateTimeProperty , deserializedModel . DateTimeProperty ) ;
190- Assert . Equal ( originalModel . NullableDateTimeProperty , deserializedModel . NullableDateTimeProperty ) ;
191- Assert . Equal ( originalModel . DateTimeOffsetProperty , deserializedModel . DateTimeOffsetProperty ) ;
192- Assert . Equal ( originalModel . NullableDateTimeOffsetProperty , deserializedModel . NullableDateTimeOffsetProperty ) ;
193- Assert . Equal ( expectedJson , json ) ;
194- }
195-
196- [ Fact ]
197- public void SourceGenerator_WithResolver_WithAttribute_UsingContext ( )
198- {
199- // Arrange
200- var testModelType = typeof ( SourceGeneratorWithResolverAttributeModel ) ;
201- var context = new DateTimeConverterResolver ( ResolverModelJsonSerializerContext . Default ) ;
202- var originalModel = new SourceGeneratorWithResolverAttributeModel
203- {
204- DateTimeProperty = new DateTime ( 2023 , 10 , 1 , 12 , 0 , 0 , DateTimeKind . Utc ) ,
205- NullableDateTimeProperty = new DateTime ( 2023 , 10 , 1 , 12 , 0 , 0 , DateTimeKind . Utc ) ,
206- DateTimeOffsetProperty = new DateTimeOffset ( 2023 , 10 , 1 , 12 , 0 , 0 , TimeSpan . Zero ) ,
207- NullableDateTimeOffsetProperty = new DateTimeOffset ( 2023 , 10 , 1 , 12 , 0 , 0 , TimeSpan . Zero )
208- } ;
209- const string expectedJson = """
210- {
211- "DateTimeProperty": "2023-10-01T12:00:00",
212- "NullableDateTimeProperty": "2023-10-01T12:00:00",
213- "DateTimeOffsetProperty": "2023-10-01T12:00:00.000Z",
214- "NullableDateTimeOffsetProperty": "2023-10-01T12:00:00.000Z"
215- }
216- """ ;
217-
218- // Act
219- var json = JsonSerializer . Serialize ( originalModel , testModelType , context ) ;
220- var deserializedModel = ( SourceGeneratorWithResolverAttributeModel ? ) JsonSerializer . Deserialize ( json , testModelType , context ) ;
185+ var deserializedModel = JsonSerializer . Deserialize < SourceGeneratorWithResolverFormatModel > ( json , sourceGenOptions ) ;
221186
222187 // Assert
223188 Assert . NotNull ( deserializedModel ) ;
@@ -229,15 +194,15 @@ public void SourceGenerator_WithResolver_WithAttribute_UsingContext()
229194 }
230195
231196 [ Fact ]
232- public void SourceGenerator_WithResolver_WithAttribute_WithNullValues_UsingOptions ( )
197+ public void SourceGenerator_WithResolver_WithFormatAttribute_WithNullValues_UsingOptions ( )
233198 {
234199 // Arrange
235200 var sourceGenOptions = new JsonSerializerOptions
236201 {
237202 WriteIndented = true ,
238203 TypeInfoResolver = new DateTimeConverterResolver ( ResolverModelJsonSerializerContext . Default )
239204 } ;
240- var originalModel = new SourceGeneratorWithResolverAttributeModel
205+ var originalModel = new SourceGeneratorWithResolverFormatModel
241206 {
242207 DateTimeProperty = new DateTime ( 2023 , 10 , 1 , 12 , 0 , 0 , DateTimeKind . Utc ) ,
243208 NullableDateTimeProperty = null ,
@@ -255,7 +220,7 @@ public void SourceGenerator_WithResolver_WithAttribute_WithNullValues_UsingOptio
255220
256221 // Act
257222 var json = JsonSerializer . Serialize ( originalModel , sourceGenOptions ) ;
258- var deserializedModel = JsonSerializer . Deserialize < SourceGeneratorWithResolverAttributeModel > ( json , sourceGenOptions ) ;
223+ var deserializedModel = JsonSerializer . Deserialize < SourceGeneratorWithResolverFormatModel > ( json , sourceGenOptions ) ;
259224
260225 // Assert
261226 Assert . NotNull ( deserializedModel ) ;
@@ -266,44 +231,6 @@ public void SourceGenerator_WithResolver_WithAttribute_WithNullValues_UsingOptio
266231 Assert . Equal ( expectedJson , json ) ;
267232 }
268233
269- [ Fact ]
270- public void SourceGenerator_WithResolver_WithFormatAttribute_UsingOptions ( )
271- {
272- // Arrange
273- var sourceGenOptions = new JsonSerializerOptions
274- {
275- WriteIndented = true ,
276- TypeInfoResolver = new DateTimeConverterResolver ( ResolverModelJsonSerializerContext . Default )
277- } ;
278- var originalModel = new SourceGeneratorWithResolverFormatModel
279- {
280- DateTimeProperty = new DateTime ( 2023 , 10 , 1 , 12 , 0 , 0 , DateTimeKind . Utc ) ,
281- NullableDateTimeProperty = new DateTime ( 2023 , 10 , 1 , 12 , 0 , 0 , DateTimeKind . Utc ) ,
282- DateTimeOffsetProperty = new DateTimeOffset ( 2023 , 10 , 1 , 12 , 0 , 0 , TimeSpan . Zero ) ,
283- NullableDateTimeOffsetProperty = new DateTimeOffset ( 2023 , 10 , 1 , 12 , 0 , 0 , TimeSpan . Zero )
284- } ;
285- const string expectedJson = """
286- {
287- "DateTimeProperty": "2023-10-01T12:00:00",
288- "NullableDateTimeProperty": "2023-10-01T12:00:00",
289- "DateTimeOffsetProperty": "2023-10-01T12:00:00.000Z",
290- "NullableDateTimeOffsetProperty": "2023-10-01T12:00:00.000Z"
291- }
292- """ ;
293-
294- // Act
295- var json = JsonSerializer . Serialize ( originalModel , sourceGenOptions ) ;
296- var deserializedModel = JsonSerializer . Deserialize < SourceGeneratorWithResolverFormatModel > ( json , sourceGenOptions ) ;
297-
298- // Assert
299- Assert . NotNull ( deserializedModel ) ;
300- Assert . Equal ( originalModel . DateTimeProperty , deserializedModel . DateTimeProperty ) ;
301- Assert . Equal ( originalModel . NullableDateTimeProperty , deserializedModel . NullableDateTimeProperty ) ;
302- Assert . Equal ( originalModel . DateTimeOffsetProperty , deserializedModel . DateTimeOffsetProperty ) ;
303- Assert . Equal ( originalModel . NullableDateTimeOffsetProperty , deserializedModel . NullableDateTimeOffsetProperty ) ;
304- Assert . Equal ( expectedJson , json ) ;
305- }
306-
307234 [ Fact ]
308235 public void SourceGenerator_WithResolver_WithFormatAttribute_UsingContext ( )
309236 {
@@ -340,14 +267,11 @@ public void SourceGenerator_WithResolver_WithFormatAttribute_UsingContext()
340267 }
341268
342269 [ Fact ]
343- public void SourceGenerator_WithResolver_WithFormatAttribute_WithNullValues_UsingOptions ( )
270+ public void SourceGenerator_WithResolver_WithFormatAttribute_WithNullValues_UsingContext ( )
344271 {
345272 // Arrange
346- var sourceGenOptions = new JsonSerializerOptions
347- {
348- WriteIndented = true ,
349- TypeInfoResolver = new DateTimeConverterResolver ( ResolverModelJsonSerializerContext . Default )
350- } ;
273+ var testModelType = typeof ( SourceGeneratorWithResolverFormatModel ) ;
274+ var context = new DateTimeConverterResolver ( ResolverModelJsonSerializerContext . Default ) ;
351275 var originalModel = new SourceGeneratorWithResolverFormatModel
352276 {
353277 DateTimeProperty = new DateTime ( 2023 , 10 , 1 , 12 , 0 , 0 , DateTimeKind . Utc ) ,
@@ -365,15 +289,15 @@ public void SourceGenerator_WithResolver_WithFormatAttribute_WithNullValues_Usin
365289 """ ;
366290
367291 // Act
368- var json = JsonSerializer . Serialize ( originalModel , sourceGenOptions ) ;
369- var deserializedModel = JsonSerializer . Deserialize < SourceGeneratorWithResolverFormatModel > ( json , sourceGenOptions ) ;
292+ var json = JsonSerializer . Serialize ( originalModel , testModelType , context ) ;
293+ var deserializedModel = ( SourceGeneratorWithResolverFormatModel ? ) JsonSerializer . Deserialize ( json , testModelType , context ) ;
370294
371295 // Assert
372296 Assert . NotNull ( deserializedModel ) ;
373297 Assert . Equal ( originalModel . DateTimeProperty , deserializedModel . DateTimeProperty ) ;
374- Assert . Null ( deserializedModel . NullableDateTimeProperty ) ;
298+ Assert . Equal ( originalModel . NullableDateTimeProperty , deserializedModel . NullableDateTimeProperty ) ;
375299 Assert . Equal ( originalModel . DateTimeOffsetProperty , deserializedModel . DateTimeOffsetProperty ) ;
376- Assert . Null ( deserializedModel . NullableDateTimeOffsetProperty ) ;
300+ Assert . Equal ( originalModel . NullableDateTimeOffsetProperty , deserializedModel . NullableDateTimeOffsetProperty ) ;
377301 Assert . Equal ( expectedJson , json ) ;
378302 }
379303}
0 commit comments