private void RunJob(Settings setting, Func<EmailNotificationItem, bool> predicateBuilder)
        {
            var emailNotificationItems = _emailNotificationItems.GetEmailNotificationItems(setting)
                .Where(x => x.Deadline.Date >= _date.GetNow().Date).Where(predicateBuilder);

            foreach (var grp in emailNotificationItems.GroupBy(x => x.Email))
            {
                if (!String.IsNullOrEmpty(grp.Key))
                {
                    _log.Msg("          Email sent to: " + grp.Key);
                    _sendEmail.SendEmail(grp.Key, _emailFrom, setting.EmailSubject, String.Join("\r\n", grp.OrderBy(x => x.Deadline).Select(x => x.Deadline.ToString("dd-MM-yyyy") + " - " + x.Text).ToArray()));
                }
            }
        }
Example #2
0
        EmailNotification.EmailNotification Substitute(DateTime now)
        {
            _logging = NSubstitute.Substitute.For<ILog>();
            _date = NSubstitute.Substitute.For<IDate>();
            _settings = NSubstitute.Substitute.For<ISettings>();
            _emailNotificationItems = NSubstitute.Substitute.For<IEmailNotificationItems>();
            _status = NSubstitute.Substitute.For<IStatus>();
            _sendEmail = NSubstitute.Substitute.For<IEmail>();

            _now = now;
            _date.GetNow().Returns(now);

            _setting = new Settings
                {
                    Id = Guid.NewGuid(),
                    CsvFile = "csvFile"
                };

            _statusItem = new Status
                {
                    LastRun = DateTime.MinValue
                };

            _settings.GetSettingsFromUrl("url").Returns(_setting);

            _status.GetStatus(_setting.Id).Returns(_statusItem);

            _emailNotificationItemList = new List<EmailNotificationItem> {
                    new EmailNotificationItem
                    {
                        Deadline = now.AddDays(-1),
                        Email = "*****@*****.**",
                        Text = "Text1234"
                    },

                    new EmailNotificationItem
                    {
                        Deadline = now,
                        Email = "*****@*****.**",
                        Text = "Text"
                    },
                    new EmailNotificationItem
                    {
                        Deadline = now.AddDays(3),
                        Email = "*****@*****.**",
                        Text = "Text3"
                    },
                    new EmailNotificationItem
                    {
                        Deadline = now.AddDays(7),
                        Email = "*****@*****.**",
                        Text = "Text7"
                    },
                    new EmailNotificationItem
                    {
                        Deadline = now.AddDays(14),
                        Email = "*****@*****.**",
                        Text = "Text14"
                    },
                    new EmailNotificationItem
                    {
                        Deadline = now.AddDays(21),
                        Email = "*****@*****.**",
                        Text = "Text21"
                    },
                    new EmailNotificationItem
                    {
                        Deadline = now.AddDays(25),
                        Email = "*****@*****.**",
                        Text = "Text25"
                    },
                    new EmailNotificationItem
                    {
                        Deadline = now.AddDays(35),
                        Email = "*****@*****.**",
                        Text = "Text35"
                    }
            };

            _emailNotificationItems.GetEmailNotificationItems(_setting).Returns(
               _emailNotificationItemList
            );

            EmailNotification.EmailNotification repo = new EmailNotification
            .EmailNotification(_logging, _date, _settings, _emailNotificationItems, _sendEmail, _status, "emailFrom", "url");

            return repo;
        }