public void can_add_new_person_with_phone_number()
        {
            GenerateDatabaseSchema();

            Person p = new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 };
            PhoneNumber num = new PhoneNumber(1, "12345678");
            p.AddPhoneNumber(num);

            IPersonRepository repository = new PersonRepository();
            repository.Add(p);

            using (ISession session = _sessionFactory.OpenSession())
            {
                Person databasePerson;
                databasePerson = session.Get<Person>(p.Id);

                Assert.IsNotNull(databasePerson, "Person not loaded from Database");
                Assertions.AssertPeopleAreEqual(p, databasePerson);

                Assert.AreEqual(1, databasePerson.PhoneNumbers.Count, "List does not contain one phone number");
                foreach (PhoneNumber number in databasePerson.PhoneNumbers)
                {
                    Assert.AreEqual(num.Id, number.Id, "Id of phone number not equal");
                    Assert.AreEqual(num.Number, number.Number, "Id of phone number not equal");
                }
            }
        }
 public void ShowPerson(Person person)
 {
     _mode = ViewMode.View;
     _view.Title = "View Person";
     _person = person;
     DisplayPerson();
 }
 public void EditPerson(Person person)
 {
     _mode = ViewMode.Edit;
     _view.Title = "Edit Person";
     _person = person;
     DisplayPerson();
 }
 public static void AssertPeopleAreEqual(Person p1, Person p2)
 {
     Assert.AreEqual(p1.Id, p2.Id, "Id's don't match");
     Assert.AreEqual(p1.Forename, p2.Forename, "Forename's don't match");
     Assert.AreEqual(p1.Surname, p2.Surname, "Surname's don't match");
     Assert.AreEqual(p1.BirthdayDay, p2.BirthdayDay, "BirthdayDay's don't match");
     Assert.AreEqual(p1.BirthdayMonth, p2.BirthdayMonth, "BirthdayMonth's don't match");
 }
 public void Remove(Person person)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     using (ITransaction transaction = session.BeginTransaction())
     {
         session.Delete(person);
         transaction.Commit();
     }
 }
        public void PersonManager_DeletePerson_RemovesFromRepository()
        {
            //Arrange
            FakePersonRepository mockRepository = new FakePersonRepository();
            PersonManager manager = new PersonManager(mockRepository);

            Person p = new Person() { Id = 1, Forename = "Ted", Surname = "Smith", BirthdayDay = 1, BirthdayMonth = 12 };

            //Act 
            manager.DeletePerson(p);

            //Assert
            Assert.IsNotNull(mockRepository.DeletedPerson, "Person not removed from repository");
            Assertions.AssertPeopleAreEqual(p, mockRepository.DeletedPerson);
        }
        public void can_add_new_person()
        {
            GenerateDatabaseSchema();
            
            Person p = new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 };
            IPersonRepository repository = new PersonRepository();
            repository.Add(p);

            using (ISession session = _sessionFactory.OpenSession())
            {
                Person databasePerson;
                databasePerson = session.Get<Person>(p.Id);

                Assert.IsNotNull(databasePerson, "Person not loaded from Database");
                Assertions.AssertPeopleAreEqual(p, databasePerson);
            }
        }
        public void can_add_new_person_with_email()
        {
            GenerateDatabaseSchema();

            Person p = new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 };
            p.AddEmail("*****@*****.**");
            
            IPersonRepository repository = new PersonRepository();
            repository.Add(p);

            using (ISession session = _sessionFactory.OpenSession())
            {
                Person databasePerson;
                databasePerson = session.Get<Person>(p.Id);

                Assert.IsNotNull(databasePerson, "Person not loaded from Database");
                Assertions.AssertPeopleAreEqual(p, databasePerson);

                Assert.IsTrue(databasePerson.EmailAddresses.Contains("*****@*****.**"), "Email address not found");
            }
        }
 public void ShowPerson(Person person)
 {
     ShownPerson = person;
 }
 private void AddPersonToDatabase(Person p)
 {
     using (ISession session = _sessionFactory.OpenSession())
     using( ITransaction transaction = session.BeginTransaction())
     {
         session.Save(p);
         transaction.Commit();
     }
 }
 public void Update(ContactsDomain.DomainObjects.Person Entity)
 {
     UpdatedPerson = Entity;
 }
 public void DeletePerson(Person person)
 {
     this.DeletedPerson = person;
 }
 public void DeletePerson(Person person)
 {
     _personRepository.Remove(person);
 }
 public void UpdatePerson(Person person)
 {
     _personRepository.Update(person);
 }
 public void AddPerson(Person person)
 {
     _personRepository.Add(person);
 }
 public void Update(ContactsDomain.DomainObjects.Person Entity)
 {
     UpdatedPerson = Entity;
 }
        private void AddPersonToManager()
        {
            Person p = new Person();
            p.Forename = _view.Forename;
            p.Surname = _view.Surname;
            p.BirthdayDay = Convert.ToInt16(_view.BirthdayDay);
            p.BirthdayMonth = Convert.ToInt16(_view.BirthdayMonth);

            _manager.AddPerson(p);
        }
 public void AddPerson(Person person)
 {
     this.AddedPerson = person;
 }
 public void EditPerson(Person person)
 {
     EditedPerson = person;
 }
 public void UpdatePerson(Person person)
 {
     UpdatedPerson = person;
 }
        public void can_remove_person()
        {
            GenerateDatabaseSchema();

            Person p = new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 };
            AddPersonToDatabase(p);

            IPersonRepository repository = new PersonRepository();
            repository.Remove(p);

            using (ISession session = _sessionFactory.OpenSession())
            {
                Person databasePerson = session.Get<Person>(p.Id);

                Assert.IsNull(databasePerson, "Person found in Database when they shouldn't be");
            }
        }
 public void Add(ContactsDomain.DomainObjects.Person Entity)
 {
     AddedPerson = Entity;
 }
        public void can_get_by_id()
        {
            GenerateDatabaseSchema();

            Person p = new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 };
            AddPersonToDatabase(p);

            IPersonRepository repository = new PersonRepository();
            Person databasePerson = repository.GetById(p.Id);

            Assert.IsNotNull(databasePerson, "Person not loaded from Database");
            Assertions.AssertPeopleAreEqual(p, databasePerson);
        }
 public void Remove(ContactsDomain.DomainObjects.Person Entity)
 {
     DeletedPerson = Entity;
 }
        public void can_get_all()
        {
            GenerateDatabaseSchema();

            Person[] people = new Person[3];
            
            people[0] = new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 };
            people[1] = new Person() { Id = 2, Forename = "Sammy", Surname = "Davis", BirthdayDay = 31, BirthdayMonth = 12 };
            people[2] = new Person() { Id = 3, Forename = "Patsy", Surname = "Kensit", BirthdayDay = 1, BirthdayMonth = 1 };

            AddPersonToDatabase(people[0]);
            AddPersonToDatabase(people[1]);
            AddPersonToDatabase(people[2]);

            IPersonRepository repository = new PersonRepository();
            ICollection<Person> databasePeople = repository.GetAll();

            Assert.IsNotNull(databasePeople, "Person not loaded from Database");
            Assert.AreEqual(3, databasePeople.Count, "Wrong number of people loaded from database");

            int arrayPerson = 0;

            foreach (Person p in databasePeople)
            {
                Assertions.AssertPeopleAreEqual(people[arrayPerson++], p);
            }
        }