Ejemplo n.º 1
0
        public void TwoSubscribersOneComicEach_BuildsTwoMailsEachWithOneComic()
        {
            IList <Mail> mails = null;

            using (var fakeComicFetcher = SelfInitializingFake <IComicFetcher> .For(
                       () => new WebComicFetcher(),
                       new XmlFileRecordedCallRepository("../../../RecordedCalls/TwoSubscribersOneComicEach_BuildsTwoMailsEachWithOneComic.xml")))
            {
                var target = new ComicMailBuilder(
                    DateTime.Now,
                    new SimpleConfigurationParser("[email protected]: 9chickweedlane; [email protected]: dilbert"),
                    fakeComicFetcher.Object,
                    A.Dummy <ILogger>());

                mails = target.CreateMailMessage().ToList();
            }

            mails.Should().HaveCount(2);

            mails[0].From.Address.Should().Be("*****@*****.**");
            mails[0].Personalization[0].Tos.Should().HaveCount(1);
            mails[0].Personalization[0].Tos[0].Address.Should().Be("*****@*****.**");
            mails[0].Contents[0].Value.Should().Contain(ChickweedLaneUrl);

            mails[1].From.Address.Should().Be("*****@*****.**");
            mails[1].Contents[0].Value.Should().Contain(DilbertImageUrl);
            mails[1].Personalization[0].Tos.Should().HaveCount(1);
            mails[1].Personalization[0].Tos[0].Address.Should().Be("*****@*****.**");
        }
Ejemplo n.º 2
0
        public void OneSubscriberOneComicTwiceAsFast_BuildsOneMailWithBothEpisodes()
        {
            IList <Mail> mails = null;

            using (var fakeComicFetcher = SelfInitializingFake <IComicFetcher> .For(
                       () => new WebComicFetcher(),
                       new XmlFileRecordedCallRepository("../../../RecordedCalls/OneSubscriberOneComicTwiceAsFast_BuildsOneMailWithBothEpisodes.xml")))
            {
                var now    = DateTime.Now;
                var target = new ComicMailBuilder(
                    now,
                    new SimpleConfigurationParser($"[email protected]: breaking-cat-news*2-20170327-{now.ToString("yyyyMMdd")}"),
                    fakeComicFetcher.Object,
                    A.Dummy <ILogger>());

                mails = target.CreateMailMessage().ToList();
            }

            mails.Should().HaveCount(1);

            mails[0].From.Address.Should().Be("*****@*****.**");
            mails[0].Personalization[0].Tos.Should().HaveCount(1);
            mails[0].Personalization[0].Tos[0].Address.Should().Be("*****@*****.**");
            mails[0].Contents[0].Value.Should().Contain(BreakingCatNews20170327ImageUrl);
            mails[0].Contents[0].Value.Should().Contain("alt='breaking-cat-news on 27 March 2017'");
            mails[0].Contents[0].Value.Should().Contain(BreakingCatNews20170328ImageUrl);
            mails[0].Contents[0].Value.Should().Contain("alt='breaking-cat-news on 28 March 2017'");
        }
Ejemplo n.º 3
0
        public void FoxtrotOnSunday_MailIncludesComic()
        {
            IList <Mail> mails = null;

            var dateToCheck = MostRecent(DayOfWeek.Sunday);

            using (var fakeComicFetcher = SelfInitializingFake <IComicFetcher> .For(
                       () => new WebComicFetcher(),
                       new XmlFileRecordedCallRepository("../../../RecordedCalls/FoxTrotOnSunday.xml")))
            {
                var target = new ComicMailBuilder(
                    dateToCheck,
                    new SimpleConfigurationParser("[email protected]: foxtrot"),
                    fakeComicFetcher.Object,
                    A.Dummy <ILogger>());

                mails = target.CreateMailMessage().ToList();
            }

            mails.Should().HaveCount(1);

            mails[0].Contents[0].Value.Should()
            .NotContain("Couldn't find comic for foxtrot", "it should not have looked for the comic").And
            .NotContain($"Comic foxtrot wasn't published on {dateToCheck.ToString("dd MMMM yyyy")}.", "it should have found the comic");
        }
Ejemplo n.º 4
0
        public void DinosaurComicOnAWeekend_MailIndicatesComicNotPublishedToday(DayOfWeek dayOfWeek)
        {
            IList <Mail> mails = null;

            var dateToCheck = MostRecent(dayOfWeek);

            using (var fakeComicFetcher = SelfInitializingFake <IComicFetcher> .For(
                       () => new WebComicFetcher(),
                       new XmlFileRecordedCallRepository("../../../RecordedCalls/DinosaurComicsOn" + dayOfWeek + ".xml")))
            {
                var target = new ComicMailBuilder(
                    dateToCheck,
                    new SimpleConfigurationParser("[email protected]: dinosaur-comics"),
                    fakeComicFetcher.Object,
                    A.Dummy <ILogger>());

                mails = target.CreateMailMessage().ToList();
            }

            mails.Should().HaveCount(1);

            mails[0].Contents[0].Value.Should()
            .NotContain("Couldn't find comic for dinosaur-comics", "it should not have looked for the comic").And
            .Contain($"No published comic for dinosaur-comics on {dateToCheck.ToString("dd MMMM yyyy")}.", "it should tell the reader why there's no comic");
        }
