public void EndShouldCloseStartedUnitOfWork() { NhConversation c = NewStartedConversation(); c.End(); ISession s = c.GetSession(sessions); Assert.That(s, Is.Not.Null); Assert.That(s.IsOpen, Is.False); }
public void EndShouldNotFlushPausedUnitOfWork() { NhConversation c = NewPausedConversation(); ISession s = c.GetSession(sessions); var persistedObj = new Silly3(); s.Save(persistedObj); c.End(); AssertDoesNotExistInDb(persistedObj); }
public void EndShouldFlushStartedUnitOfWork() { NhConversation c = NewStartedConversation(); ISession s = c.GetSession(sessions); var persistedObj = new Silly3(); s.Save(persistedObj); c.End(); AssertExistsInDb(persistedObj); }
public void ManualUnbindSessionDoNotCreateProblemsInARunningConversation() { NhConversation c = NewStartedConversation(); ISession s = c.GetSession(sessions); c.Unbind(s); Assert.That(c.GetSession(sessions), Is.Null, "A session still bind after manual Unbind."); c.Resume(); Assert.That(c.GetSession(sessions).IsOpen); c.End(); }
public void StartAfterEndShouldStartAnotherUnitOfWork() { NhConversation c = NewStartedConversation(); ISession previousUoW = c.GetSession(sessions); c.End(); c.Start(); ISession currentUoW = c.GetSession(sessions); AssertIsOpen(currentUoW); Assert.That(currentUoW, Is.Not.SameAs(previousUoW)); }
public void ConversationUsage() { CommitInNewSession(session => { var o = new Other3 { Name = "some other silly" }; var e = new Silly3 { Name = "somebody", Other = o }; session.Save(e); }); using (NhConversation c = NewConversation()) { c.Start(); ISession s = c.GetSession(sessions); IList <Silly3> sl = s.CreateQuery("from Silly3").List <Silly3>(); c.Pause(); Assert.That(sl.Count == 1); Assert.That(!NHibernateUtil.IsInitialized(sl[0].Other)); // working with entities, even using lazy loading Assert.That(!s.Transaction.IsActive); Assert.That("some other silly", Is.EqualTo(sl[0].Other.Name)); Assert.That(NHibernateUtil.IsInitialized(sl[0].Other)); sl[0].Other.Name = "nobody"; c.Resume(); s = c.GetSession(sessions); s.SaveOrUpdate(sl[0]); // the dispose auto-end the conversation } using (NhConversation c = NewConversation()) { c.Start(); ISession s = c.GetSession(sessions); s.Delete("from Silly3"); c.End(); } }