We have many tests in which test data is stored in Excel. I created testmethods where Excel worksheets are linked as a DataSource to TestContext .
For reasons of convenience, I want to update Excel worksheets with test results, so it's easy to see where the data (or system) is wrong.
Things I tried:
Direct write to TestContext.DataRow :
TestContext.DataRow.BeginEdit(); TestContext.DataRow["Result"] = "change"; TestContext.DataRow.EndEdit(); TestContext.DataRow.AcceptChanges();
Result: passes, but no rows are updated in my Excel file.
Update using DataConnection :
string currentRow = TestContext.DataRow["RowId"].ToString(); System.Data.Common.DbCommand cmd = TestContext.DataConnection.CreateCommand(); cmd.CommandText = String.Format("UPDATE {0} SET {1} = pass WHERE {2} = {3}", sheetName, columnName, "RowId", currentRow); cmd.CommandType = System.Data.CommandType.Text; cmd.ExecuteReader();
Result: System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.
And updating it, changing the DataRow under TestContext :
string currentRow = TestContext.DataRow["RowId"].ToString(); OleDbDataAdapter adapter = new OleDbDataAdapter(); adapter.UpdateCommand = new OleDbCommand(String.Format("UPDATE {0} SET {1} = pass WHERE {2} = {3}", sheetName, columnName, "RowId", currentRow)); adapter.UpdateCommand.Connection = (OleDbConnection)TestContext.DataConnection; adapter.Update(new System.Data.DataRow[] { TestContext.DataRow });
Result: also passes, but no rows are updated in my Excel file.
Has anyone done this before? Or someone tell me where I can be wrong?