예제 #1
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());
        }
예제 #2
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);
        }
예제 #3
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);
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
        public void Add_PersonIsNull_ExceptionNotThrown()
        {
            var repository = new PersonRepository();

            repository.Add(null);
        }
예제 #6
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);
            }
        }