public void CanAddPerson() { using (var session = sessionFactory.OpenSession()) { var person = new DAL.Entities.Person.Person() { Title = "Mr", FirstName = "TestFirstName04", LastName = "TestLastName04", PersonType = "EM" }; using (var transaction = session.BeginTransaction()) { try { session.SaveOrUpdate(person); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }
public void CanDeletePerson() { //Here we add and then delete the person, so to avoid any referencial integrity errors are being thrown using (var session = sessionFactory.OpenSession()) { int personId = 0; var person = new DAL.Entities.Person.Person() { Title = "Mr", FirstName = "TestFirstName05", LastName = "TestLastName05", PersonType = "EM" }; using (var transaction = session.BeginTransaction()) { try { session.SaveOrUpdate(person); transaction.Commit(); personId = person.Id; Assert.IsTrue(personId > 0); } catch (Exception ex) { transaction.Rollback(); throw ex; } } var personToDelete = session.CreateCriteria <Entities.Person.Person>().List <Entities.Person.Person>().Where(p => p.Id == personId).First(); using (var transaction = session.BeginTransaction()) { try { session.Delete(personToDelete); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }