我正在尝试做的事情
我刚刚设置了一个测试,以确保将 NodaTimeLocalDateTime
映射到 .NET DateTime
,并保留相同的日期和时间值。我正在使用 FluentAssertions 的ShouldBeEquivalentTo
方法来比较相应的属性值。
[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)
);
}
}
问题
测试失败:
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)
我不知道最后两行是什么意思。
我试过的
- 在调试器中运行测试以确认每个值都相同。
Include
通过删除不同属性的 s 来查看问题是否是特定属性。- 基于配置
EquivalencyAssertionOptions<DateTime>.Empty()
确保不隐式涉及额外的检查或属性。 将其简化为以下内容。
dotnetTime.ShouldBeEquivalentTo(nodatimeTime, o => EquivalencyAssertionOptions<DateTime>.Empty() );