John Hammond

John Hammond

  • NA
  • 16
  • 8.9k

NUnit Testcase with an import file for my data

Aug 3 2015 11:33 AM
With the testcase below how do I import data from an external source like xml file or excel to test my properties without the hardcode of the data below.Any help will be appreciated. Thanks JB
 
[TestCase(true)]
public void AddNewCategory(bool expectedResult)
{
//Add new Category
bool results = true;
string sqlStr = String.Empty;
ODP_DataClient service = new ODP_DataClient();
service.ExecuteNonQuery(dbConn, "DELETE FROM WSINTRA_TBL_MAILSVCS_KEY WHERE C_NAME = 'TestPlate' ");
MailsvcMenu cat = new MailsvcMenu();
cat.Id = "57";
cat.Category = "2";
cat.CategoryName = "TestPlate";
cat.Type = "1";
cat.RateId = "2";
cat.Stat = "A";
List<string> list = MailAdmin.CategoryUpdate(cat);
results = results && list.Count.Equals(0);
DataSet data = service.GetDataSet(dbConn, "SELECT COUNT(*) ROW_COUNT from WSINTRA_TBL_MAILSVCS_KEY WHERE ID = " + "'" + cat.Id + "'");
DataRow row = data.Tables[0].Rows[0];
int count = Convert.ToInt32(row["ROW_COUNT"]);
results = results && count.Equals(1);
Assert.IsTrue(results && expectedResult);
}