예제 #1
0
        public void ReadAndProcess_FeedWithEmptyPage0_ShouldNotReadAllItems_EmptyPageOnFeedExceptionThrown()
        {
            // Arrange

            var atomFeedProcessor = new AtomFeedProcessor((uri) =>
            {
                if (uri == "http://page0/")
                {
                    return(GetEmptyPage(next_url: "http://page1"));
                }
                if (uri == "http://page1/")
                {
                    return(GetFeedPage1(prev_url: "http://page0"));
                }
                return(null);
            });

            // Act
            atomFeedProcessor.ReadAndProcess(
                "http://page1/",
                shouldReadAllItems: () => false,
                isPreviouslyReadItem: item => false,
                processItem: item => item,
                afterLastItemProcessed: (item, uri) => { });
        }
예제 #2
0
        public void ReadAndProcess_FeedWithNoItems_ShouldNotReadAllItems_AfterLastItemProcessedCalled()
        {
            // Arrange
            var afterLastItemProcessedCalled = false;
            var atomFeedProcessor            = new AtomFeedProcessor((uri) => GetEmptyPage());

            // Act
            atomFeedProcessor.ReadAndProcess(
                "test",
                shouldReadAllItems: () => false,
                isPreviouslyReadItem: item => false,
                processItem: item => item,
                afterLastItemProcessed: (item, uri) => { afterLastItemProcessedCalled = true; });

            // Assert
            Assert.AreEqual(true, afterLastItemProcessedCalled);
        }
예제 #3
0
        public void ReadAndProcess_FeedWithOnePage_MatchingSearchValueFound_ElementsAfterMatchingSearchValueRead()
        {
            // Arrange
            var lastReadId = "Id1";
            var afterLastItemProcessedCalled = false;
            var atomFeedProcessor            = new AtomFeedProcessor((uri) => GetFeedPage0());

            // Act
            var actual = atomFeedProcessor.ReadAndProcess("test",
                                                          shouldReadAllItems: () => false,
                                                          isPreviouslyReadItem: item => item.Id == lastReadId,
                                                          processItem: item => item,
                                                          afterLastItemProcessed: (item, uri) => { afterLastItemProcessedCalled = true; }).ToList();

            // Assert
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual("Id2", actual[0].Id);
            Assert.AreEqual("Item 2", actual[0].Title.Text);
            Assert.AreEqual(false, afterLastItemProcessedCalled);
        }
예제 #4
0
        public void ReadAndProcess_FeedWithMultiplePages_SearchValueAsEmpty_AllItemsRetreived()
        {
            // Arrange
            var lastReadItemId = string.Empty;
            var afterLastItemProcessedCalled = false;
            var atomFeedProcessor            = new AtomFeedProcessor((uri) =>
            {
                if (uri == "http://page0/")
                {
                    return(GetFeedPage0(next_url: "http://page1"));
                }
                if (uri == "http://page1/")
                {
                    return(GetFeedPage1(prev_url: "http://page0"));
                }
                return(null);
            });

            // Act
            var actual = new List <SyndicationItem>();

            actual.AddRange(atomFeedProcessor.ReadAndProcess(
                                "http://page0/",
                                shouldReadAllItems: () => true,
                                isPreviouslyReadItem: item => item.Id == lastReadItemId,
                                processItem: item => item,
                                afterLastItemProcessed: (item, uri) => { afterLastItemProcessedCalled = true; }));

            // Assert
            Assert.AreEqual(4, actual.Count);
            Assert.AreEqual("Id1", actual[0].Id);
            Assert.AreEqual("Id2", actual[1].Id);
            Assert.AreEqual("Id3", actual[2].Id);
            Assert.AreEqual("Id4", actual[3].Id);
            Assert.AreEqual("Item 1", actual[0].Title.Text);
            Assert.AreEqual("Item 2", actual[1].Title.Text);
            Assert.AreEqual("Item 3", actual[2].Title.Text);
            Assert.AreEqual("Item 4", actual[3].Title.Text);
            Assert.AreEqual(true, afterLastItemProcessedCalled);
        }