public void PersonListPresenter_DeleteButtonPressed_DeletesSelectedPersonFromRepository() { // Arrange List <Person> personList = new List <Person>() { PersonObjectMother.GetPerson(TestPeople.Sue), PersonObjectMother.GetPerson(TestPeople.Bill) }; FakePersonManager manager = new FakePersonManager(); FakePersonListView view = new FakePersonListView(); view.PersonList = personList; IPersonListPresenter presenter = new PersonListPresenter(view, manager); ClientServiceLocator.PersonDetailsPresenter = new FakePersonDetailsPresenter(); //Act view.PressDeleteButton(); //Assert Assert.IsNotNull(manager.DeletedPerson, "Person not deleted from repository"); Assertions.AssertPeopleAreEqual(personList[0], manager.DeletedPerson); }
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 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 can_save_person_list() { GenerateDatabaseSchema(); ICollection <Person> personList = new List <Person>(); personList.Add(new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 }); personList.Add(new Person() { Id = 2, Forename = "Sammy", Surname = "Davis", BirthdayDay = 31, BirthdayMonth = 12 }); personList.Add(new Person() { Id = 3, Forename = "Patsy", Surname = "Kensit", BirthdayDay = 1, BirthdayMonth = 1 }); IPersonRepository repository = new PersonRepository(); repository.SaveList(personList); using (ISession session = _sessionFactory.OpenSession()) { foreach (Person p in personList) { Person databasePerson = session.Get <Person>(p.Id); Assert.IsNotNull(databasePerson, "Person not loaded from database"); Assertions.AssertPeopleAreEqual(p, databasePerson); } } }
public void can_update_person() { GenerateDatabaseSchema(); Person p = new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 }; AddPersonToDatabase(p); p.Forename = "John"; p.Surname = "Wayne"; p.BirthdayMonth = 12; p.BirthdayDay = 31; IPersonRepository repository = new PersonRepository(); repository.Update(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 PersonManager_UpdatePerson_UpdatesPersonInRepository() { //Arrange FakePersonRepository mockRepository = new FakePersonRepository(); PersonManager manager = new PersonManager(mockRepository); Person p = PersonObjectMother.GetPerson(TestPeople.Bill); //Act manager.UpdatePerson(p); //Assert Assert.IsNotNull(mockRepository.UpdatedPerson, "Person not updated in repository"); Assertions.AssertPeopleAreEqual(p, mockRepository.UpdatedPerson); }
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 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 PersonDetailsPresenter_OkButtonPressedInEditMode_UpdatesPersonInManager() { // Arrange FakePersonManager manager = new FakePersonManager(); IPersonDetailsPresenter presenter = new PersonDetailsPresenter(new FakeViewFactory(), manager); Person p = PersonObjectMother.GetPerson(TestPeople.Sue); presenter.EditPerson(p); //Act presenter.OkButtonPressed(); //Assert Person updatedPerson = manager.UpdatedPerson; Assert.IsNotNull(updatedPerson, "The person was not updated in the manager"); Assertions.AssertPeopleAreEqual(p, updatedPerson); }
public void PersonManager_GetAll_ReturnsListFromRepository() { // Arrange List <Person> personList = new List <Person>(); personList.Add(new Person() { Id = 1, Forename = "Jimmy", Surname = "Choo", BirthdayDay = 1, BirthdayMonth = 1 }); personList.Add(new Person() { Id = 2, Forename = "Sammy", Surname = "Davis", BirthdayDay = 31, BirthdayMonth = 12 }); personList.Add(new Person() { Id = 3, Forename = "Patsy", Surname = "Kensit", BirthdayDay = 1, BirthdayMonth = 1 }); FakePersonRepository mockRepository = new FakePersonRepository(); mockRepository.PersonList = personList; PersonManager manager = new PersonManager(mockRepository); // Act ICollection <Person> managerPeople = manager.GetAllPeople(); // Assert Assert.AreEqual(3, managerPeople.Count, "The wrong number of people were loaded"); foreach (Person p in managerPeople) { Person testPerson = (from person in personList where person.Id == p.Id select person).Single(); Assertions.AssertPeopleAreEqual(p, testPerson); } }
public void PersonListPresenter_EditButtonPressed_PassesDetailsToPersonDetailsPresenter() { // Arrange List <Person> personList = new List <Person>() { PersonObjectMother.GetPerson(TestPeople.Ted) }; FakePersonManager manager = new FakePersonManager(); FakePersonListView listView = new FakePersonListView(); listView.SetPersonList(personList); IPersonListPresenter listPresenter = new PersonListPresenter(listView, manager); FakePersonDetailsPresenter detailsPresenter = new FakePersonDetailsPresenter(); ClientServiceLocator.PersonDetailsPresenter = detailsPresenter; //Act listView.PressEditButton(); //Assert Assertions.AssertPeopleAreEqual(PersonObjectMother.GetPerson(TestPeople.Ted), detailsPresenter.EditedPerson); }
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); } }