Example #1
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));
        }
Example #2
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);
        }
Example #3
0
        public void CleanUp()
        {
            // delete all rows with department name 'Massive Dep'.
            var depts = new Departments(ProviderName);

            depts.Delete("DNAME=:0", "Massive Dep");
        }
Example #4
0
        public void Insert_SingleRow()
        {
            var depts    = new Departments(ProviderName);
            var inserted = depts.Insert(new { DNAME = "Massive Dep", LOC = "Beach" });

            Assert.IsTrue(inserted.DEPTNO > 0);
            Assert.AreEqual(1, depts.Delete(inserted.DEPTNO));
        }
Example #5
0
        public void Save_SingleRow()
        {
            var     depts = new Departments(ProviderName);
            dynamic toSave = new { DNAME = "Massive Dep", LOC = "Beach" }.ToExpando();
            var     result = depts.Save(toSave);

            Assert.AreEqual(1, result);
            Assert.IsTrue(toSave.DEPTNO > 0);
            Assert.AreEqual(1, depts.Delete(toSave.DEPTNO));
        }
Example #6
0
        public void Insert_SingleRow(bool explicitConnection)
        {
            var          depts      = new Departments(ProviderName, explicitConnection);
            DbConnection connection = null;

            if (explicitConnection)
            {
                MightyTests.ConnectionStringUtils.CheckConnectionStringRequiredForOpenConnection(depts);
                connection = depts.OpenConnection(MightyTests.ConnectionStringUtils.GetConnectionString(TestConstants.ReadWriteTestConnection, ProviderName));
            }
            using (connection)
            {
                var inserted = depts.Insert(new { DNAME = "Massive Dep", LOC = "Beach" }, connection: connection);
                Assert.IsTrue(inserted.DEPTNO > 0);
                Assert.AreEqual(1, depts.Delete(connection, inserted.DEPTNO));
            }
        }
 // GET: Departments/Delete/5
 public ActionResult Delete(int id)
 {
     department.Delete(id);
     return(RedirectToAction("Index"));
 }