public void RunMailService_UnnotifiedNotifications_ShouldCall_SendMails_ButNotAddNewNotification() { var preLength = repoMock.AsQueryable().ToList().Count; var customText1 = "customText1"; var customText2 = ""; var datetimeNoMilisec = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); var mailSub = NSubstitute.Substitute.For <IMailService>(); var substituteSub = NSubstitute.Substitute.For <ISubstituteService>(); var notification1 = repoMock.noti1 = new MailNotificationSchedule() { Id = 1, DateTimestamp = Utilities.ToUnixTime(datetimeNoMilisec), FileGenerationSchedule = new FileGenerationSchedule { DateTimestamp = Utilities.ToUnixTime(datetimeNoMilisec) }, CustomText = customText1 }; repoMock.noti2 = new MailNotificationSchedule() { Id = 2, DateTimestamp = Utilities.ToUnixTime(DateTime.Now.AddDays(1)), FileGenerationSchedule = new FileGenerationSchedule { DateTimestamp = Utilities.ToUnixTime(datetimeNoMilisec) }, CustomText = customText2 }; repoMock.ReSeed(); var uut = new ConsoleMailerService(mailSub, substituteSub, repoMock, _logger, _customSettings); uut.RunMailService(); mailSub.Received().SendMails(datetimeNoMilisec, customText1); mailSub.DidNotReceive().SendMails(datetimeNoMilisec, customText2); Assert.AreEqual(preLength, repoMock.AsQueryable().ToList().Count); }
public void RunMailService_UnnotifiedNotifications_ShouldCall_SendMails_ButNotAddNewNotification() { var preLength = repoMock.AsQueryable().ToList().Count; var mailSub = NSubstitute.Substitute.For <IMailService>(); repoMock.noti1 = new MailNotificationSchedule() { Id = 1, DateTimestamp = ToUnixTime(DateTime.Now), Notified = false, Repeat = false }; repoMock.noti2 = new MailNotificationSchedule() { Id = 2, DateTimestamp = ToUnixTime(DateTime.Now.AddDays(1)), Notified = false, Repeat = false }; repoMock.ReSeed(); var uut = new ConsoleMailerService(mailSub, repoMock, _logger); uut.RunMailService(); mailSub.ReceivedWithAnyArgs().SendMails(new DateTime()); Assert.AreEqual(preLength, repoMock.AsQueryable().ToList().Count); }