C# CollectionAssert-断言集合的集合

C# CollectionAssert-断言集合的集合,c#,nunit,assert,C#,Nunit,Assert,我有以下资料: internal class Payments { public DateTime date { get; set; } public double amount { get; set; } public string currency { get; set; } public override string ToString() { string[] members = new string[] {

我有以下资料:

internal class Payments
{
    public DateTime date { get; set; }
    public double amount { get; set; }
    public string currency { get; set; }

    public override string ToString()
    {
        string[] members = new string[] {
            "date = " + date,
            "amount = " + amount,
            "currency = " + currency,
        };

        return string.Join( ", ", members );
    }
}


为了成功进行比较,您需要实现某种“深度”等价性检查,例如覆盖
Equals
GetHashCode
和/或实现
IEqualityComparer
接口。另外,我不确定您试图用第三个参数
typeof…
实现什么?第三个参数只是测试失败输出的格式化程序。只想在断言失败时调用类型。
internal class Customer
{
    public Guid id { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public string email { get; set; }
    public string country { get; set; }
    public string ip_address { get; set; }
    public List<Payments> payments { get; set; }

    public override string ToString()
    {
        string[] members = new string[] {
            "id = " + id,
            "first_name = " + first_name,
            "last_name = " + last_name,
            "email = " + email,
            "country = " + country,
            "ip_address = " + ip_address,
            "payments = <" + payments.ToString() + ">",
        };

        return string.Join( ", ", members );
    }
}
CollectionAssert.AreEquivalent(
    customersListA,
    customersListB,
    typeof(List<Customer>).ToString()
    );
Assert.AreEqual(
    customers.OrderBy( c => c.id ).ToString(),
    _allData.OrderBy( c => c.id ).ToString(),
    typeof( List<Customer> ).ToString()
    );