Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateOnly Extension demonstration #610

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Changes from all commits
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
49 changes: 49 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue608Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.ContentModel.Conversion;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using System;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue608Tests
{
#if CORE
public class TestClass
{
public DateOnly DateOfBirth { get; set; }
}

[Fact]
public void Verify()
{
TestClass instance = new()
{
DateOfBirth = DateOnly.Parse("2024-01-22")
};

var serializer = new ConfigurationContainer().UseAutoFormatting()
.UseOptimizedNamespaces()
.Type<DateOnly>()
.Register()
.Converter()
.Using(DateOnlyConverter.Default)
.ForTesting();

serializer.Cycle(instance).Should().BeEquivalentTo(instance);
}

sealed class DateOnlyConverter : ConverterBase<DateOnly>
{
public static DateOnlyConverter Default { get; } = new();

DateOnlyConverter() {}

public override DateOnly Parse(string data) => DateOnly.Parse(data);

public override string Format(DateOnly instance) => instance.ToString();
}
#endif
}
}
Loading