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("*****@*****.**"); }
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'"); }
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"); }
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"); }
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(); }
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); }
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"); }
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"); }
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"); }