예제 #1
0
        public void Create_Adds_A_List_Of_Entities_To_The_Table()
        {
            int       startCount;
            const int numToAdd = 3;

            List <Person> localList = new List <Person>();

            for (int i = 0; i < numToAdd; i++)
            {
                localList.Add(CreatePerson());
            }

            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                // create
                startCount = repo.All().Count();
                Assert.IsTrue(repo.Add(localList));

                dbSession.Commit();
            }

            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();
                int finalCount = repo.All().Count();

                Assert.IsTrue(finalCount == startCount + numToAdd);
            }
        }
예제 #2
0
        public void Create_Adds_Entities_To_The_Table()
        {
            int       currentCount;
            const int numToAdd = 3;

            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                // create
                currentCount = repo.All().Count();
                for (int i = 0; i < numToAdd; i++)
                {
                    Assert.IsTrue(repo.Add(CreatePerson()));
                }

                dbSession.Commit();
            }
            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();
                int newCount = repo.All().Count();

                Assert.IsTrue(currentCount + numToAdd == newCount);
            }
        }
예제 #3
0
        private void AddTestData()
        {
            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                for (int i = 0; i < 5; i++)
                {
                    repo.Add(CreatePerson());
                }

                dbSession.Commit();
            }
        }
        public void Commit_And_Rollback_Work()
        {
            Person person = new Person
            {
                Id        = Guid.NewGuid(),
                FirstName = Guid.NewGuid().ToString(),
                LastName  = Guid.NewGuid().ToString()
            };

            // Rollback
            using (DbSession dbSession = GetSession())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                repo.Add(person);

                dbSession.Rollback();
            }
            using (DbSession dbSession = GetSession())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                Assert.IsNull(repo.FindBy(person.Id));
            }
            // Commit
            using (DbSession dbSession = GetSession())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                repo.Add(person);

                dbSession.Commit();
            }
            using (DbSession dbSession = GetSession())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                Assert.IsNotNull(repo.FindBy(person.Id));
            }

            // Cleanup
            using (DbSession dbSession = GetSession())
            {
                IKeyedRepository <Guid, Person> repo = dbSession.CreateKeyedRepository <Guid, Person>();

                repo.Delete(person);

                dbSession.Commit();
            }
        }
예제 #5
0
        public void Create_Adds_Entities_To_The_Table()
        {
            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <int, Person> repo = dbSession.CreateKeyedRepository <int, Person>();

                // create
                int expectedCount = repo.All().Count();
                for (int i = 0; i < 3; i++)
                {
                    Assert.IsTrue(repo.All().Count() == expectedCount++);
                    Assert.IsTrue(repo.Add(CreatePerson()));
                    Assert.IsTrue(repo.All().Count() == expectedCount);
                }

                dbSession.Commit();
            }
        }
예제 #6
0
        public void Create_Adds_A_List_Of_Entities_To_The_Table()
        {
            List <Person> localList = new List <Person>();

            for (int i = 0; i < 3; i++)
            {
                localList.Add(CreatePerson());
            }

            using (IDbSession dbSession = _dbSessionFactory.Create())
            {
                IKeyedRepository <int, Person> repo = dbSession.CreateKeyedRepository <int, Person>();

                // create
                int countBefore = repo.All().Count();
                Assert.IsTrue(repo.Add(localList));
                Assert.IsTrue(repo.All().Count() == countBefore + localList.Count);

                dbSession.Commit();
            }
        }