collection 比较失败时在测试输出中打印任意 属性 值

Print arbitrary property value in test output when collection comparison fails

当我使用 .BeEquivalentTo() 比较 collections 和 objects 并且这些 collections 中的属性不匹配时,我得到类似这样的错误输出:

Expected item[8].DaysExpiredMessage to be 
"In 8 days", but 
"In 9 days" differs near "9 d" (index 3).

但是,通过索引引用 collection 项目对调试测试没有多大帮助。

是否可以包含 object 中的其他一些 属性,(例如,我的 collection 中的 object 具有独特的 "Id" 属性) 在测试输出中,所以我可以在查看失败时清楚地识别项目?

不,很遗憾不是。这只是意味着您正在比较的集合的索引 8 处的项目有一个 属性 缺少该值。