Esempio n. 1
0
        public void GetFeedItemsByGenre_FeedItemHtmlParserParseThrowsException_LogsErrorAndThrowsBoomkatServiceException()
        {
            var feedItemHtmlParserFake = A.Fake <IFeedItemHtmlParser>();
            var pages = (IList <string>)null;

            A.CallTo(() => feedItemHtmlParserFake.Parse(A <IHtmlDocument> .Ignored, out pages)).Throws(new Exception("foo"));
            var logFactoryFake = A.Fake <ILogFactory>();
            var logFake        = A.Fake <ILog>();

            A.CallTo(() => logFactoryFake.GetLogger(A <Type> .Ignored)).Returns(logFake);

            var feedItemService = new FeedItemService(
                feedItemHtmlParserFake,
                A.Fake <IHtmlWebFactory>(),
                A.Fake <IUrlBuilder>(),
                logFactoryFake);

            try {
                var feedItemsResult = feedItemService.GetFeedItemsByGenre(2, 1);
            }
            catch (Exception ex) {
                Assert.That(ex, Is.TypeOf <BoomkatServiceException>());
            }

            A.CallTo(() => logFake.ErrorFormat(A <string> .Ignored, A <object[]> .Ignored)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void FeedItemsByGenre_ReturnsFeedItemsResult()
        {
            var urlBuilderFake = A.Fake <IUrlBuilder>();

            A.CallTo(() => urlBuilderFake.BuildFeedItemByGenreUrl(A <int> .Ignored, A <int> .Ignored)).Returns("http://boomkat.com/genres/133/summary/page/1");
            var boomkatConfigurationFake = A.Fake <IBoomkatConfiguration>();

            A.CallTo(() => boomkatConfigurationFake.SiteUrl).Returns("http://boomkat.com");

            var feedItemService = new FeedItemService(
                new FeedItemHtmlParser(boomkatConfigurationFake),
                new HtmlWebFactory(A.Fake <IHtmlWebConfiguration>()),
                urlBuilderFake,
                A.Fake <ILogFactory>());

            var feedItemsResult = feedItemService.GetFeedItemsByGenre(133, 1);

            Assert.That(feedItemsResult, Is.Not.Null);
            Assert.That(feedItemsResult.Items, Is.Not.Empty);
            Assert.That(feedItemsResult.Items[0].Artist, Is.Not.Empty);
            Assert.That(feedItemsResult.Items[0].Album, Is.Not.Empty);
            Assert.That(feedItemsResult.Items[0].Url, Is.Not.Empty);
            Assert.That(feedItemsResult.Pages, Is.Not.Empty);
        }
Esempio n. 3
0
        public void GetFeedItemsByGenre_FeedItemHtmlParserParseReturnsFeedItems_ReturnsFeedItemsResultWithDistinctFeedItems()
        {
            var feedItemHtmlParserFake = A.Fake <IFeedItemHtmlParser>();
            var pages = (IList <string>)null;

            A.CallTo(() => feedItemHtmlParserFake.Parse(A <IHtmlDocument> .Ignored, out pages)).Returns(new List <IFeedItem> {
                new FeedItem {
                    Album = "abc", Artist = "def", Url = "ghi"
                }, new FeedItem {
                    Album = "abc", Artist = "def", Url = "ghi"
                }
            });

            var feedItemService = new FeedItemService(
                feedItemHtmlParserFake,
                A.Fake <IHtmlWebFactory>(),
                A.Fake <IUrlBuilder>(),
                A.Fake <ILogFactory>());

            var feedItemsResult = feedItemService.GetFeedItemsByGenre(2, 1);

            Assert.That(feedItemsResult, Is.Not.Null);
            Assert.That(feedItemsResult.Items.Count, Is.EqualTo(1));
        }