Thanks Doron.
The dataTable is fine as I can pass to the MyMethod as input parameter.
Your comments inspired me to find the solution to my problem:
// mock HttpResponse
HttpResponse fakeHttpResponse = Isolate.Fake.Instance<HttpResponse>();
Isolate.WhenCalled <HttpResponse>(delegate() { return HttpContext.Current.Response; }).WillReturn(fakeHttpResponse);
// mock Response.Write()
Isolate.WhenCalled(delegate() { fakeHttpResponse.Write(""); }).IgnoreCall();
Then for verification:
foreach (DataRow row in dataTableForTest.Rows)
{
foreach (DataColumn column in dataTableForTest.Columns)
{
string toWrite = row[column.ColumnName].ToString() + ",";
Isolate.Verify.WasCalledWithExactArguments(
delegate() { fakeHttpResponse.Write(toWrite); });
}
}
The performance issue is resolved as well as it doesn't use the HttpContext.Current.Response.Write().
Lessons I learned:
1) At the time of mocking, we don't need to write the mocking statement several times if that dependency is used in the code several times e.g. my loop scenario
2) At the time of mocking, the input arguments don't matter. At the time of verification, we can verify the input arguments. Having said that this is in contrast with how NMock works as you can specify the expected method arguments when mocking using NMock. NMock syntax seems neater to me to be honest in this case. Maybe a feature for improvement for TypeMock?