Ejemplo n.º 5
0
        public void SubscribesToOneComic_QueriesFetcherWithCorrectUrl(string comic, string expectedUrl)
        {
            var fakeComicFetcher = A.Fake <IComicFetcher>();

            var target = new ComicMailBuilder(
                new DateTime(2018, 6, 27),
                new SimpleConfigurationParser($"[email protected]: {comic}"),
                fakeComicFetcher,
                A.Dummy <ILogger>());

            target.CreateMailMessage().ToList();

            A.CallTo(() => fakeComicFetcher.GetContent(expectedUrl)).MustHaveHappened();
        }
Ejemplo n.º 6
0
        public void OneSubscriberOneComicFiveTimesAsFastOnlyThreeNewComicsLeft_OnlyRequestsThreeComics()
        {
            var today = new DateTime(2019, 2, 19);

            var fakeComicFetcher = A.Fake <IComicFetcher>();
            var target           = new ComicMailBuilder(
                today,
                new SimpleConfigurationParser($"[email protected]: breaking-cat-news*5-20190217-20190219"),
                fakeComicFetcher,
                A.Dummy <ILogger>());

            target.CreateMailMessage().ToList();

            A.CallTo(() => fakeComicFetcher.GetContent(A <string> ._)).MustHaveHappened(3, Times.Exactly);
        }
        public static void OneSubscriberOneComicThreeTimesAsFastWellAfterWeCaughtUp_OnlyRequestsOneComic()
        {
            var today = new DateTime(2020, 4, 10);

            var fakeComicFetcher = A.Fake <IComicFetcher>();
            var target           = new ComicMailBuilder(
                today,
                new ConfigurationParser("[email protected]: breaking-cat-news*3-20170327-20190328"),
                fakeComicFetcher,
                A.Dummy <ILogger>());

            var mailMessages = target.CreateMailMessage().ToList();

            A.CallTo(() => fakeComicFetcher.GetContent(A <Uri> ._)).MustHaveHappened(1, Times.Exactly);
        }
Ejemplo n.º 8
0
        public void SubscribesToComicsKingdomComics_BuildsOneMailWithBothComics()
        {
            IList <Mail> mails = null;

            using (var fakeComicFetcher = SelfInitializingFake <IComicFetcher> .For(
                       () => new WebComicFetcher(),
                       new XmlFileRecordedCallRepository("../../../RecordedCalls/SubscribesToComicsKingdomComics_BuildsOneMailWithBothComics.xml")))
            {
                var target = new ComicMailBuilder(
                    new DateTime(2019, 7, 14),
                    new SimpleConfigurationParser("[email protected]: blondie, rhymes-with-orange"),
                    fakeComicFetcher.Object,
                    A.Dummy <ILogger>());

                mails = target.CreateMailMessage().ToList();
            }

            mails.Should().HaveCount(1);

            mails[0].Contents[0].Value.Should()
            .Contain(BlondieUrl, "it should have Blondie").And
            .Contain(RhymesWithOrangeUrl, "it should have Rhymes with Orange");
        }
Ejemplo n.º 9
0
        public void TwoComicsOneThrowsWhenFetched_BuildsOneMailWithOneComicOneError()
        {
            IList <Mail> mails = null;

            var fakeComicFetcher = A.Fake <IComicFetcher>();

            A.CallTo(() => fakeComicFetcher.GetContent("http://rhymeswithorange.com/"))
            .Throws(new WebException("Bad Request"));
            A.CallTo(() => fakeComicFetcher.GetContent("http://www.dilbert.com/"))
            .Returns(@"<img class=""img-responsive img-comic"" src=""//assets.amuniversal.com/cfa39b00b39601365f19005056a9545d"" />");

            var target = new ComicMailBuilder(
                DateTime.Now,
                new SimpleConfigurationParser("[email protected]: rhymeswithorange, dilbert"),
                fakeComicFetcher,
                A.Dummy <ILogger>());

            mails = target.CreateMailMessage().ToList();

            mails.Should().HaveCount(1);

            mails[0].Contents[0].Value.Should().Contain(DilbertImageUrl);
            mails[0].Contents[0].Value.Should().Contain("Couldn't find comic for rhymeswithorange");
        }
Ejemplo n.º 10
0
        public static void CalvinAndHobbesOnSunday_MailIncludesComic()
        {
            IList <Mail> mails = null;

            using (var fakeComicFetcher = SelfInitializingFake <IComicFetcher> .For(
                       () => new WebComicFetcher(),
                       new XmlFileRecordedCallRepository("../../../RecordedCalls/CalvinAndHobbesOnSunday.xml")))
            {
                var dateToCheck = MostRecent(DayOfWeek.Sunday);
                var target      = new ComicMailBuilder(
                    dateToCheck,
                    new ConfigurationParser("[email protected]: calvinandhobbes"),
                    fakeComicFetcher.Object,
                    A.Dummy <ILogger>());

                mails = target.CreateMailMessage().ToList();
            }

            mails.Should().HaveCount(1);

            mails[0].Contents[0].Value.Should()
            .NotContain("Couldn't find comic for calvinandhobbes", "it should not have looked for the comic").And
            .Contain(CalvinAndHobbesSundayUrl, "it should have found the comic");
        }