31 July 2013

When Testing Data Access with _SP and DataSet

Here's how I perform U-Test whenever I develop data-driven apps and I still need to deal with ADO.NET:

//Arrange
var con = new SqlConnection() //connection goes here
var cmd = new SqlCommand() //command object goes here
var ds = new DataSet() //dataset goes here
var da = new SqlDataAdapter() //adapter goes here

//Act
cmd.CommandType = CommandType. //Procedure call goes here
try {
da.Fill(ds);
}

//Assert
catch {
Assert.Fail("Exception occured");
}

Next, Assert that the following returns true:

ds.Tables.Count == 1
dt.Columns.Count == 8 // (if I have 8 columns)
dt.Columns.IndexOf("Student Name") > -1 // (to identify that the column exists)
dt.Columns["Salary"].DataType == typeof (decimal) //(to make sure it's in correct data type)
dt.Rows.Count <= 1 //(of course, there should only be 1 row or 0 returned)


 I'm still looking for ways to improve my U-Test so I could cover "most" of the expectations and solidify my codes for easier debugging and maintenance.






No comments:

Post a Comment