Esempio n. 1
0
        public void test_LoadRecord()
        {
            DataSetDalc dsDalc = createDsDalc();
            Query       q      = new Query("users");

            q.Condition = (QField)"name" == (QConst)"Mike";
            var res = dsDalc.LoadRecord(q);

            Assert.NotNull(res, "LoadRecord failed");
            Assert.AreEqual(1, (int)res["id"], "LoadRecord failed");
        }
Esempio n. 2
0
        public void test_Update()
        {
            DataSetDalc dsDalc = createDsDalc();
            DataSet     ds     = new DataSet();
            Query       q      = new Query("users");

            q.Condition = (QField)"id" == (QConst)1;

            dsDalc.Load(q, ds);
            ds.Tables["users"].Rows[0]["name"] = "Vit";
            var newRow = ds.Tables["users"].Rows.Add(new object[] { 4, "Petya", "2" });

            dsDalc.Update(ds.Tables["users"]);

            Assert.AreEqual(4, dsDalc.RecordsCount(new Query("users")), "Update failed");

            var res = dsDalc.LoadRecord(q);

            Assert.AreEqual("Vit", res["name"].ToString(), "Update failed");

            ds.Tables["users"].Rows[1].Delete();
            dsDalc.Update(ds.Tables["users"]);
            if (dsDalc.PersistedDS.Tables["users"].Rows.Count != 3)
            {
                throw new Exception("Update failed");
            }

            res         = new Hashtable();
            res["name"] = "VVV";
            var affected = dsDalc.Update(q, res);

            Assert.AreEqual(1, affected, "Update by query failed");

            var res2 = dsDalc.LoadRecord(q);

            Assert.AreEqual("VVV", res2["name"], "Update failed");
        }
Esempio n. 3
0
        public void test_Delete()
        {
            DataSetDalc dsDalc = createDsDalc();

            Query subQuery = new Query("roles");

            subQuery.Condition = (QField)"role" == (QConst)"user";
            subQuery.Fields    = new QField[] { "id" };
            Query q = new Query("users");

            q.Condition = (QField)"role" == subQuery;

            dsDalc.Delete(q);

            Hashtable res = new Hashtable();

            Assert.Null(dsDalc.LoadRecord(q), "Delete failed");
            Assert.AreEqual(2, dsDalc.PersistedDS.Tables["users"].Rows.Count, "Delete failed");
        }