FrenkyB FrenkyB - 4 months ago 59
C# Question

Compare collection with mock collection

I am unit testing one of my functionalities. Results are OK, but collections of result from method are of type

, collection for comparison is of type
. That is why test always fails, because comparison between the two is not correct.

Is there a way I can override default comparison between collections?

Results are of type Position, which implements this interface:

public interface IPosition
char HorizontalPosition { get;}
int VerticalPosition { get; }

But mock collection is of type


You have to modify the collections:

var positions = new List<Position>();
var mocks = new List<Mock<IPosition>>();

YourComparisonMethod(positions.Cast<IPosition>(), mocks.Select(m => m.Object));