What I'm trying to do
I've just set up a test to ensure that a NodaTime LocalDateTime
is mapped to a .NET DateTime
, retaining the same date and time values. I'm using FluentAssertions' ShouldBeEquivalentTo
method to compare the corresponding property values.
[TestClass]
public class LocalDateTimeMapping
{
[TestMethod]
public void RetainsComponentValues()
{
var nodatimeTime = new LocalDateTime();
var dotnetTime = nodatimeTime.ToDateTimeUnspecified();
dotnetTime.ShouldBeEquivalentTo(nodatimeTime,
o => o
.Including(d => d.Year)
.Including(d => d.Month)
.Including(d => d.Day)
.Including(d => d.Hour)
.Including(d => d.Minute)
.Including(d => d.Second)
.Including(d => d.Millisecond)
);
}
}
The problem
The test is failing:
Expected subject to be 01/01/1970 00:00:00, but found <1970-01-01>.
With configuration:
- Select property System.DateTime.Year
- Select property System.DateTime.Month
- Select property System.DateTime.Day
- Select property System.DateTime.Hour
- Select property System.DateTime.Minute
- Select property System.DateTime.Second
- Select property System.DateTime.Millisecond
- Match property by name (or throw)
- Invoke Action<DateTime> when info.RuntimeType.IsSameOrInherits(System.DateTime)
- Invoke Action<String> when info.RuntimeType.IsSameOrInherits(System.String)
I don't know what the last two lines mean.
What I've tried
- Running the test in the debugger to confirm that the values of each of these were the same.
- Seeing if the problem was a specific property by removing the
Include
s for the different properties. - Basing the configuration on
EquivalencyAssertionOptions<DateTime>.Empty()
to ensure that no extra checks or properties were implicitly involved. Simplifying it all down to just the following.
dotnetTime.ShouldBeEquivalentTo(nodatimeTime, o => EquivalencyAssertionOptions<DateTime>.Empty() );
DateTime
. Does that mean there is a bug in FluentAssertions, or am I misunderstanding what you mean? – EncasementLocalDateTime
, which is also astruct
. Anyway, thanks for clarifying that this is by design. I suggest this be treated as a design flaw or bug since I think it's unintuitive. It'd be interesting to see what other users of the library think. – Encasementstruct
, it's because we treat DateTime as a primitive for which FA contains dedicated assertions. – Drub