Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

Compare lists of same DTOs with different size using C# Fluent Assertions

I am having this issue when I have two lists containing the same object type but with different sizes. I want to make sure they are being checked (one is sub list of the other for example) based on the all of the properties of the given DTO for example:

public class Student
{
    public int? id { get; set; }
    public string? name { get; set; }
}

And I have two lists for example:

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"}
};

So my question is how can I make an assertion with Fluent Assertion that secondList is a sub list of firstList using deep compare making sure all the properties of an objects are compared to each other.

Thank you for your time and attention!

question from:https://stackoverflow.com/questions/65848443/compare-lists-of-same-dtos-with-different-size-using-c-sharp-fluent-assertions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...