示例#1
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"]);
        }