public void ExecuteNonQueryTestUsingQuery() { SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=Rooster;User Id=sa;Password=sa_2008;"); try { connection.Open(); } catch (Exception ex) { Assert.Fail(ex.Message, ex); return; } SQLDataAdaptor target = new SQLDataAdaptor(connection); string command = "insert into USER_LOGIN_HISTORY ( [USER_ID] , LOGIN_DATE_TIME) values ( 'gto','2012-09-29 19:30:00')"; int expected = 1; int actual; actual = target.ExecuteNonQuery(command); try { Assert.AreEqual(expected, actual); } catch (Exception ex) { Assert.Fail(ex.Message, ex); } }
public void ExecuteNonQueryTestUsingCommandObj() { SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=Rooster;User Id=sa;Password=sa_2008;"); try { connection.Open(); } catch (Exception ex) { Assert.Fail(ex.Message, ex); return; } SQLDataAdaptor target = new SQLDataAdaptor(connection); string query = "insert into USER_LOGIN_HISTORY ( [USER_ID] , LOGIN_DATE_TIME) values ( 'gto','2012-09-29 19:34:00')"; SqlCommand command = new SqlCommand(query); int expected = 1; int actual; try { actual = target.ExecuteNonQuery(command); Assert.AreEqual(expected, actual); } catch (Exception ex) { Assert.Fail(ex.Message, ex); } }
public void ExecuteReaderTestUsingQuery() { SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=Rooster;User Id=sa;Password=sa_2008;"); try { connection.Open(); } catch (Exception ex) { Assert.Fail(ex.Message, ex); return; } SQLDataAdaptor target = new SQLDataAdaptor(connection); string command = "Select * from USER_LOGIN_HISTORY"; try { var table = target.ExecuteReader(command); if (table.Rows.Count > 0) { foreach (DataRow row in table.Rows) { Debug.WriteLine("User ID : " + row["USER_ID"].ToString()); } } } catch (Exception ex) { Assert.Fail("Test Failed \n" + ex.Message, ex); } }