Here’s a method I need to unit test:
void Do(IEnumerable<string> items, TextWriter tw){
foreach(var item in items) { tw.WriteLine(item); }
}
How can I configure a mock of TextWriter to verify that certain arguments are passed to the same method (WriteLine) in a certain order ?
[Test]
public void Test(){
var mock = new Mock<TextWriter>();
mock.Setup( ??? ); //check that WriteLine is called 3 times,
//with arguments "aa","bb","cc", in that order.
Do(new[]{"aa", "bb", "cc"}, mock);
mock.Verify();
}
You can use Callback to verify passed parameter for each call: