Пример #1
0
        public static async Task Does_not_send_emails_to_users_with_cancelled_requests()
        {
            var weeklyNotificationDates = new[] { 21.December(2020), 24.December(2020) };

            var mockDateCalculator = new Mock <IDateCalculator>(MockBehavior.Strict);

            mockDateCalculator.Setup(c => c.GetWeeklyNotificationDates()).Returns(weeklyNotificationDates);

            var mockEmailRepository = new Mock <IEmailRepository>();

            var requests = new[] { new Request("user1", weeklyNotificationDates.First(), RequestStatus.Cancelled) };

            var mockRequestRepository = new Mock <IRequestRepository>(MockBehavior.Strict);

            mockRequestRepository
            .Setup(r => r.GetRequests(weeklyNotificationDates.First(), weeklyNotificationDates.Last()))
            .ReturnsAsync(requests);

            var mockUserRepository = new Mock <IUserRepository>(MockBehavior.Strict);

            mockUserRepository.Setup(r => r.GetUsers()).ReturnsAsync(new List <User>());

            var weeklyNotification = new WeeklyNotification(
                mockDateCalculator.Object,
                mockEmailRepository.Object,
                mockRequestRepository.Object,
                mockUserRepository.Object);

            await weeklyNotification.Run();

            mockEmailRepository.VerifyNoOtherCalls();
        }
Пример #2
0
        public static void ScheduledTaskType_returns_WeeklyNotification()
        {
            var dailySummary = new WeeklyNotification(
                Mock.Of <IDateCalculator>(),
                Mock.Of <IEmailRepository>(),
                Mock.Of <IRequestRepository>(),
                Mock.Of <IUserRepository>());

            Assert.Equal(ScheduledTaskType.WeeklyNotification, dailySummary.ScheduledTaskType);
        }
Пример #3
0
        public static async Task Sends_emails_to_users_with_requests()
        {
            var weeklyNotificationDates = new[] { 21.December(2020), 24.December(2020) };

            var mockDateCalculator = new Mock <IDateCalculator>(MockBehavior.Strict);

            mockDateCalculator.Setup(c => c.GetWeeklyNotificationDates()).Returns(weeklyNotificationDates);

            var mockEmailRepository = new Mock <IEmailRepository>();

            var requests = new[]
            {
                new Request("user1", weeklyNotificationDates.First(), RequestStatus.Allocated),
                new Request("user2", weeklyNotificationDates.Last(), RequestStatus.Interrupted)
            };

            var mockRequestRepository = new Mock <IRequestRepository>(MockBehavior.Strict);

            mockRequestRepository
            .Setup(r => r.GetRequests(weeklyNotificationDates.First(), weeklyNotificationDates.Last()))
            .ReturnsAsync(requests);

            var users = new[]
            {
                CreateUser.With(userId: "user1", emailAddress: "*****@*****.**"),
                CreateUser.With(userId: "user2", emailAddress: "*****@*****.**"),
            };

            var mockUserRepository = new Mock <IUserRepository>(MockBehavior.Strict);

            mockUserRepository.Setup(r => r.GetUsers()).ReturnsAsync(users);

            var weeklyNotification = new WeeklyNotification(
                mockDateCalculator.Object,
                mockEmailRepository.Object,
                mockRequestRepository.Object,
                mockUserRepository.Object);

            await weeklyNotification.Run();

            mockEmailRepository.Verify(
                r => r.Send(It.Is <IEmailTemplate>(e =>
                                                   e.To == "*****@*****.**" && e.Subject == "Provisional parking status for Mon 21 Dec - Thu 24 Dec")),
                Times.Once);
            mockEmailRepository.Verify(
                r => r.Send(It.Is <IEmailTemplate>(e =>
                                                   e.To == "*****@*****.**" && e.Subject == "Provisional parking status for Mon 21 Dec - Thu 24 Dec")),
                Times.Once);

            mockEmailRepository.VerifyNoOtherCalls();
        }
Пример #4
0
        public static void GetNextRunTime_uses_London_time_zone()
        {
            var dateCalculator = CreateDateCalculator(27.March(2020).At(0, 2, 0).Utc());

            var actual = new WeeklyNotification(
                dateCalculator,
                Mock.Of <IEmailRepository>(),
                Mock.Of <IRequestRepository>(),
                Mock.Of <IUserRepository>()).GetNextRunTime();

            var expected = 1.April(2020).At(23, 2, 0).Utc();

            Assert.Equal(expected, actual);
        }
Пример #5
0
        public static void GetNextRunTime_returns_midnight_on_next_Thursday(int currentDay, int expectedNextDay)
        {
            var dateCalculator = CreateDateCalculator(currentDay.December(2020).At(0, 2, 0).Utc());

            var actual = new WeeklyNotification(
                dateCalculator,
                Mock.Of <IEmailRepository>(),
                Mock.Of <IRequestRepository>(),
                Mock.Of <IUserRepository>()).GetNextRunTime();

            var expected = expectedNextDay.December(2020).At(0, 2, 0).Utc();

            Assert.Equal(expected, actual);
        }