public void MegaNHibernateUnitOfWorkFactory_Should_Create_New_Instances_Of_Unit_Of_Work() { var factory = new MegaNHibernateUnitOfWorkFactory(); var uow1 = factory.Create(); var uow2 = factory.Create(); Assert.AreNotSame(uow1, uow2); uow2.Dispose(); uow1.Dispose(); }
public void Can_Use_UoW_To_Remove_And_Add_Customer_In_A_Transaction() { using (var uow = new MegaNHibernateUnitOfWorkFactory().Create()) { var repo = new RepositoryFactory().Create(uow); var c1 = repo.All <Customer>().Single(c => c.Email == "*****@*****.**"); repo.Delete(c1); var c2 = GetCustomer(); repo.Add(c2); c2.Country = "Italy"; repo.Update(c2); uow.Commit(); } using (var repo = new RepositoryFactory().Create()) { var x = repo.All <Customer>().SingleOrDefault(c => c.Email == "*****@*****.**"); Assert.IsNull(x); var y = repo.All <Customer>().Any(c => c.Country == "Italy"); Assert.IsTrue(y); } }