【发布时间】:2016-01-28 01:42:09
【问题描述】:
我尝试使用 FluentAssertions 来检查我的 UnitTest,项目列表中的属性类型是否属于某种类型。
myObj.Items.OfType<TypeA>().Single()
.MyProperty1.GetType()
.Should().BeOfType<TypeB>();
很遗憾,我的测试失败并显示以下错误消息:
预期的类型是 B型, 但找到了 System.RuntimeType。
为什么说它找到了System.RuntimeType?
我用调试器验证了MyProperty1是TypeB类型,它是……我用.BeOfType<>错了吗?
【问题讨论】:
-
你能跳过 .GetType() 吗?您问的不是 MyProperty1 的类型,而是类型的类型。它太深了 1 级。
标签: c# .net unit-testing nunit fluent-assertions