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"));
        }
Example #3
0
        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"));
            }
        }
Example #4
0
        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"));
            }
        }
        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"));
        }
Example #7
0
        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);
        }