GetPreviousAndNextEntries() public method

Returns the previous and next entry to the specified entry.
public GetPreviousAndNextEntries ( int entryId, PostType postType ) : IList
entryId int
postType PostType
return IList
コード例 #1
0
        public void GetPreviousAndNextBasedOnSyndicationDateNotEntryId()
        {
            var repository = new DatabaseObjectProvider();
            string hostname = UnitTestHelper.GenerateUniqueString();
            repository.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = repository.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(repository);
            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 = repository.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.");
        }
コード例 #2
0
        public void GetPreviousAndNextEntriesReturnsBoth()
        {
            var repository = new DatabaseObjectProvider();
            string hostname = UnitTestHelper.GenerateUniqueString();
            repository.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty);

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

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

            var entries = repository.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.");
        }
コード例 #3
0
        public void GetPreviousAndNextEntriesReturnsPreviousWhenNoNextExists()
        {
            string hostname = UnitTestHelper.GenerateUniqueString();
            var repository = new DatabaseObjectProvider();
            repository.CreateBlog("", "username", "password", hostname, string.Empty);
            UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty);
            BlogRequest.Current.Blog = repository.GetBlog(hostname, string.Empty);

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

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

            var entries = repository.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.");
        }