Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions Adyen.Test/Core/Converters/DateOnlyNullableJsonConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DateOnlyNullableJsonConverterTest
private readonly DateOnlyNullableJsonConverter _converter = new DateOnlyNullableJsonConverter();

[TestMethod]
public void Given_DateWithDashes_yyyy_MM_dd_When_Read_Then_ReturnsCorrectDate()
public void Given_DateWithDashes_yyyy_MM_dd_When_Read_Then_Returns_Correct_DateOnly()
{
// Arrange
string json = "\"2025-12-25\"";
Expand All @@ -25,7 +25,7 @@ public void Given_DateWithDashes_yyyy_MM_dd_When_Read_Then_ReturnsCorrectDate()
}

[TestMethod]
public void Given_Date_yyyyMMdd_When_Read_Then_ReturnsCorrectDate()
public void Given_DateOnly_yyyyMMdd_When_Read_Then_Returns_Correct_DateOnly()
{
// Arrange
string json = "\"20251225\"";
Expand All @@ -40,23 +40,22 @@ public void Given_Date_yyyyMMdd_When_Read_Then_ReturnsCorrectDate()
}

[TestMethod]
public void Given_WrongFormatDateOnlyString_When_Read_Then_ThrowsNotSupportedException()
public void Given_InvalidFormat_DateOnlyString_When_Read_Then_Returns_Null()
{
// Arrange
string json = "\"25-12-2025\""; // Incorrect format dd-MM-yyyy
string json = "\"25-12-2025\""; // Invalid format "yyyy'-'MM'-'dd" or "yyyyMMdd"

// Act
Utf8JsonReader reader = new Utf8JsonReader(System.Text.Encoding.UTF8.GetBytes(json));
reader.Read();
var result = _converter.Read(ref reader, typeof(DateOnly), new JsonSerializerOptions());

// Assert
Assert.ThrowsException<NotSupportedException>(() =>
{
var reader = new Utf8JsonReader(System.Text.Encoding.UTF8.GetBytes(json));
reader.Read();
_converter.Read(ref reader, typeof(DateOnly), new JsonSerializerOptions());
});
Assert.IsNull(result);
}

[TestMethod]
public void Given_InvalidDateOnlyString_When_Read_Then_ThrowsJsonException()
public void Given_Invalid_DateOnlyString_When_Read_Then_ThrowsJsonException()
{
// Arrange
string json = "invalid-date";
Expand Down
2 changes: 1 addition & 1 deletion Adyen/Core/Converters/DateOnlyNullableJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DateOnlyNullableJsonConverter : JsonConverter<DateOnly?>
if (DateOnly.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateOnly result))
return result;

throw new NotSupportedException();
return null;
}

/// <summary>
Expand Down