tags:

views:

262

answers:

1

I have a method which retrieves DataTable and iterates each DataRow and stores each row in ArrayList.After the iteration is over it returns the ArrayList.How can i write test case to test the ArrayList ?

Example :

ArrayList =>0 ( {1,personName1,Designation} );

ArrayList =>1 ( {2,personName2,Designation} );

ArrayList =>2 ( {3,personName3,Designation} );

Thanks in advance.

+1  A: 

Perhaps something like the following:

[Test]
public void RetrieveDataTableAndArrayList()
{
    // set up dependencies here
    // i.e. maybe a mocked DataSet which would return your DataTable?

    // an instance of the class under test
    var sut = new SystemUnderTest(dataSet); 

     // the method that you are testing
    ArrayList result = sut.RetrieveDataTable();

    // verification of results
    DataRow row1 = (DataRow)result[0];
    Assert.AreEqual(1, row1.Field<int>(0));
    Assert.AreEqual("personName1", row1.Field<string>(1));
    Assert.AreEqual("Designation", row1.Field<string>(2));
    // ... and so on
}
jpoh