PreviousNextTests.cs :  » Bloggers » SubText » UnitTests » Subtext » Framework » Components » EntryTestsi » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » UnitTests » Subtext » Framework » Components » EntryTestsi » PreviousNextTests.cs
#region Disclaimer/Info

///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at subtext@googlegroups.com 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.Linq;
using System.Threading;
using MbUnit.Framework;
using Moq;
using Subtext.Extensibility;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Configuration;
using Subtext.Framework.Providers;
using Subtext.Framework.Web.HttpModules;

namespace UnitTests.Subtext.Framework.Components.EntryTestsi{
    /// <summary>
    /// Tests the methods to obtain the previous and next entry to an entry.
    /// </summary>
    [TestFixture]
    public class PreviousNextTests
    {
        /// <summary>
        /// Test the case where we have a previous, but no next entry.
        /// </summary>
        [Test]
        [RollBack]
        public void GetPreviousAndNextEntriesReturnsPreviousWhenNoNextExists()
        {
            string hostname = UnitTestHelper.GenerateUniqueString();
            Config.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostname, string.Empty);

            Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                   UnitTestHelper.GenerateUniqueString(),
                                                                                   DateTime.Now.AddDays(-1));
            Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                  UnitTestHelper.GenerateUniqueString(),
                                                                                  DateTime.Now);

            int previousId = UnitTestHelper.Create(previousEntry);
            int currentId = UnitTestHelper.Create(currentEntry);

            var entries = ObjectProvider.Instance().GetPreviousAndNextEntries(currentId,
                                                                                             PostType.BlogPost);
            Assert.AreEqual(1, entries.Count, "Since there is no next entry, should return only 1");
            Assert.AreEqual(previousId, entries.First().Id, "The previous entry does not match expectations.");
        }

        /// <summary>
        /// Test the case where we have a next, but no previous entry.
        /// </summary>
        [Test]
        [RollBack]
        public void GetPreviousAndNextEntriesReturnsNextWhenNoPreviousExists()
        {
            string hostname = UnitTestHelper.GenerateUniqueString();
            Config.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostname, string.Empty);

            Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                  UnitTestHelper.GenerateUniqueString(),
                                                                                  DateTime.Now.AddDays(-1));
            Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                               UnitTestHelper.GenerateUniqueString(),
                                                                               DateTime.Now);

            int currentId = UnitTestHelper.Create(currentEntry);
            int nextId = UnitTestHelper.Create(nextEntry);

            var entries = ObjectProvider.Instance().GetPreviousAndNextEntries(currentId,
                                                                                             PostType.BlogPost);
            Assert.AreEqual(1, entries.Count, "Since there is no previous entry, should return only next");
            Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations.");
        }

        /// <summary>
        /// Test the case where we have both a previous and next.
        /// </summary>
        [Test]
        [RollBack]
        public void GetPreviousAndNextEntriesReturnsBoth()
        {
            string hostname = UnitTestHelper.GenerateUniqueString();
            Config.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostname, string.Empty);

            Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                   UnitTestHelper.GenerateUniqueString(),
                                                                                   DateTime.Now.AddDays(-2));
            Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                  UnitTestHelper.GenerateUniqueString(),
                                                                                  DateTime.Now.AddDays(-1));
            Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                               UnitTestHelper.GenerateUniqueString(),
                                                                               DateTime.Now);

            int previousId = UnitTestHelper.Create(previousEntry);
            Thread.Sleep(100);
            int currentId = UnitTestHelper.Create(currentEntry);
            Thread.Sleep(100);
            int nextId = UnitTestHelper.Create(nextEntry);

            var entries = ObjectProvider.Instance().GetPreviousAndNextEntries(currentId,
                                                                                             PostType.BlogPost);
            Assert.AreEqual(2, entries.Count, "Expected both previous and next.");

            //The more recent one is next because of desceding sort.
            Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations.");
            Assert.AreEqual(previousId, entries.ElementAt(1).Id, "The previous entry does not match expectations.");
        }

        /// <summary>
        /// Test the case where we have more than three entries.
        /// </summary>
        [Test]
        [RollBack]
        public void GetPreviousAndNextEntriesReturnsCorrectEntries()
        {
            string hostname = UnitTestHelper.GenerateUniqueString();
            Config.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostname, string.Empty);

            Entry firstEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                UnitTestHelper.GenerateUniqueString(),
                                                                                DateTime.Now.AddDays(-3));
            Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                   UnitTestHelper.GenerateUniqueString(),
                                                                                   DateTime.Now.AddDays(-2));
            Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                                  UnitTestHelper.GenerateUniqueString(),
                                                                                  DateTime.Now.AddDays(-1));
            Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                               UnitTestHelper.GenerateUniqueString(),
                                                                               DateTime.Now);
            Entry lastEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body",
                                                                               UnitTestHelper.GenerateUniqueString(),
                                                                               DateTime.Now.AddDays(1));

            Thread.Sleep(100);
            int previousId = UnitTestHelper.Create(previousEntry);
            Thread.Sleep(100);
            int currentId = UnitTestHelper.Create(currentEntry);
            Thread.Sleep(100);
            int nextId = UnitTestHelper.Create(nextEntry);
            Thread.Sleep(100);

            var entries = ObjectProvider.Instance().GetPreviousAndNextEntries(currentId, PostType.BlogPost);
            Assert.AreEqual(2, entries.Count, "Expected both previous and next.");

            //The more recent one is next because of desceding sort.
            Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations.");
            Assert.AreEqual(previousId, entries.ElementAt(1).Id, "The previous entry does not match expectations.");
        }

        /// <summary>
        /// Make sure that previous and next are based on syndication date and not entry id.
        /// </summary>
        [Test]
        [RollBack]
        public void GetPreviousAndNextBasedOnSyndicationDateNotEntryId()
        {
            string hostname = UnitTestHelper.GenerateUniqueString();
            Config.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = Config.GetBlog(hostname, string.Empty);

            Entry previousEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body");
            Entry currentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body");
            Entry nextEntry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "test", "body");

            previousEntry.IsActive = false;
            currentEntry.IsActive = false;
            nextEntry.IsActive = false;

            //Create out of order.
            int currentId = UnitTestHelper.Create(currentEntry);
            int nextId = UnitTestHelper.Create(nextEntry);
            int previousId = UnitTestHelper.Create(previousEntry);

            //Now syndicate.
            previousEntry.IsActive = true;
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog);
            subtextContext.Setup(c => c.Repository).Returns(ObjectProvider.Instance());
            UnitTestHelper.Update(previousEntry, subtextContext.Object);
            Thread.Sleep(100);
            currentEntry.IsActive = true;
            UnitTestHelper.Update(currentEntry, subtextContext.Object);
            Thread.Sleep(100);
            nextEntry.IsActive = true;
            UnitTestHelper.Update(nextEntry, subtextContext.Object);

            Assert.IsTrue(previousId > currentId, "Ids are out of order.");

            var entries = ObjectProvider.Instance().GetPreviousAndNextEntries(currentId, PostType.BlogPost);
            Assert.AreEqual(2, entries.Count, "Expected both previous and next.");
            //The first should be next because of descending sort.
            Assert.AreEqual(nextId, entries.First().Id, "The next entry does not match expectations.");
            Assert.AreEqual(previousId, entries.ElementAt(1).Id, "The previous entry does not match expectations.");
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.