我有两个类:如何使用排除在FluentAssertions集合中的属性?
public class ClassA
{
public int? ID {get; set;}
public IEnumerable<ClassB> Children {get; set;}
}
public class ClassB
{
public int? ID {get; set;}
public string Name {get; set;}
}
我想用流利的断言来比较ClassA的实例。但是我想忽略这些ID(因为这些ID在保存后将被分配)。
我知道我能做到这一点:
expectedA.ShouldBeEquivalentTo(actualA, options => options.Excluding(x => x.PropertyPath == "Children[0].ID"));
,我可以在收集明显重复每个ClassB的。不过,我正在寻找一种方法来排除所有的ID(而不是对每个元素进行排除)。
我读过this question但是,如果我删除[0]索引器断言失败。
这可能吗?
我打算将这一个标记为答案,因为扩展方法中的正则表达式是我最后使用的方法 – Liath
在更新版本的FluentAssertions中,这有何变化?我不确定'PropertyPath'仍然存在 – superjos