views:

37

answers:

1

When using Excel (2003) to provide data for my unit tests it seems to think that when a cell has TRUE / FALSE value that it is null when there has been no preceding cell values e.g.

 if (TestContext.DataRow["SatisfactionExtremelySatisfied"] != DBNull.Value)
      model.SatisfactionExtremelySatisfied = (bool)TestContext.DataRow
      ["SatisfactionExtremelySatisfied"];

Sample Excel Data

DataRow  SatisfactionExtremelySatisfied
0
1
2                 TRUE
3                 TRUE

When reading the test data using OLEDB the cells with TRUE hold no value (when inspected in debug) but when the preceding cells have the value FALSE entered it correctly gets the values TRUE.

Am I missing something?

+2  A: 

Simplify.

Save the excel spreadsheet as a plain text .csv file, and have your test framework read that. Otherwise, you're complicating your tests by troubleshooting the nuances of reading from Excel.

Bruce McGee
Thanks a million Bruce, working correctly now!
David