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()); }
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); }
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); } }
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); } }
public void Add_PersonIsNull_ExceptionNotThrown() { var repository = new PersonRepository(); repository.Add(null); }
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); } }