public void CanRestartAConversationWithFreshSessions() { ISession s1, s2; using (var c = new ScopedConversation()) { using (new ConversationalScope(c)) { BlogLazy.FindAll(); s1 = BlogLazy.Holder.CreateSession(typeof(BlogLazy)); } c.Restart(); using (new ConversationalScope(c)) { BlogLazy.FindAll(); s2 = BlogLazy.Holder.CreateSession(typeof(BlogLazy)); } Assert.That(s1, Is.Not.SameAs(s2)); Assert.That(s1.IsOpen, Is.False); Assert.That(s2.IsOpen, Is.True); } }
public void CanSetFlushModeToNever() { ArrangeRecords(); using (var conversation = new ScopedConversation(ConversationFlushMode.Explicit)) { BlogLazy blog; using (new ConversationalScope(conversation)) { blog = BlogLazy.FindAll().First(); blog.Author = "Anonymous"; blog.Save(); BlogLazy.FindAll(); // Triggers flushing if allowed } Assert.That(blog.Author, Is.EqualTo("Anonymous")); // Outside any ConversationalScope session-per-request is used Assert.That(BlogLazy.FindAll().First().Author, Is.EqualTo("Markus")); conversation.Flush(); } Assert.That(BlogLazy.FindAll().First().Author, Is.EqualTo("Anonymous")); }
public void BasicScenario() { // Arrange ArrangeRecords(); // Act IScopeConversation conversation = new ScopedConversation(); BlogLazy queriedBlog; using (new ConversationalScope(conversation)) { queriedBlog = BlogLazy.Find(1); } // No scope here var fetchedPosts = queriedBlog.PublishedPosts; var firstPost = fetchedPosts[0] as PostLazy; firstPost.Published = false; using (new ConversationalScope(conversation)) { firstPost.SaveAndFlush(); queriedBlog.Refresh(); } // Assert // Again, we're querying lazy properties out of scope Assert.That(queriedBlog.PublishedPosts, Is.Empty); Assert.That(queriedBlog.Posts, Is.Not.Empty); conversation.Dispose(); }
public void CannotSetFlushModeAfterUsingTheConversation() { using (var c = new ScopedConversation()) { using (new ConversationalScope(c)) { BlogLazy.FindAll(); } var ex = Assert.Throws <ActiveRecordException>( () => c.FlushMode = ConversationFlushMode.Explicit); Assert.That(ex.Message, Is.Not.Null .And.Contains("FlushMode") .And.Contains("set") .And.Contains("after") .And.Contains("session")); } }
public void ThrowsReasonableErrorMessageWhenUsedAfterCancel() { using (var conversation = new ScopedConversation()) { conversation.Cancel(); var ex = Assert.Throws <ActiveRecordException>(() => { using (new ConversationalScope(conversation)) BlogLazy.FindAll(); } ); Assert.That(ex.Message.Contains("cancel")); Assert.That(ex.Message.Contains("ConversationalScope")); Assert.That(ex.Message.Contains("session")); Assert.That(ex.Message.Contains("request")); } }
private void ArrangeRecords() { BlogLazy blog = new BlogLazy() { Author = "Markus", Name = "Conversations" }; PostLazy post = new PostLazy() { Blog = blog, Category = "Scenario", Title = "The Convesration is here", Contents = "A new way for AR in fat clients", Created = new DateTime(2010, 1, 1), Published = true }; blog.Save(); post.Save(); }
public void CanCancelConversations() { ArrangeRecords(); using (var conversation = new ScopedConversation()) { BlogLazy blog = null; using (new ConversationalScope(conversation)) { blog = BlogLazy.FindAll().First(); } blog.Author = "Somebody else"; using (new ConversationalScope(conversation)) { blog.SaveAndFlush(); } conversation.Cancel(); } Assert.That(BlogLazy.FindAll().First().Author, Is.EqualTo("Markus")); }
public void CanUseIConversationDirectly() { ArrangeRecords(); using (IConversation conversation = new ScopedConversation()) { BlogLazy blog = null; conversation.Execute(() => { blog = BlogLazy.FindAll().First(); }); Assert.That(blog, Is.Not.Null); Assume.That(blog.Author, Is.EqualTo("Markus")); // Lazy access Assert.That(blog.PublishedPosts.Count, Is.EqualTo(1)); blog.Author = "Anonymous"; conversation.Execute(() => blog.Save()); } Assert.That(BlogLazy.FindAll().First().Author, Is.EqualTo("Anonymous")); }
public void SessionsAreKeptThroughoutTheConversation() { IScopeConversation conversation = new ScopedConversation(); ISession session = null; using (new ConversationalScope(conversation)) { BlogLazy.FindAll(); session = BlogLazy.Holder.CreateSession(typeof(BlogLazy)); } Assert.That(session.IsOpen); using (new ConversationalScope(conversation)) { BlogLazy.FindAll(); Assert.That(BlogLazy.Holder.CreateSession(typeof(BlogLazy)), Is.SameAs(session)); } conversation.Dispose(); Assert.That(session.IsOpen, Is.False); }