Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #237 from JamesKyburz/issue-236

UpsertBy not inserting all data
  • Loading branch information...
commit 116031a19cc1ad473b87a7f5f3b1d5b748f869ce 2 parents 9ffd32a + 48b8a06
@markrendle authored
View
44 Simple.Data.SqlTest/UpsertTests.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);
+ }
}
}
View
1  Simple.Data/Commands/UpsertByCommand.cs
@@ -62,7 +62,6 @@ internal static object UpsertByKeyFields(string tableName, DataStrategy dataStra
}
criteria.Add(keyFieldName, keyValuePair.Value);
- record.Remove(keyValuePair);
}
return criteria;
}
Please sign in to comment.
Something went wrong with that request. Please try again.