public void UpdateWithoutPrimaryKeyShouldFail() { DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("id=@0", 1313); //Verify we got the value we expected Assert.AreEqual("A", obj.Rows[0]["middle_initial"], "Verifying Default Test Value"); //Remove the primary key obj.Rows[0][obj.PrimaryKey] = null; //Now Change the value obj.Rows[0]["middle_initial"] = "Z"; Assert.Throws<NoPrimaryKeyException>(delegate { obj.Update(); }); //Make sure it didn't update the value. obj.Where("id=@0", 1313); Assert.AreEqual("A", obj.Rows[0]["middle_initial"]); }
public void UpdateThreeRowsOneColumn() { DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("id IN (1313,1315,1327)"); // //NOTE: This is not the best use of LINQ // This would be alot more effectent/faster in a single loop with an if statement on ID //Change the columns DBRow dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1313; }); dbrow["middle_initial"] = "X"; dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1315; }); dbrow["middle_initial"] = "Y"; dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1327; }); dbrow["middle_initial"] = "Z"; //Update obj.Update(); //Now Verify obj.Where("id IN (1313,1315,1327)"); dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1313; }); Assert.AreEqual("X", dbrow["middle_initial"], "Test Change"); dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1315; }); Assert.AreEqual("Y", dbrow["middle_initial"], "Test Change"); dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1327; }); Assert.AreEqual("Z", dbrow["middle_initial"], "Test Change"); //Reset the values obj.Where("id IN (1313,1315,1327)"); dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1313; }); dbrow["middle_initial"] = "A"; dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1315; }); dbrow["middle_initial"] = "B"; dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1327; }); dbrow["middle_initial"] = "C"; //Update obj.Update(); //Verify reset obj.Where("id IN (1313,1315,1327)"); dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1313; }); Assert.AreEqual("A", dbrow["middle_initial"], "Verify Reset to Test Value"); dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1315; }); Assert.AreEqual("B", dbrow["middle_initial"], "Verify Reset to Test Value"); dbrow = obj.Rows.Single(delegate(DBRow row) { return (int)row["id"] == 1327; }); Assert.AreEqual("C", dbrow["middle_initial"], "Verify Reset to Test Value"); }
public void UpdateWithBadColumnName() { DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("id=@0", 1313); obj.Columns.Add("badcolumn"); //Add a column that won't exist in the row //Verify we got the value we expected Assert.AreEqual("A", obj.Rows[0]["middle_initial"]); //Now Change the value obj.Rows[0]["middle_initial"] = "Q"; obj.Update(); //Get it fresh from the DB. obj.Where("id=@0", 1313); //Verify we got the value we expected Assert.AreEqual("Q", obj.Rows[0]["middle_initial"], "Verify Value Change"); //Now Change it back obj.Rows[0]["middle_initial"] = "A"; obj.Update(); //Verify it reset obj.Where("id=@0", 1313); Assert.AreEqual("A", obj.Rows[0]["middle_initial"], "Verify Test Value Reset"); }
public void UpdateOneRowOneColumn() { DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("id=@0", 1313); //Verify we got the value we expected Assert.AreEqual("A", obj.Rows[0]["middle_initial"], "Verifying Default Test Value"); //Now Change the value obj.Rows[0]["middle_initial"] = "Z"; obj.Update(); //Get it fresh from the DB. obj.Where("id=@0", 1313); //Verify we got the value we expected Assert.AreEqual("Z", obj.Rows[0]["middle_initial"], "Testing Change"); //Now Change it back obj.Rows[0]["middle_initial"] = "A"; obj.Update(); obj.Where("id=@0", 1313); //Verify we got the value we expected Assert.AreEqual("A", obj.Rows[0]["middle_initial"], "Verifying Value is Reset to Test Value"); }