-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: when using
SET_INITIAL_DATE_IF_NULL
in STJ only set MinValue i…
…f json value is not nullable i think, this was the initial intention behind the converters? and there's no older/existing test that fails, so I think it's fine that way note that this does _NOT_ change the behaviour of the newtonsoft converters!
- Loading branch information
Konstantin
committed
Nov 20, 2024
1 parent
e3f8a10
commit 39bdfa7
Showing
3 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
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
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,78 @@ | ||
using System; | ||
using BO4E.meta.LenientConverters; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace TestBO4E; | ||
|
||
[TestClass] | ||
public class TestNullableDateTimeOffsetConverter | ||
{ | ||
public class ClassWithNullableDateTimeOffset | ||
{ | ||
public DateTimeOffset? Foo { get; set; } | ||
} | ||
|
||
[TestMethod] | ||
public void Test_Nullable_DateTimeOffset_is_not_set_to_min_value() | ||
{ | ||
const string jsonString = "{\"Foo\":null}"; | ||
var lenientParsing = LenientParsing.SET_INITIAL_DATE_IF_NULL | LenientParsing.DATE_TIME; | ||
var obj = System.Text.Json.JsonSerializer.Deserialize<ClassWithNullableDateTimeOffset>( | ||
jsonString, | ||
lenientParsing.GetJsonSerializerOptions() | ||
); | ||
obj.Foo.Should().BeNull(); | ||
} | ||
|
||
public class ClassWithNonNullableDateTimeOffset | ||
{ | ||
public DateTimeOffset Foo { get; set; } | ||
} | ||
|
||
[TestMethod] | ||
public void Test_NonNullable_DateTimeOffset_is_set_to_min_value() | ||
{ | ||
const string jsonString = "{\"Foo\":null}"; | ||
var lenientParsing = LenientParsing.SET_INITIAL_DATE_IF_NULL | LenientParsing.DATE_TIME; | ||
var obj = System.Text.Json.JsonSerializer.Deserialize<ClassWithNonNullableDateTimeOffset>( | ||
jsonString, | ||
lenientParsing.GetJsonSerializerOptions() | ||
); | ||
obj.Foo.Should().Be(DateTimeOffset.MinValue); | ||
} | ||
|
||
public class ClassWithNullableDateTime | ||
{ | ||
public DateTime? Foo { get; set; } | ||
} | ||
|
||
[TestMethod] | ||
public void Test_Nullable_DateTime_is_not_set_to_min_value() | ||
{ | ||
const string jsonString = "{\"Foo\":null}"; | ||
var lenientParsing = LenientParsing.SET_INITIAL_DATE_IF_NULL | LenientParsing.DATE_TIME; | ||
var obj = System.Text.Json.JsonSerializer.Deserialize<ClassWithNullableDateTime>( | ||
jsonString, | ||
lenientParsing.GetJsonSerializerOptions() | ||
); | ||
obj.Foo.Should().BeNull(); | ||
} | ||
|
||
public class ClassWithNonNullableDateTime | ||
{ | ||
public DateTime Foo { get; set; } | ||
} | ||
|
||
[TestMethod] | ||
public void Test_NonNullable_DateTime_is_set_to_min_value() | ||
{ | ||
const string jsonString = "{\"Foo\":null}"; | ||
var lenientParsing = LenientParsing.SET_INITIAL_DATE_IF_NULL | LenientParsing.DATE_TIME; | ||
var obj = System.Text.Json.JsonSerializer.Deserialize<ClassWithNonNullableDateTime>( | ||
jsonString, | ||
lenientParsing.GetJsonSerializerOptions() | ||
); | ||
obj.Foo.Should().Be(DateTime.MinValue); | ||
} | ||
} |