Exemplo n.º 1
0
        public static async Task Does_not_notify_user_for_other_request_statuses(RequestStatus requestStatus)
        {
            var users = new[] { CreateUser.With(userId: "user1", emailAddress: "*****@*****.**") };

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

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

            var requests = new[]
            {
                new Request("user1", 11.January(2021), requestStatus),
            };

            var mockEmailRepository = new Mock <IEmailRepository>();

            var allocationNotifier = new AllocationNotifier(
                Mock.Of <ILogger <AllocationNotifier> >(),
                CreateDummyDateCalculator(),
                mockEmailRepository.Object,
                CreateDummyScheduleRepository(),
                mockUserRepository.Object);

            await allocationNotifier.Notify(requests);

            mockEmailRepository.VerifyNoOtherCalls();
        }
Exemplo n.º 2
0
        public static async Task Does_not_notify_user_when_request_will_appear_on_scheduled_weekly_notification()
        {
            var users = new[] { CreateUser.With(userId: "user1", emailAddress: "*****@*****.**") };

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

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

            var requests = new[]
            {
                new Request("user1", 11.January(2021), RequestStatus.Allocated),
                new Request("user1", 12.January(2021), RequestStatus.Allocated)
            };

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

            mockDateCalculator
            .Setup(c => c.ScheduleIsDue(
                       It.Is <Schedule>(s => s.ScheduledTaskType == ScheduledTaskType.DailyNotification),
                       Duration.FromMinutes(2)))
            .Returns(false);
            mockDateCalculator
            .Setup(c => c.ScheduleIsDue(
                       It.Is <Schedule>(s => s.ScheduledTaskType == ScheduledTaskType.WeeklyNotification),
                       Duration.FromMinutes(2)))
            .Returns(true);
            mockDateCalculator
            .Setup(c => c.GetWeeklyNotificationDates())
            .Returns(new[] { 11.January(2021), 12.January(2021) });

            var mockEmailRepository = new Mock <IEmailRepository>();

            var allocationNotifier = new AllocationNotifier(
                Mock.Of <ILogger <AllocationNotifier> >(),
                mockDateCalculator.Object,
                mockEmailRepository.Object,
                CreateDummyScheduleRepository(),
                mockUserRepository.Object);

            await allocationNotifier.Notify(requests);

            mockEmailRepository.VerifyNoOtherCalls();
        }
Exemplo n.º 3
0
        public static async Task Notifies_each_user_with_newly_allocated_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 requests = new[]
            {
                new Request("user1", 11.January(2021), RequestStatus.Allocated),
                new Request("user2", 12.January(2021), RequestStatus.Allocated)
            };

            var mockEmailRepository = new Mock <IEmailRepository>();

            var allocationNotifier = new AllocationNotifier(
                Mock.Of <ILogger <AllocationNotifier> >(),
                CreateDummyDateCalculator(),
                mockEmailRepository.Object,
                CreateDummyScheduleRepository(),
                mockUserRepository.Object);

            await allocationNotifier.Notify(requests);

            mockEmailRepository.Verify(
                r => r.Send(It.Is <IEmailTemplate>(t =>
                                                   t.To == "*****@*****.**" &&
                                                   t.Subject == "Parking space allocated for Mon 11 Jan")),
                Times.Once);
            mockEmailRepository.Verify(
                r => r.Send(It.Is <IEmailTemplate>(t =>
                                                   t.To == "*****@*****.**" &&
                                                   t.Subject == "Parking space allocated for Tue 12 Jan")),
                Times.Once);

            mockEmailRepository.VerifyNoOtherCalls();
        }
Exemplo n.º 4
0
        public static async Task Groups_notifications_into_a_single_email_when_a_user_has_multiple_notifications()
        {
            var users = new[] { CreateUser.With(userId: "user1", emailAddress: "*****@*****.**") };

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

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

            var requests = new[]
            {
                new Request("user1", 11.January(2021), RequestStatus.Allocated),
                new Request("user1", 12.January(2021), RequestStatus.Allocated)
            };

            var mockEmailRepository = new Mock <IEmailRepository>();

            var allocationNotifier = new AllocationNotifier(
                Mock.Of <ILogger <AllocationNotifier> >(),
                CreateDummyDateCalculator(),
                mockEmailRepository.Object,
                CreateDummyScheduleRepository(),
                mockUserRepository.Object);

            await allocationNotifier.Notify(requests);

            mockEmailRepository.Verify(
                r => r.Send(It.Is <IEmailTemplate>(t =>
                                                   t.To == "*****@*****.**" &&
                                                   t.Subject == "Parking spaces allocated for multiple upcoming dates" &&
                                                   t.PlainTextBody.Contains("Mon 11 Jan") &&
                                                   t.PlainTextBody.Contains("Tue 12 Jan"))),
                Times.Once);

            mockEmailRepository.VerifyNoOtherCalls();
        }