I've been messing around with some of c#9's new features, and I've run into something that's less than fun. If I try to use Should().BeEquivalentTo() on a record with a DateTimeOffset, setting the Using option for DateTimeOffset to use BeCloseTo, the test fails even if the DateTimeOffset is within the allowed precision. Is there a way to get this to work (without changing the record to a class lol)? Thanks much!
Example:
public class ExampleTest
{
[Fact]
public void FunWithRecords()
{
var thing1 = new Thing
{
SomeDate = DateTimeOffset.UtcNow
};
var thing2 = new Thing
{
SomeDate = DateTimeOffset.UtcNow.AddSeconds(2)
};
thing1.Should().BeEquivalentTo(thing2, o =>
o.Using<DateTimeOffset>(ctx =>
ctx.Subject.Should().BeCloseTo(ctx.Expectation, 10000))
.WhenTypeIs<DateTimeOffset>());
}
}
public record Thing
{
public DateTimeOffset SomeDate {get; init;}
}