+ SqlDataAdapter adapter;
+ SqlDataReader dr;
+ DataSet data;
+ string connectionString = ConnectionManager.Instance.Sql.ConnectionString;
+ SqlConnection conn;
+ EngineConfig engine;
+
+ [SetUp]
+ public void SetUp ()
+ {
+ engine = ConnectionManager.Instance.Sql.EngineConfig;
+ }
+
+ [TearDown]
+ public void TearDown ()
+ {
+ if (adapter != null) {
+ adapter.Dispose ();
+ adapter = null;
+ }
+
+ if (dr != null) {
+ dr.Close ();
+ dr = null;
+ }
+
+ if (conn != null) {
+ conn.Close ();
+ conn = null;
+ }
+ }
+
+ [Test]
+ [Category("NotWorking")]
+ public void Update_DeleteRow ()
+ {
+ conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
+ conn.Open ();
+
+ DataTable dt = new DataTable ();
+ adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
+ SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
+ adapter.DeleteCommand = builder.GetDeleteCommand ();
+ adapter.Fill (dt);
+
+ DateTime now = DateTime.Now;
+
+ DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+ now.Minute, now.Second);
+
+ DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+ now.Minute, now.Second);
+ dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
+
+ try {
+ DataRow newRow = dt.NewRow ();
+ newRow ["id"] = 6002;
+ newRow ["fname"] = "boston";
+ newRow ["dob"] = dob;
+ newRow ["doj"] = doj;
+ newRow ["email"] = "mono@novell.com";
+ dt.Rows.Add (newRow);
+ adapter.Update (dt);
+
+ foreach (DataRow row in dt.Rows)
+ if (((int) row ["id"]) == 6002)
+ row.Delete ();
+ adapter.Update (dt);
+
+ SqlCommand cmd = conn.CreateCommand ();
+ cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
+ dr = cmd.ExecuteReader ();
+ Assert.IsFalse (dr.Read ());
+ dr.Close ();
+ } finally {
+ DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
+ }
+ }
+
+ [Test]
+ [Category("NotWorking")]
+ public void Update_InsertRow ()
+ {
+ conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
+ conn.Open ();
+
+ DataTable dt = new DataTable ();
+ adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
+
+ SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
+ adapter.InsertCommand = builder.GetInsertCommand ();
+ adapter.Fill (dt);
+
+ DateTime now = DateTime.Now;
+
+ DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+ now.Minute, now.Second);
+
+ DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+ now.Minute, now.Second);
+ dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
+
+ try {
+ DataRow newRow = dt.NewRow ();
+ newRow ["id"] = 6002;
+ newRow ["fname"] = "boston";
+ newRow ["dob"] = dob;
+ newRow ["doj"] = doj;
+ newRow ["email"] = "mono@novell.com";
+ dt.Rows.Add (newRow);
+ adapter.Update (dt);
+
+ SqlCommand cmd = conn.CreateCommand ();
+ cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
+ dr = cmd.ExecuteReader ();
+ Assert.IsTrue (dr.Read (), "#A1");
+ Assert.AreEqual (6002, dr.GetValue (0), "#A2");
+ Assert.AreEqual ("boston", dr.GetValue (1), "#A3");
+ Assert.AreEqual (DBNull.Value, dr.GetValue (2), "#A4");
+ Assert.AreEqual (dob, dr.GetValue (3), "#A5");
+ Assert.AreEqual (doj, dr.GetValue (4), "#A6");
+ Assert.AreEqual ("mono@novell.com", dr.GetValue (5), "#A7");
+ Assert.IsFalse (dr.Read (), "#A8");
+ dr.Close ();
+ } finally {
+ DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
+ }
+ }
+
+ [Test]
+ [Category("NotWorking")]
+ public void Update_UpdateRow ()
+ {
+ conn = new SqlConnection (ConnectionManager.Instance.Sql.ConnectionString);
+ conn.Open ();
+
+ DataTable dt = new DataTable ();
+ adapter = new SqlDataAdapter ("SELECT * FROM employee", conn);
+ SqlCommandBuilder builder = new SqlCommandBuilder (adapter);
+ adapter.UpdateCommand = builder.GetUpdateCommand ();
+ adapter.Fill (dt);
+
+ DateTime now = DateTime.Now;
+
+ DateTime doj = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+ now.Minute, now.Second);
+
+ DateTime dob = new DateTime (now.Year, now.Month, now.Day, now.Hour,
+ now.Minute, now.Second);
+ dob.Subtract (new TimeSpan (20 * 365, 0, 0, 0));
+
+ try {
+ DataRow newRow = dt.NewRow ();
+ newRow ["id"] = 6002;
+ newRow ["fname"] = "boston";
+ newRow ["dob"] = dob;
+ newRow ["doj"] = doj;
+ newRow ["email"] = "mono@novell.com";
+ dt.Rows.Add (newRow);
+ adapter.Update (dt);
+
+ foreach (DataRow row in dt.Rows)
+ if (((int) row ["id"]) == 6002)
+ row ["lname"] = "de Icaza";
+ adapter.Update (dt);
+
+ SqlCommand cmd = conn.CreateCommand ();
+ cmd.CommandText = "SELECT id, fname, lname, dob, doj, email FROM employee WHERE id = 6002";
+ dr = cmd.ExecuteReader ();
+ Assert.IsTrue (dr.Read (), "#A1");
+ Assert.AreEqual (6002, dr.GetValue (0), "#A2");
+ Assert.AreEqual ("boston", dr.GetValue (1), "#A3");
+ Assert.AreEqual ("de Icaza", dr.GetValue (2), "#A4");
+ Assert.AreEqual (dob, dr.GetValue (3), "#A5");
+ Assert.AreEqual (doj, dr.GetValue (4), "#A6");
+ Assert.AreEqual ("mono@novell.com", dr.GetValue (5), "#A7");
+ Assert.IsFalse (dr.Read (), "#A8");
+ dr.Close ();
+ } finally {
+ DBHelper.ExecuteSimpleSP (conn, "sp_clean_employee_table");
+ }
+ }