我有两门课:
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"));
显然,我可以为集合中的每个 Class B 重复这个步骤。然而,我正在寻找一种方法来排除所有的 ID (而不是对每个元素进行排除)。
但是,如果我删除了[0]索引器,断言就会失败。
这可能吗?