Does MS Test default to equal comparison?

I want to check for example

int orderId = myRepository.SubmitOrder(orderA);

orderB = myRepository.GetOrder(orderId);

Assert.AreEqual(orderA, orderB); // fail

Obviously, I need a comparison of the values ​​here, but I don't want to provide an overridden implementation of Equals for all my classes solely for testing (this would be useless in the rest of the application).

Is there a generic method provided that just checks each field using reflection? Or, if not, can you write your own?

EDIT . It seems that people do not understand the meaning. I do not want to write my own comparison logic. This will require hundreds of lines of additional code. I'm looking for something like a generic

bool ContainSameValues<T>(T t1, T t2)

which recursively uses reflection to stretch all values ​​to T.

. , - , ()

+1
3

- :

Assert.AreEqual(orderA.ID, orderB.ID);    
Assert.AreEqual(orderA.CustomerID, orderB.CustomerID);
Assert.AreEqual(orderA.OrderDate, orderB.OrderDate);
+1

Assert , ( ). Assert, ?

:

public static class MyAssertions
{
    public static void AreOrdersEqual(Order a, Order b)
    {
        if (!OrdersAreEqual) // your comparison logic here
           Assert.Fail("Orders arent equal");           
    }
}

:

MyAssertions.AreOrdersEqual(orderA, orderB)
0

IComparable ( ICompare?) Order.method.

-2

All Articles