Exemple #1
0
        public void UpdateUsing_SingleRow()
        {
            var     depts = new Departments(ProviderName);
            dynamic toSave = new { DNAME = "Massive Dep", LOC = "Beach" }.ToExpando();
            var     saveResult = depts.Save(toSave);

            Assert.AreEqual(1, saveResult);
            Assert.IsTrue(toSave.DEPTNO > 0);
            var mightyDep = new { DNAME = "Mighty Dep" };

            // Clean down
            // TO DO: Copy to the others
            depts.Delete("DNAME = :0", mightyDep.DNAME);

            // The original test
            Assert.AreEqual(0, depts.All(mightyDep).ToList().Count);
            Assert.AreEqual(1, depts.UpdateUsing(mightyDep, toSave.DEPTNO));

            // Some new tests

            // For reasons unknown to science, this will not make this call
            //Assert.AreEqual(1, depts.UpdateUsing(mightyDep, "DEPTNO = :0", args: Convert.ToInt32(toSave.DEPTNO)));

            // works
            string dn     = $"{toSave.DEPTNO}"; // used later too
            var    thungy = Convert.ToInt32(dn);

            Assert.AreEqual(1, depts.UpdateUsing(mightyDep, "DEPTNO = :0", args: thungy));

            // This doesn't work either, it's because the conversion is from a field of a dynamic, so the var is an object not a basic type
            //var thingy = Convert.ToInt32(toSave.DEPTNO);
            //var type = $"{thingy.GetType()} {thungy.GetType()}";
            //Assert.AreEqual(1, depts.UpdateUsing(mightyDep, "DEPTNO = :0", args: thingy));

            // Check that these do work, also checks that the where args version is working
            Assert.AreEqual(1, depts.UpdateUsing(mightyDep, "DEPTNO = :0", args: new object[] { Convert.ToInt32(toSave.DEPTNO) }));
            Assert.AreEqual(1, depts.UpdateUsing(mightyDep, "DEPTNO = :0", Convert.ToInt32(toSave.DEPTNO)));

            Assert.AreEqual(1, depts.UpdateUsing(mightyDep, where : "DEPTNO = :0", args: dn));
            Assert.AreEqual(1, depts.UpdateUsing(mightyDep, "DEPTNO = :0", args: (int)toSave.DEPTNO));

            // Check
            Assert.AreEqual(1, depts.All(mightyDep).ToList().Count);

            // Clean up
            Assert.AreEqual(1, depts.Delete(toSave.DEPTNO));
            Assert.AreEqual(0, depts.All(mightyDep).ToList().Count);
        }
Exemple #2
0
 public void NormalWhereCall()
 {
     // Check that things are up and running normally before trying the new stuff
     var db = new Departments(ProviderName);
     var rows = db.All(where: "LOC = :0", args: "Nowhere");
     Assert.AreEqual(9, rows.ToList().Count);
 }
Exemple #3
0
        public void All_LimitSpecification()
        {
            var depts   = new Departments(ProviderName);
            var allRows = depts.All(limit: 10).ToList();

            Assert.AreEqual(10, allRows.Count);
        }
Exemple #4
0
        public void Save_MultipleRows()
        {
            var depts = new Departments(ProviderName);

            object[] toSave = new object[]
            {
                new { DNAME = "Massive Dep", LOC = "Beach" }.ToExpando(),
                new { DNAME = "Massive Dep", LOC = "DownTown" }.ToExpando()
            };
            var result = depts.Save(toSave);

            Assert.AreEqual(2, result);
            foreach (dynamic o in toSave)
            {
                Assert.IsTrue(o.DEPTNO > 0);
            }

            // read them back, update them, save them again,
            var savedDeps = depts.All(where : "WHERE DEPTNO=:0 OR DEPTNO=:1", args: new object[] { ((dynamic)toSave[0]).DEPTNO, ((dynamic)toSave[1]).DEPTNO }).ToList();

            Assert.AreEqual(2, savedDeps.Count);
            savedDeps[0].LOC += "C";
            savedDeps[1].LOC += "C";
            result            = depts.Save(toSave);
            Assert.AreEqual(2, result);
            Assert.AreEqual(1, depts.Delete(savedDeps[0].DEPTNO));
            Assert.AreEqual(1, depts.Delete(savedDeps[1].DEPTNO));
        }
Exemple #5
0
        public void All_NoParameters()
        {
            var depts   = new Departments(ProviderName);
            var allRows = depts.All().ToList();

            Assert.AreEqual(60, allRows.Count);
            foreach (var d in allRows)
            {
                Console.WriteLine("{0} {1} {2}", d.DEPTNO, d.DNAME, d.LOC);
            }
        }
Exemple #6
0
        public void All_WhereSpecification_OrderBySpecification_LimitSpecification()
        {
            var depts   = new Departments(ProviderName);
            var allRows = depts.All(limit: 6, orderBy: "DEPTNO DESC", where : "WHERE LOC=:0", args: "Nowhere").ToList();

            Assert.AreEqual(6, allRows.Count);
            int previous = int.MaxValue;

            foreach (var r in allRows)
            {
                int current = r.DEPTNO;
                Assert.IsTrue(current <= previous);
                previous = current;
            }
        }