Exemplo n.º 1
0
        public void TransactionTest()
        {
            using (DbManager db = new DbManager())
            {
                PersonAccessor pa = DataAccessor.CreateInstance <PersonAccessor>();

                db.BeginTransaction();

                // Insert and get id.
                //
                Person person = Person.CreateInstance();

                person.FirstName = "Crazy";
                person.LastName  = "Frog";
                person.Gender    = Gender.Unknown;

                int id = pa.Insert(db, person);

                person = pa.SelectByID(db, id);

                TypeAccessor.WriteConsole(person);
                Assert.IsNotNull(person);

                // Update.
                //
                person.Gender = Gender.Other;

                pa.Query.Update(db, person);

                person = pa.SelectByID(db, person.ID);

                TypeAccessor.WriteConsole(person);
                Assert.AreEqual(Gender.Other, person.Gender);

                // Delete.
                //
                pa.Query.Delete(db, person);

                person = pa.SelectByID(db, person.ID);

                Assert.IsNull(person);

                db.CommitTransaction();

                // Get All.
                //
                List <Person> list = pa.Query.SelectAll(db);

                foreach (Person p in list)
                {
                    TypeAccessor.WriteConsole(p);
                }
            }
        }
Exemplo n.º 2
0
        public void Test()
        {
            PersonAccessor pa = DataAccessor.CreateInstance <PersonAccessor>();

            // Insert and get id.
            //
            Person person = Person.CreateInstance();

            person.FirstName = "Crazy";
            person.LastName  = "Frog";
            person.Gender    = Gender.Unknown;

            int id = pa.Insert(person);

            person = pa.SelectByID(id);

            TypeAccessor.WriteConsole(person);
            Assert.IsNotNull(person);

            // Update.
            //
            person.Gender = Gender.Other;

            pa.Query.Update(person);

            person = pa.SelectByID(person.ID);

            TypeAccessor.WriteConsole(person);
            Assert.AreEqual(Gender.Other, person.Gender);

            // Delete.
            //
            pa.Query.Delete(person);

            person = pa.SelectByID(person.ID);

            Assert.IsNull(person);

            // Get All.
            //
            List <Person> list = pa.Query.SelectAll();

            foreach (Person p in list)
            {
                TypeAccessor.WriteConsole(p);
            }
        }