# 比較MbUnit中兩個相同的對象

Assert.AreSame(RawDataRow, result);


Expected Value & Actual Value : {RawDataRow: CentreID = "CentreID1",
CentreLearnerRef = "CentreLearnerRef1",
ContactID = 1, DOB = 2010-05-05T00:00:00.0000000,
Email = "Email1", ErrorCodes = "ErrorCodes1",
ErrorDescription = "ErrorDescription1", FirstName = "FirstName1"}


## 最佳答案

There are several solutions. One of them is Coppermill's solution: you may want to implement a structural equality comparer based on reflection. But MbUnit has already a built-in feature like that. It's called StructuralEqualityComparer and it's very easy to use. So why reinventing the wheel?

Assert.AreSame(RawDataRow, result, new StructuralEqualityComparer
{
{ x => x.CentreID },
{ x => x.CentreLearnerRef, (a, b) => a.Equals(b, StringComparison.OrdinalIgnoreCase) },
{ x => x.ContactID },
//You can customize completely the comparison process...
});


Anyway, I suggest you read that article: http://interfacingreality.blogspot.com/2009/09/equality-assertions-in-mbunit-v3.html