public void GetRowsFromDataSheets_With_Null_Connection_Throws_ArgumentNullException() { OleDbConnection nullConnection = null; Assert.That( () => ExcelOleDbHelper.GetRowsFromDataSheets(nullConnection), Throws.InstanceOf <ArgumentNullException>() ); }
public void GetRowsFromDataSheets_Gets_All_Rows_From_All_Data_Sheets(string excelFileName) { OleDbConnection connection = ExcelOleDbHelper.MakeConnection(excelFileName); var rows = ExcelOleDbHelper.GetRowsFromDataSheets(connection); Assert.AreEqual(3, rows.Count()); for (int i = 0; i < rows.Count(); i++) { Assert.AreEqual(String.Format("baz{0}", i + 1), rows.ElementAt(i)["foo"]); Assert.AreEqual(String.Format("qux{0}", i + 1), rows.ElementAt(i)["bar"]); } }
public void GetRowsFromDataSheets_Opens_And_Closes_The_Connection(string excelFileName) { OleDbConnection connection = ExcelOleDbHelper.MakeConnection(excelFileName); //manually open and close the connection to ensure it is closed connection.Open(); connection.Close(); //assert the connection is really closed Assert.AreEqual(ConnectionState.Closed, connection.State); //GetRowsFromDataSheet on a *closed* connection shouldn't throw an exception Assert.That( () => ExcelOleDbHelper.GetRowsFromDataSheets(connection), Throws.Nothing ); //assert that the connection was not left open Assert.AreEqual(ConnectionState.Closed, connection.State); }