-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add source generator tests for GuidIds
- Loading branch information
1 parent
12f7728
commit 8498584
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
test/StronglyTypedIds.IntegrationTests/SystemTextJsonSerializerContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#if NET6_0_OR_GREATER | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using StronglyTypedIds.IntegrationTests.Types; | ||
|
||
namespace StronglyTypedIds.IntegrationTests; | ||
|
||
[JsonSerializable(typeof(GuidId1))] | ||
[JsonSerializable(typeof(ConvertersGuidId))] | ||
[JsonSerializable(typeof(ConvertersGuidId2))] | ||
[JsonSerializable(typeof(GuidIdTests.TypeWithDictionaryKeys))] | ||
internal partial class SystemTextJsonSerializerContext : JsonSerializerContext | ||
{ | ||
internal static SystemTextJsonSerializerContext Custom | ||
=> new(new JsonSerializerOptions | ||
{ | ||
Converters = | ||
{ | ||
new GuidId1.GuidId1SystemTextJsonConverter(), | ||
new ConvertersGuidId.ConvertersGuidIdSystemTextJsonConverter(), | ||
new ConvertersGuidId2.ConvertersGuidId2SystemTextJsonConverter(), | ||
} | ||
}); | ||
|
||
internal static SystemTextJsonSerializerContext Web | ||
=> new(new JsonSerializerOptions() | ||
{ | ||
WriteIndented = true, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
Converters = | ||
{ | ||
new GuidId1.GuidId1SystemTextJsonConverter(), | ||
new ConvertersGuidId.ConvertersGuidIdSystemTextJsonConverter(), | ||
new ConvertersGuidId2.ConvertersGuidId2SystemTextJsonConverter(), | ||
} | ||
}); | ||
} | ||
#endif |