コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
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);
        }
コード例 #4
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);
        }