You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FluentAssertions等效比较时IMemberInfo无Name属性问题咨询

你遇到的是FluentAssertions 6.x版本的API破坏性变更导致的问题,既不是文档笔误,也不需要导入额外命名空间:

  • 5.x及更早版本的IMemberInfo接口直接暴露Name属性,公开示例多基于该版本编写
  • 6.x版本重构了等效性比较相关的API,原Name属性被移动到IMemberInfo.SelectedMemberInfo属性下

你可以根据需求选择两种解决方式:

  1. 精准匹配当前层级的成员名称,不受嵌套层级影响:
orderDto.Should().BeEquivalentTo(order, options => options
    .Using<DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1.Seconds()))
    .When(info => info.SelectedMemberInfo.Name == "Date"));
  1. 匹配完整成员路径(适合嵌套对象字段筛选场景),直接使用Path属性:
// 根层级Date字段直接写"Date",嵌套字段需要写全路径,例如"Order.CreateDate"
orderDto.Should().BeEquivalentTo(order, options => options
    .Using<DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1.Seconds()))
    .When(info => info.Path == "Date"));

内容的提问来源于stack exchange,提问作者GKalnytskyi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 17:24:06