Answer the question
In order to leave comments, you need to log in
Displaying object properties in NUnit
Using NUnit I create a test to compare two arrays:
Class1[] array1;
Class1[] array2;
...
Assert.That(array1, Is.EqualTo(array2).Using(new Class1Comparer()));
Tester.Test_2861:
Expected and actual are both <Class1[161]> Values differ at index [0]
Expected: <Class1>
But was: <Class1>
Expected: {X: 10, Y: "Hi"}
But was: {X: 10, Y: "Hello"}
Answer the question
In order to leave comments, you need to log in
The message displays the text returned by ToString().
If Class1 cannot be changed, then you can create a "wrapper" class in which you can override the ToString() method so that it displays the necessary information. You will also have to use another class instead of Class1Comparer that will compare "wrappers"
class Class1Wrapper {
public readonly Class1 Wrapped;
public Class1Wrapper(Class1 toWrap) {
Wrapperd = toWrap;
}
public override string ToString() {
return string.Format("X: {0}, Y : {1}", Wrapped.X, Wrapped.Y);
}
public static Class1Wrapper Wrap(Class1 toWrap) {
return new Class1Wrapper(toWrap) ;
}
}
Дальше в тесте
Assert.That(templateSeries.getElements().Select(Class1Wrapper.Wrap).ToArray(),
Is.EqualTo(resultSeries.getElements().Select(Class1Wrapper.Wrap).ToArray())
.Using(new Class1WrapperComparer()));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question