Example #1
0
        public static void UpsertWithPredicate(ICRUDDataStore store)
        {
            var patient  = TestLogic.GetDefaultPatient();
            var affected = store.Insert(patient);

            Assert.AreEqual(1, affected);
            var query = new Query <Patient>("CRUD.Patient.List")
            {
                new Query.Param("LN", "%%")
            };
            var persisted = store.LoadRow(query);

            persisted.Zip        = "010203";
            persisted.First_Name = "John";
            persisted.Last_Name  = "Smith";
            affected             = store.Upsert(persisted, (r, k, f) => f.Name != "Zip");
            Assert.AreEqual(2, affected);

            var updated = store.LoadRow(query);

            Assert.IsNotNull(updated);
            Assert.AreEqual(persisted.SSN, updated.SSN);
            Assert.AreEqual(persisted.City, updated.City);
            Assert.AreEqual(persisted.Address1, updated.Address1);
            Assert.AreEqual(persisted.Address2, updated.Address2);
            Assert.AreEqual(persisted.Amount, updated.Amount);
            Assert.AreEqual(persisted.Doctor_Phone, updated.Doctor_Phone);
            Assert.AreEqual(persisted.Phone, updated.Phone);
            Assert.AreEqual(persisted.DOB, updated.DOB);
            Assert.AreEqual(persisted.Note, updated.Note);

            Assert.AreEqual(persisted.First_Name, updated.First_Name);
            Assert.AreEqual(persisted.Last_Name, updated.Last_Name);
            Assert.AreEqual(patient.Zip, updated.Zip); // notice ZIP remains the same
        }
Example #2
0
        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.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%loff_5")
            })[0];

            Assert.AreEqual(1, result.Count);
            var row = result[0] as Patient;

            Assert.AreEqual("5", row.SSN);
            Assert.AreEqual(null, row.Phone);

            row.Phone = "22-94-92";
            store.Upsert(row);

            result = store.Load(new Query("CRUD.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%loff_5")
            })[0];
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("22-94-92", result[0]["Phone"]);

            result = store.Load(new Query("CRUD.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%loff_%")
            })[0];
            Assert.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.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%")
            })[0];
            Assert.AreEqual(11, result.Count);

            result = store.Load(new Query("CRUD.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "Lenin")
            })[0];
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Vlad", result[0]["First_Name"]);
        }
Example #3
0
        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.Patient.List", typeof(Patient) ) { new Query.Param("LN", "%loff_5") } )[0];
            
            Assert.AreEqual(1, result.Count);
            var row = result[0] as Patient;
            Assert.AreEqual("5", row.SSN);
            Assert.AreEqual(null, row.Phone);

            row.Phone = "22-94-92";
            store.Upsert( row );
            
            result = store.Load( new Query("CRUD.Patient.List", typeof(Patient) ) { new Query.Param("LN", "%loff_5") } )[0];
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("22-94-92", result[0]["Phone"]);

            result = store.Load( new Query("CRUD.Patient.List", typeof(Patient) ) { new Query.Param("LN", "%loff_%") } )[0];
            Assert.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.Patient.List", typeof(Patient) ) { new Query.Param("LN", "%") } )[0];
            Assert.AreEqual(11, result.Count);

            result = store.Load( new Query("CRUD.Patient.List", typeof(Patient) ) { new Query.Param("LN", "Lenin") } )[0];
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Vlad", result[0]["First_Name"]);

        }
Example #4
0
        public static void UpsertWithPredicate(ICRUDDataStore store)
        {
            var patient = TestLogic.GetDefaultPatient();
            var affected = store.Insert(patient);
            Assert.AreEqual(1, affected);
            var query = new Query<Patient>("CRUD.Patient.List") { new Query.Param("LN", "%%") };
            var persisted = store.LoadRow(query);

            persisted.Zip = "010203";
            persisted.First_Name = "John";
            persisted.Last_Name = "Smith";
            affected = store.Upsert(persisted, (r, k, f) => f.Name != "Zip");
            Assert.AreEqual(2, affected);

            var updated = store.LoadRow(query);
            Assert.IsNotNull(updated);
            Assert.AreEqual(persisted.SSN, updated.SSN);
            Assert.AreEqual(persisted.City, updated.City);
            Assert.AreEqual(persisted.Address1, updated.Address1);
            Assert.AreEqual(persisted.Address2, updated.Address2);
            Assert.AreEqual(persisted.Amount, updated.Amount);
            Assert.AreEqual(persisted.Doctor_Phone, updated.Doctor_Phone);
            Assert.AreEqual(persisted.Phone, updated.Phone);
            Assert.AreEqual(persisted.DOB, updated.DOB);
            Assert.AreEqual(persisted.Note, updated.Note);

            Assert.AreEqual(persisted.First_Name, updated.First_Name);
            Assert.AreEqual(persisted.Last_Name, updated.Last_Name);
            Assert.AreEqual(patient.Zip, updated.Zip); // notice ZIP remains the same
        }