public void TestLinq() { DBObject obj = new DBObject(connMy, "users", "id"); obj.Where("id IN (1313,1315,1327)"); var results = from row in obj.Rows where (int)row["id"] == 1313 select row["middle_initial"]; }
public void Teardown() { //Delete all of the records DBObject db = new DBObject(Utility.connMy, "users", "id"); db.Where("true=true"); foreach (DBRow row in db.Rows) { row.Delete(db); } }
public void FindByTwoColumnsInRow() { DBObject db = new DBObject(Utility.connMy, "users", "id"); //Create a row with the propertys we want to find DBRow where = new DBRow(); where["middle_initial"] = "A"; where["last_name"] = "Richards"; //Now find everyone with an A for a middle name. db.Where(where); //Should find 3 rows. Assert.AreEqual(2, db.Rows.Count); //Verify they are the three we expect int found = 0; foreach (DBRow row in db.Rows) { if (1313 == (int)row["id"]) { Assert.AreEqual(row["first_name"], "Chris"); Assert.AreEqual(row["middle_initial"], "A"); Assert.AreEqual(row["last_name"], "Richards"); Assert.AreEqual(row["email"], "*****@*****.**"); found++; } else if (1315 == (int)row["id"]) { Assert.AreEqual(row["first_name"], "Ross"); Assert.AreEqual(row["middle_initial"], "A"); Assert.AreEqual(row["last_name"], "Richards"); Assert.AreEqual(row["email"], "*****@*****.**"); found++; } } Assert.AreEqual(2, found); }
public void NumberOfColumnsFromNewWithWhere() { DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("email=@0", "*****@*****.**"); Assert.AreEqual(12, obj.Columns.Count); }
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 RowCount() { DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("id=@0 OR id=@1 OR id=@2", 1313, 1315, 2); Assert.AreEqual(3, obj.Rows.Count); }
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 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 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"); }
public void GetColumnNames() { DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("id=@0", 1313); Assert.AreEqual("Chris", obj.Rows[0]["first_name"]); }
public void InsertRecordShowInRow() { //Inserting a Record, the record should be added to the objects Rows property //-- // These parrts are tested by InsertRecord() //Verify our record doesn't already exist. DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("email=@0", "*****@*****.**"); Assert.AreEqual(0, obj.Rows.Count); //Create a new Row DBRow ladygaga = new DBRow(); ladygaga["first_name"] = "Lady"; ladygaga["last_name"] = "Gaga"; ladygaga["email"] = "*****@*****.**"; //-- Assert.AreEqual(0, obj.Rows.Count); //Insert the Row ladygaga.Insert(obj); //Test that it's in the DBObject Assert.AreEqual(1, obj.Rows.Count); //-- // These parrts are tested by InsertRecord() //Try to get it now obj.Where("email=@0", "*****@*****.**"); Assert.AreEqual(1, obj.Rows.Count, "Checking that the record exists."); //Now get rid of it. obj.Rows[0].Delete(obj); //Verify that it's gone obj.Where("email=@0", "*****@*****.**"); Assert.AreEqual(0, obj.Rows.Count); //-- }
public void InsertRecord() { //Make sure the row doesn't exist already. DBObject obj = new DBObject(Utility.connMy, "users", "id"); obj.Where("email=@0", "*****@*****.**"); Assert.AreEqual(0, obj.Rows.Count); //Create a new Row DBRow ladygaga = new DBRow(); ladygaga["first_name"] = "Lady"; ladygaga["last_name"] = "Gaga"; ladygaga["email"] = "*****@*****.**"; //Insert the Row ladygaga.Insert(obj); //Try to get it now obj.Where("email=@0", "*****@*****.**"); Assert.AreEqual(1, obj.Rows.Count, "Checking that the record exists."); //Now get rid of it. obj.Rows[0].Delete(obj); //Verify that it's gone obj.Where("email=@0", "*****@*****.**"); Assert.AreEqual(0, obj.Rows.Count); }