예제 #1
0
        public void AllowNullInsert()
        {
            var db = new RealDB(connString, new SQL2005DBAnalyzer(connString));

            var org = new Organization();
            org.Name = "My Organization";

            var key = db.Insert("Organization", org._AsDictionary());

            //Verify that only 1 row exists with the key of this inserted organization
            Assert.AreEqual(1, db.RawRead("Organization", key).Count());
        }
예제 #2
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());
        }
예제 #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"]);
        }
예제 #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());
        }
예제 #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());
        }
예제 #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"]);
        }