Exemple #1
0
        public void Delete()
        {
            var db = new RealDB(connString, new SQL2005DBAnalyzer(connString));

            var person = new Person();
            person.FirstName = "bob";
            person.LastName = "morris";

            var key = db.Insert("Person", person._AsDictionary());
            db.Delete("Person", key);

            Assert.AreEqual(0, db.RawRead("Person", key).Count());
        }
Exemple #2
0
        public void Insert()
        {
            var db = new RealDB(connString, new SQL2005DBAnalyzer(connString));

            var contents = db.ReadAll<Person>();

            var person = new Person();
            person.FirstName = "test";
            person.LastName = "person";

            db.Insert("Person", person._AsDictionary());

            Assert.AreEqual(contents.Count() + 1, db.ReadAll<Person>().Count());
        }
Exemple #3
0
        public void Update()
        {
            var db = new RealDB(connString, new SQL2005DBAnalyzer(connString));

            var person = new Person();
            person.FirstName = "test";
            person.LastName = "person";

            var keys = db.Insert("Person", person._AsDictionary());

            //Retrieve the saved person so we can verify it saved with our intended data
            var retrieved = db.RawRead("Person", keys).First();
            Assert.AreEqual(person.FirstName, retrieved["FirstName"]);
            Assert.AreEqual(person.LastName, retrieved["LastName"]);

            person.FirstName = "newFirst";
            person.LastName = "newLastName";

            //Update and retrieve the person again so we can verify that the Update worked
            db.Update("Person", person._AsDictionary(), keys);
            retrieved = db.RawRead("Person", keys).First();
            Assert.AreEqual(person.FirstName, retrieved["FirstName"]);
            Assert.AreEqual(person.LastName, retrieved["LastName"]);
        }
Exemple #4
0
        public void TransactionSuccessful()
        {
            var db = new RealDB(connString, new SQL2005DBAnalyzer(connString));
            var transaction = db.BeginTransaction();

            var person = new Person();
            person.FirstName = "test";
            person.LastName = "person";

            var keys = db.Insert("Person", person._AsDictionary(), transaction);

            transaction.Commit();

            Assert.AreEqual(1, db.RawRead("Person", keys).Count());
        }
Exemple #5
0
        public void TransactionAbandoned()
        {
            var keys = new Dictionary<string, object>();

            using (var db = new RealDB(connString, new SQL2005DBAnalyzer(connString)))
            {
                var transaction = db.BeginTransaction();

                var person = new Person();
                person.FirstName = "test";
                person.LastName = "person";

                keys = db.Insert("Person", person._AsDictionary(), transaction);
            }

            var conn = new RealDB(connString, new SQL2005DBAnalyzer(connString));
            Assert.AreEqual(0, conn.RawRead("Person", keys).Count());
        }
Exemple #6
0
        public void RealUpdate()
        {
            var db = new RealDB(connString, new SQL2005DBAnalyzer(connString));

            var person = new Person();
            person.FirstName = "test";
            person.LastName = "person";

            var keys = db.Insert("Person", person._AsDictionary());

            //Retrieve the saved person so we can verify it saved with our intended data
            var retrieved = db.RawRead("Person", keys).First();
            Assert.AreEqual(person.FirstName, retrieved["FirstName"]);
            Assert.AreEqual(person.LastName, retrieved["LastName"]);

            person.FirstName = "newFirst";
            person.LastName = "newLastName";

            //Update and retrieve the person again so we can verify that the Update worked
            var data = person._AsDictionary().Where(kv => !keys.Keys.Contains(kv.Key))
                .ToDictionary(i => i.Key, i => i.Value);
            db.RealUpdate("Person", data, keys);
            retrieved = db.RawRead("Person", keys).First();
            Assert.AreEqual(person.FirstName, retrieved["FirstName"]);
            Assert.AreEqual(person.LastName, retrieved["LastName"]);
        }