public static void UpsertWithPredicate(ICrudDataStore store) { var patient = TestLogic.GetDefaultPatient(); var affected = store.Insert(patient); Aver.AreEqual(1, affected); var query = new Query <Patient>("CRUD.Queries.Patient.List") { new Query.Param("LN", "%%") }; var persisted = store.LoadDoc(query); persisted.Zip = "010203"; persisted.First_Name = "John"; persisted.Last_Name = "Smith"; affected = store.Upsert(persisted, (r, k, f) => f.Name != "Zip"); Aver.AreEqual(2, affected); var updated = store.LoadDoc(query); Aver.IsNotNull(updated); Aver.AreEqual(persisted.SSN, updated.SSN.Trim()); Aver.AreEqual(persisted.City, updated.City); Aver.AreEqual(persisted.Address1, updated.Address1); Aver.AreEqual(persisted.Address2, updated.Address2); Aver.AreEqual(persisted.Amount, updated.Amount); Aver.AreEqual(persisted.Doctor_Phone, updated.Doctor_Phone); Aver.AreEqual(persisted.Phone, updated.Phone.Trim()); Aver.AreEqual(persisted.DOB, updated.DOB); Aver.AreEqual(persisted.Note, updated.Note); Aver.AreEqual(persisted.First_Name, updated.First_Name); Aver.AreEqual(persisted.Last_Name, updated.Last_Name); Aver.AreEqual(patient.Zip, updated.Zip); // notice ZIP remains the same }
public static void InsertThenUpsert_TypedRow(ICrudDataStore store) { for (var i = 0; i < 10; i++) { store.Insert(new Patient { SSN = i.ToString(), First_Name = "Jack", Last_Name = "Kozloff_" + i, DOB = new DateTime(1980, 1, 12) }); } var result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient)) { new Query.Param("LN", "%loff_5") })[0]; Aver.AreEqual(1, result.Count); var row = result[0] as Patient; Aver.AreEqual("5", row.SSN.Trim()); Aver.AreEqual(null, row.Phone); row.Phone = "22-94-92"; store.Upsert(row); result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient)) { new Query.Param("LN", "%loff_5") })[0]; Aver.AreEqual(1, result.Count); Aver.AreObjectsEqual("22-94-92", result[0]["Phone"]); result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient)) { new Query.Param("LN", "%loff_%") })[0]; Aver.AreEqual(10, result.Count); row = new Patient { SSN = "-100", First_Name = "Vlad", Last_Name = "Lenin", DOB = new DateTime(1871, 4, 20) }; store.Upsert(row); result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient)) { new Query.Param("LN", "%") })[0]; Aver.AreEqual(11, result.Count); result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient)) { new Query.Param("LN", "Lenin") })[0]; Aver.AreEqual(1, result.Count); Aver.AreObjectsEqual("Vlad", result[0]["First_Name"]); }