CollectionAssert - 断言集合的集合

时间:2015-05-11 02:09:30

标签: 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[] {
            "date = " + date,
            "amount = " + amount,
            "currency = " + currency,
        };

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

...

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()
    );

我怀疑是因为PaymentsList,所以它只针对指针进行断言。有没有办法让NUnit断言List<Payments>的内容而不是指针?

我看到了similar question,但其中一位NUnit的作者说that particular problem was fixed

注意:暂时,因为我已覆盖ToString(),我正在做:

Assert.AreEqual(
    customers.OrderBy( c => c.id ).ToString(),
    _allData.OrderBy( c => c.id ).ToString(),
    typeof( List<Customer> ).ToString()
    );

0 个答案:

没有答案