0

I have a method like this:

public void ABC(ViewModeL model)
    {
        var dataTable = new DataTable();
        dataTable.Columns.Add("column1", typeof(int));
        dataTable.Columns.Add("column2", typeof(int));                     
        var dr = dataTable.NewRow();
        dr["column1"] = 2;
        dr["column2"] = 0;
     }

I want to assert on the dataTable object but I am not able to figure out how to do so, since it is created inside the method and also it is not returned by this method. Is it possible to test it using rhino mocks??

Infant Dev
  • 1,659
  • 8
  • 24
  • 48

1 Answers1

0

No, this is a local variable which life-space is ABC() method scope. So thsi is not possible from C# perspectives and even wrong from unit test perspectives such you must not relie on the implementation details.

Perhaps you've provided not entire method body since dataTable variable will die after ABC() method execution, so why you need checking it?

sll
  • 61,540
  • 22
  • 104
  • 156
  • I am calling another method in which i am passing the dataTable object from inside my method. repository.InsertDataTable(dataTable); – Infant Dev Apr 23 '12 at 11:28
  • Hey I refactored my code and created a protected method which will return the DataTable object and tested it indepedently by generating partial mock. Thanks anyway.. :-) – Infant Dev Apr 23 '12 at 12:30