c# - 使用 C# Fluent Assertions 比较具有不同大小的相同 DTO 列表
问题描述
当我有两个包含相同对象类型但大小不同的列表时,我遇到了这个问题。我想确保根据给定 DTO 的所有属性检查它们(例如一个是另一个的子列表),例如:
public class Student
{
public int? id { get; set; }
public string? name { get; set; }
}
例如,我有两个列表:
List<Student> firstList = new List<Student>() {
new Student(){ Id = 1, Name="Bill"},
new Student(){ Id = 2, Name="Steve"},
new Student(){ Id = 3, Name="Ram"},
new Student(){ Id = 4, Name="Abdul"}
};
List<Student> secondList = new List<Student>() {
new Student(){ Id = 1, Name="Bill"},
new Student(){ Id = 4, Name="Abdul"}
};
所以我的问题是如何使用 Fluent Assertion 断言 secondList 是 firstList 的子列表,使用深度比较确保对象的所有属性都相互比较。
感谢您的时间和关注!
解决方案
推荐阅读
- powershell - 如何远程运行 New-DfsnRoot
- c# - 如何使用外键访问关系表上不同变量的值
- angular - 视频自动播放器离子
- excel - 为什么在包含 Double 的行上执行 VBA Step Over 会导致溢出错误?
- c# - 指定 ON DELETE NO ACTION 为同一个表创建 3 个外键 - 实体框架
- typescript - 返回类型为非空且基于输入类型
- c# - 限制框架在 c# NetCore 中的 SOAP xml 消息中添加可选标签
- python - 在 TensorFlow Functional API 中保存和加载具有相同图形的多个模型
- android - 在 Xamarin 表单中测量字符串大小 (Android)
- node.js - Nodejs没有运行批处理文件或命令