Permalink
Browse files

Merge pull request #237 from JamesKyburz/issue-236

UpsertBy not inserting all data
  • Loading branch information...
2 parents 9ffd32a + 48b8a06 commit 116031a19cc1ad473b87a7f5f3b1d5b748f869ce @markrendle committed Oct 15, 2012
Showing with 44 additions and 1 deletion.
  1. +44 −0 Simple.Data.SqlTest/UpsertTests.cs
  2. +0 −1 Simple.Data/Commands/UpsertByCommand.cs
@@ -414,5 +414,49 @@ public void TestUpsertWithSingleArgumentAndExistingObject()
Assert.AreEqual(1, actual.Id);
Assert.IsNotNull(actual.Name);
}
+
+ [Test]
+ public void TestUpsertUserBySecondaryField()
+ {
+ var db = DatabaseHelper.Open();
+
+ var id = db.Users.UpsertByName(new User() { Age = 20, Name = "Black sheep", Password = "Bah" }).Id;
+ User actual = db.Users.FindById(id);
+
+ Assert.AreEqual(id, actual.Id);
+ Assert.AreEqual("Black sheep", actual.Name);
+ Assert.AreEqual("Bah", actual.Password);
+ Assert.AreEqual(20, actual.Age);
+ }
+
+ [Test]
+ public void TestUpsertUserByTwoSecondaryFields()
+ {
+ var db = DatabaseHelper.Open();
+
+ var id = db.Users.UpsertByNameAndPassword(new User() { Age = 20, Name = "Black sheep", Password = "Bah" }).Id;
+ User actual = db.Users.FindById(id);
+
+ Assert.AreEqual(id, actual.Id);
+ Assert.AreEqual("Black sheep", actual.Name);
+ Assert.AreEqual("Bah", actual.Password);
+ Assert.AreEqual(20, actual.Age);
+ }
+
+ [Test]
+ public void TestUpsertExisting()
+ {
+ var db = DatabaseHelper.Open();
+
+ var id = db.Users.UpsertByNameAndPassword(new User() { Age = 20, Name = "Black sheep", Password = "Bah" }).Id;
+ db.Users.UpsertById(new User() { Id = id, Age = 12, Name = "Dog", Password = "Bark" });
+
+ User actual = db.Users.FindById(id);
+
+ Assert.AreEqual(id, actual.Id);
+ Assert.AreEqual("Dog", actual.Name);
+ Assert.AreEqual("Bark", actual.Password);
+ Assert.AreEqual(12, actual.Age);
+ }
}
}
@@ -62,7 +62,6 @@ internal static object UpsertByKeyFields(string tableName, DataStrategy dataStra
}
criteria.Add(keyFieldName, keyValuePair.Value);
- record.Remove(keyValuePair);
}
return criteria;
}

0 comments on commit 116031a

Please sign in to comment.