Verify collection as a method parameter How can I verify that ohterClassMock.MethodToTest() was called with contracts?

That it was called with contract, that have Id = 1 and Param2 = 34 and also with contract2, which has Id = 2 and Param2 = 56.

This is my code:

GoodClass goodClass = new GoodClass(ohterClassMock);
...
var contracts = new List&lt;Contract&gt;();
var contract = new Contract{ Id = 1, Param2 = 34 };
contracts.Add(contract);
var contract2 = new Contract { Id = 2, Param2 = 56 };
contracts.Add(contract2);

goodClass.DoSomething(contracts);

ohterClassMock.Verify(mock =&gt; mock.MethodToTest(It.IsAny&lt;contracts&gt;()));


I know that it can be tested for every item in the collection:

ohterClassMock.Verify(mock =&gt; mock.MethodToTest(It.Is&lt;Contract&gt;(contract =&gt; contract.Id == 1)));
...


but maybe there is some other syntax to call it in one line of code?

Updated:

goodClass.DoSomething(contracts);


calls 

foreach(Contract contract in contracts)
{
   ohterClassMock.MethodToTest(contract);
}
Strictly to answer the question at hand, you have local variables for the individual contracts already, so you can just re-use them:

ohterClassMock.Verify(mock =&gt; mock.MethodToTest(It.Is&lt;Contract&gt;(c =&gt; contract.Equals(c))));
ohterClassMock.Verify(mock =&gt; mock.MethodToTest(It.Is&lt;Contract&gt;(c =&gt; contract2.Equals(c))));


This assumes you have implemented IEquatable&lt;Contract&gt; and/or overridden Object.Equals on your Contract object.

Given the behavior of most test and mocking frameworks, it will probably save you a lot of grief to go ahead and override Object.ToString so that failed tests will print out nicer expected/actual values than the fully-qualified type names.

Also, as an aside, you can create your list with a collection initializer if you do so after building your individual contracts:

var contracts = new List&lt;Contract&gt; { contract, contract2 };


Or, if your method takes in IEnumerable&lt;Contract&gt;, it may be even simpler to use:

var contracts = new [] { contract, contract2 };