Ejemplo n.º 1
0
        public void GetBy_ValidIdForPersonInDb_PersonReturned()
        {
            var existingPerson = new Person { FirstName = "Albert", LastName = "Einstein", Email = "*****@*****.**" };
            var repository = new PersonRepository();
            repository.Add(existingPerson);

            var personFromDb = repository.GetBy(existingPerson.Id);

            Assert.AreEqual("Albert", personFromDb.FirstName);
            Assert.AreEqual("Einstein", personFromDb.LastName);
        }
Ejemplo n.º 2
0
 public void Update(Person person)
 {
     using (var session = NHibernateSessionManager.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Update(person);
             transaction.Commit();
         }
     }
 }
Ejemplo n.º 3
0
        public void Add(Person person)
        {
            if (person == null) return;

            using (var session = NHibernateSessionManager.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    session.Save(person);
                    transaction.Commit();
                }
            }
        }
Ejemplo n.º 4
0
        public void Add_ValidPerson_PersonAddedToDatabase()
        {
            var newPerson = new Person {FirstName = "Albert", LastName = "Einstein"};
            var repository = new PersonRepository();

            repository.Add(newPerson);

            using (var session = _sessionFactory.OpenSession())
            {
                var addedPerson = session.Get<Person>(newPerson.Id);
                Assert.AreEqual("Albert", addedPerson.FirstName);
                Assert.AreEqual("Einstein", newPerson.LastName);
            }
        }
Ejemplo n.º 5
0
        public void GetAllPersonsWith_FirstNameIsAlbert_TwoPersonsReturned()
        {
            var albert1 = new Person { FirstName = "Albert", LastName = "Einstein", Email = "*****@*****.**" };
            var albert2 = new Person { FirstName = "Albert", LastName = "TheOtherEinstein", Email = "*****@*****.**" };
            var isaac = new Person { FirstName = "Isaac", LastName = "Newton", Email = "*****@*****.**" };

            var repository = new PersonRepository();
            repository.Add(albert1);
            repository.Add(albert2);
            repository.Add(isaac);

            var alberts = repository.GetAllPersonsWith("Albert");

            Assert.AreEqual(2, alberts.Count());
        }
Ejemplo n.º 6
0
        public void Remove_ExisitingPersonInDb_ExistingPersonRemoved()
        {
            var existingPerson = new Person { FirstName = "Albert", LastName = "Einstein", Email = "*****@*****.**" };
            var repository = new PersonRepository();
            repository.Add(existingPerson);

            repository.Remove(existingPerson);

            using (var session = _sessionFactory.OpenSession())
            {
                var removedPerson = session.Get<Person>(existingPerson.Id);
                Assert.IsNull(removedPerson);
            }
        }
Ejemplo n.º 7
0
        public void Update_ChangeEmailOfExistingPerson_EmailChanged()
        {
            var existingPerson = new Person {FirstName = "Albert", LastName = "Einstein", Email = "*****@*****.**"};
            var repository = new PersonRepository();
            repository.Add(existingPerson);

            existingPerson.Email = "*****@*****.**";

            repository.Update(existingPerson);

            using (var session = _sessionFactory.OpenSession())
            {
                var updatedPerson = session.Get<Person>(existingPerson.Id);
                Assert.AreEqual("*****@*****.**", updatedPerson.Email);
            }
        }