public void AddPersonWithCommsTest() { //setup var facade = new PersonFacade(new SessionFactoryHelper(), new PersonRepository(), new CommunicationRepository()); var person = new Person() { Name = "Person Two", CreatedBy = _user, UpdatedBy = _user }; person.Communications.Add(new Communication() { CommunicationType = new CommunicationType() { Value = "Email" }, Detail = "*****@*****.**", CreatedBy = _user, UpdatedBy = _user });/* person.Communications.Add(new Communication() { CommunicationType = new CommunicationType() { Value = "Phone" }, Detail = "0299990000", CreatedBy = _user, UpdatedBy = _user });*/ //act person = facade.SavePerson(person); //assert Assert.IsNotNull(person); Assert.AreNotEqual(0, person.Id); Assert.AreEqual("Person Two", person.Name); Assert.AreEqual("*****@*****.**", person.Communications.First().Detail); }
public void CreatePersonTest() { //setup var facade = new PersonFacade(new SessionFactoryHelper(), new PersonRepository(), new CommunicationRepository()); var person = new Person() { Name = "Person One", CreatedBy = _user, UpdatedBy = _user }; //act person = facade.SavePerson(person); //assert Assert.IsNotNull(person); Assert.AreNotEqual(0, person.Id); Assert.AreEqual("Person One", person.Name); }
public Person SavePerson(Person person) { using (var session = _sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { var existing = _personRepository.FetchPerson(person.Name, session); var personToSave = existing == null ? new Person() { Name = person.Name, UpdatedBy = person.UpdatedBy, CreatedBy = person.CreatedBy } : existing; foreach (var item in person.Communications) { item.CommunicationType = session.Query<CommunicationType>().Where(x => x.Value == item.CommunicationType.Value).First(); personToSave.Communications.Add(item); } _personRepository.Save(personToSave, session); transaction.Commit(); return personToSave; } } }