Exemplo n.º 1
0
        public static void QueryInsertQuery(ICrudDataStore store)
        {
            var query = new Query("CRUD.Queries.Patient.List")
            {
                new Query.Param("LN", "%loff")
            };
            var result = store.Load(query);

            Aver.AreEqual(1, result.Count);
            var rowset = result[0];

            Aver.AreEqual(0, rowset.Count);

            var row = new DynamicDoc(rowset.Schema);

            row["ssn"]        = "999-88-9012";
            row["First_Name"] = "Jack";
            row["Last_Name"]  = "Kozloff";
            row["DOB"]        = new DateTime(1980, 1, 12);

            Aver.IsNull(row.Validate());

            store.Insert(row);


            result = store.Load(query);

            Aver.AreEqual(1, result.Count);
            rowset = result[0];

            Aver.AreEqual(1, rowset.Count);
            Aver.AreObjectsEqual("Jack", rowset[0]["First_Name"]);
        }
Exemplo n.º 2
0
        public static void InsertInTransaction_Rollback_TypedRow(ICrudDataStore store)
        {
            var transaction = store.BeginTransaction();

            for (var i = 0; i < 25; i++)
            {
                transaction.Insert(new Patient
                {
                    SSN        = "999-88-9012",
                    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%")
            })[0];

            Aver.AreEqual(0, result.Count);

            transaction.Rollback();

            result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%loff%")
            })[0];

            Aver.AreEqual(0, result.Count);
        }
Exemplo n.º 3
0
        public static void QueryInsertQuery_TypedRowDerived(ICrudDataStore store)
        {
            var query = new Query("CRUD.Queries.Patient.List", typeof(SuperPatient))
            {
                new Query.Param("LN", "%loff")
            };
            var result = store.Load(query);

            Aver.AreEqual(1, result.Count);
            var rowset = result[0];

            Aver.AreEqual(0, rowset.Count);

            var row = new SuperPatient();

            row.SSN        = "999-88-9012";
            row.First_Name = "Jack";
            row.Last_Name  = "Kozloff";
            row.DOB        = new DateTime(1980, 1, 12);
            row.Superman   = true;

            Aver.IsNull(row.Validate());

            store.Insert(row);


            result = store.Load(query);

            Aver.AreEqual(1, result.Count);
            rowset = result[0];

            Aver.AreEqual(1, rowset.Count);
            Aver.IsTrue(rowset[0] is SuperPatient);
            Aver.AreObjectsEqual("Jack", rowset[0]["First_Name"]);
        }
Exemplo n.º 4
0
        public static void QueryInsertQuery_DynamicRow(ICrudDataStore store)
        {
            var query = new Query <DynamicDoc>("CRUD.Queries.Patient.List")
            {
                new Query.Param("LN", "%ruman")
            };
            var result = store.Load(query);

            Aver.AreEqual(1, result.Count);
            var rowset = result[0];

            Aver.AreEqual(0, rowset.Count);

            var row = new Patient();

            row.SSN        = "999-88-9012";
            row.First_Name = "Mans";
            row.Last_Name  = "Skolopendruman";
            row.DOB        = new DateTime(1970, 1, 12);

            Aver.IsNull(row.Validate());

            store.Insert(row);


            var row2 = store.LoadDoc(query);

            Aver.IsNotNull(row2);
            Aver.IsTrue(row2 is DynamicDoc);
            Aver.AreObjectsEqual("Mans", row2["First_Name"]);
        }
Exemplo n.º 5
0
        public static void InsertManyUsingLogChanges_TypedRow(ICrudDataStore store)
        {
            var rowset = new Rowset(Schema.GetForTypedDoc(typeof(Patient)));

            rowset.LogChanges = true;

            for (var i = 0; i < 1000; i++)
            {
                rowset.Insert(new Patient
                {
                    SSN        = "999-88-9012",
                    First_Name = "Jack",
                    Last_Name  = "Kozloff" + i,
                    DOB        = new DateTime(1980, 1, 12)
                });
            }

            for (var i = 0; i < 327; i++)
            {
                rowset.Insert(new Patient
                {
                    SSN        = "999-88-9012",
                    First_Name = "Jack",
                    Last_Name  = "Abramovich" + i,
                    DOB        = new DateTime(2001, 1, 12)
                });
            }

            store.Save(rowset);

            var result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%loff%")
            })[0];

            Aver.AreEqual(1000, result.Count);

            result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%ovich%")
            })[0];

            Aver.AreEqual(327, result.Count);
        }
Exemplo n.º 6
0
        public static async Task ASYNC_InsertThenUpdate_TypedRow(ICrudDataStore store)
        {
            for (var i = 0; i < 10; i++)
            {
                await store.InsertAsync(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());

            row.Last_Name = "Gagarin";
            await store.UpdateAsync(row);

            result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%loff_5")
            })[0];
            Aver.AreEqual(0, result.Count);

            result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%garin")
            })[0];
            Aver.AreEqual(1, result.Count);
            Aver.AreObjectsEqual("5", result[0]["SSN"].AsString().Trim());
            Aver.AreObjectsEqual("Gagarin", result[0]["Last_Name"]);
        }
Exemplo n.º 7
0
        public static void InsertThenDelete_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());

            store.Delete(row);

            result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%loff_5")
            })[0];
            Aver.AreEqual(0, result.Count);

            result = store.Load(new Query("CRUD.Queries.Patient.List", typeof(Patient))
            {
                new Query.Param("LN", "%loff_%")
            })[0];
            Aver.AreEqual(9, result.Count);
        }
Exemplo n.º 8
0
        public static void ExecuteCustomCommandHandler(ICrudDataStore store)
        {
            var query = new Query("CustomTestCommandHandler")
            {
                new Query.Param("Msg", "we are on the moon!")
            };
            var result = store.Load(query);

            Aver.AreEqual(1, result.Count);
            var rowset = result[0];

            Aver.AreEqual(2, rowset.Count);

            Aver.AreEqual("Jack", rowset[0]["First_Name"].AsString());
            Aver.AreEqual("Mary", rowset[1]["First_Name"].AsString());
            Aver.AreEqual("we are on the moon!", rowset[1]["Address1"].AsString());
        }
Exemplo n.º 9
0
        public static async Task ASYNC_InsertThenUpsert_TypedRow(ICrudDataStore store)
        {
            for (var i = 0; i < 10; i++)
            {
                await store.InsertAsync(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";
            await store.UpsertAsync(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)
            };

            await store.UpsertAsync(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"]);
        }