Skip to content

Tests: Coverage for JsonDateTimeFormat attribute behavior and DateTimeConverterResolver#8

Merged
ScarletKuro merged 3 commits intomasterfrom
copilot/add-reflection-based-tests
Jan 16, 2026
Merged

Tests: Coverage for JsonDateTimeFormat attribute behavior and DateTimeConverterResolver#8
ScarletKuro merged 3 commits intomasterfrom
copilot/add-reflection-based-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 16, 2026

Adds missing test coverage demonstrating that [JsonDateTimeFormat] requires DateTimeConverterResolver to function, and increases coverage of DateTimeConverterResolver constructors and fallback paths.

Changes

New test file: ReflectionBasedTests.JsonDateTimeFormat.cs

  • Verifies [JsonDateTimeFormat] is ignored in reflection-based serialization without DateTimeConverterResolver
  • Demonstrates default formats are used instead of attribute-specified formats

Enhanced: SourceGeneratorBasedTests.JsonDateTimeFormat.cs

  • Added tests showing source generators ignore [JsonDateTimeFormat] without DateTimeConverterResolver
  • Covers both single-parameter and context-based serialization paths

New test file: DateTimeConverterResolverTests.cs

  • Covers parameterless DateTimeConverterResolver() constructor
  • Covers DateTimeConverterResolver(JsonSerializerOptions) constructor
  • Tests GetTypeInfo(Type) fallback path when _source is null
  • Tests GetTypeInfo(Type) when _source is JsonSerializerContext vs other resolvers

Example

// Without DateTimeConverterResolver, custom format is ignored
var options = new JsonSerializerOptions { WriteIndented = true };
var model = new ModelWithAttribute { DateTimeProperty = new DateTime(2023, 10, 1, 12, 0, 0, DateTimeKind.Utc) };
var json = JsonSerializer.Serialize(model, options);
// Result: "2023-10-01T12:00:00Z" (default format, not custom "yyyy-MM-ddTHH:mm:ss")

// With DateTimeConverterResolver, custom format is applied
var resolverOptions = new JsonSerializerOptions
{
    TypeInfoResolver = new DateTimeConverterResolver(ResolverContext.Default)
};
json = JsonSerializer.Serialize(model, resolverOptions);
// Result: "2023-10-01T12:00:00" (custom format from attribute)
Original prompt

I think we need to add
ReflectionBasedTests.JsonDateTimeFormat.cs
that verifies that [JsonDateTimeFormat("xxx)] verifies that reflection based serlize / deserlize doesn't work with it, and no DateTimeConverterResolver should be used.

I also would add additional tests to SourceGeneratorBasedTests.JsonDateTimeFormat.cs that shows that without using DateTimeConverterResolver it doesn't work


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 16, 2026 14:55
…rator scenarios

Co-authored-by: ScarletKuro <19953225+ScarletKuro@users.noreply.github.com>
Co-authored-by: ScarletKuro <19953225+ScarletKuro@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for JsonDateTimeFormat serialization behavior Add test coverage for JsonDateTimeFormat attribute behavior and DateTimeConverterResolver Jan 16, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.07%. Comparing base (709d47b) to head (76f5f83).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master       #8      +/-   ##
==========================================
+ Coverage   92.30%   98.07%   +5.76%     
==========================================
  Files          13       13              
  Lines         156      156              
  Branches       35       35              
==========================================
+ Hits          144      153       +9     
+ Misses          7        1       -6     
+ Partials        5        2       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copilot AI requested a review from ScarletKuro January 16, 2026 15:06
@ScarletKuro ScarletKuro marked this pull request as ready for review January 16, 2026 15:06
@ScarletKuro ScarletKuro changed the title Add test coverage for JsonDateTimeFormat attribute behavior and DateTimeConverterResolver Tests: Coverage for JsonDateTimeFormat attribute behavior and DateTimeConverterResolver Jan 16, 2026
@ScarletKuro ScarletKuro merged commit 67ce54f into master Jan 16, 2026
3 checks passed
@ScarletKuro ScarletKuro deleted the copilot/add-reflection-based-tests branch January 16, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants