public async Task SendNotifyVolunteersCommand_WithCorrectSubject()
        {
            var userId  = "*****@*****.**";
            var subject = "allReady Task Un-enrollment Confirmation";

            var notification = new UserUnenrolled {
                UserId = userId
            };

            var model = new TaskDetailForNotificationModel
            {
                Volunteer = new ApplicationUser {
                    Id = userId, Email = userId
                }
            };

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.SendAsync(It.IsAny <TaskDetailForNotificationQuery>())).ReturnsAsync(model);

            var options = new Mock <IOptions <GeneralSettings> >();

            options.Setup(o => o.Value).Returns(new GeneralSettings());

            var handler = new NotifyVolunteerForTaskUnenrollHandler(mockMediator.Object, options.Object);
            await handler.Handle(notification);

            mockMediator.Verify(x => x.SendAsync(It.Is <NotifyVolunteersCommand>(c =>
                                                                                 c.ViewModel.Subject == subject
                                                                                 )), Times.Once);
        }
        public async Task SendNotifyVolunteersCommand_ToUserEmail()
        {
            var userId    = "*****@*****.**";
            var userEmail = "*****@*****.**";

            var notification = new UserUnenrolled {
                UserId = userId
            };

            var model = new TaskDetailForNotificationModel
            {
                Volunteer = new ApplicationUser {
                    Id = userId, Email = userEmail
                }
            };

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.SendAsync(It.IsAny <TaskDetailForNotificationQuery>())).ReturnsAsync(model);

            var options = new Mock <IOptions <GeneralSettings> >();

            options.Setup(o => o.Value).Returns(new GeneralSettings());

            var handler = new NotifyVolunteerForTaskUnenrollHandler(mockMediator.Object, options.Object);
            await handler.Handle(notification);

            mockMediator.Verify(x => x.SendAsync(It.Is <NotifyVolunteersCommand>(c =>
                                                                                 c.ViewModel.EmailRecipients != null &&
                                                                                 c.ViewModel.EmailRecipients.Count == 1 &&
                                                                                 c.ViewModel.EmailRecipients.First() == userEmail
                                                                                 )), Times.Once);
        }
        public async Task SendNotifyVolunteersCommand_WithCorrectMessage()
        {
            var userId = "*****@*****.**";

            var siteBaseUrl  = $"http://www.htbox.org";
            var taskId       = 111;
            var eventId      = 111;
            var campaignName = "Compaign1";
            var eventName    = "Event1";
            var taskName     = "Task1";

            var eventLink = $"View event: {siteBaseUrl}Event/Details/{eventId}";

            var message = new StringBuilder();

            message.AppendLine($"This is to confirm that you have elected to un-enroll from the following task:");
            message.AppendLine();
            message.AppendLine($"   Campaign: {campaignName}");
            message.AppendLine($"   Event: {eventName} ({eventLink})");
            message.AppendLine($"   Task: {taskName}");
            message.AppendLine();
            message.AppendLine("Thanks for letting us know that you will not be participating.");

            var notification = new UserUnenrolled {
                UserId = userId
            };

            var model = new TaskDetailForNotificationModel
            {
                TaskId       = taskId,
                TaskName     = taskName,
                EventId      = eventId,
                EventName    = eventName,
                CampaignName = campaignName,
                Volunteer    = new ApplicationUser {
                    Id = userId, Email = userId
                }
            };

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.SendAsync(It.IsAny <TaskDetailForNotificationQuery>())).ReturnsAsync(model);

            var options = new Mock <IOptions <GeneralSettings> >();

            options.Setup(o => o.Value).Returns(new GeneralSettings {
                SiteBaseUrl = siteBaseUrl
            });

            var handler = new NotifyVolunteerForTaskUnenrollHandler(mockMediator.Object, options.Object);
            await handler.Handle(notification);

            mockMediator.Verify(x => x.SendAsync(It.Is <NotifyVolunteersCommand>(c =>
                                                                                 !string.IsNullOrEmpty(c.ViewModel.EmailMessage) &&
                                                                                 c.ViewModel.EmailMessage == message.ToString() &&
                                                                                 !string.IsNullOrEmpty(c.ViewModel.HtmlMessage) &&
                                                                                 c.ViewModel.HtmlMessage == message.ToString()
                                                                                 )), Times.Once);
        }
        public async Task SendTaskDetailForNotificationQueryWithCorrectParameters()
        {
            var notification = new UserUnenrolled
            {
                UserId = "*****@*****.**",
                TaskId = 111
            };

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.SendAsync(It.IsAny <TaskDetailForNotificationQuery>())).ReturnsAsync(new TaskDetailForNotificationModel());

            var handler = new NotifyVolunteerForTaskUnenrollHandler(mockMediator.Object, null);
            await handler.Handle(notification);

            mockMediator.Verify(x => x.SendAsync(It.Is <TaskDetailForNotificationQuery>(n => n.TaskId == notification.TaskId && n.UserId == notification.UserId)), Times.Once);
        }
        public async Task NotSendNotifyVolunteersCommand_WhenVolunteerIsNull()
        {
            var notification = new UserUnenrolled {
                UserId = "*****@*****.**"
            };

            var model = new TaskDetailForNotificationModel
            {
                Volunteer = null
            };

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.SendAsync(It.IsAny <TaskDetailForNotificationQuery>())).ReturnsAsync(model);

            var handler = new NotifyVolunteerForTaskUnenrollHandler(mockMediator.Object, null);
            await handler.Handle(notification);

            mockMediator.Verify(x => x.SendAsync(It.IsAny <NotifyVolunteersCommand>()), Times.Never);
        }
Example #6
0
        public async Task NotSendNotifyVolunteersCommand_WhenRecepientEmailIsEmpty()
        {
            var userId = "*****@*****.**";

            var notification = new UserUnenrolled {
                UserId = userId
            };

            var model = new VolunteerTaskDetailForNotificationModel
            {
                Volunteer = new ApplicationUser {
                    Email = string.Empty
                }
            };

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(x => x.SendAsync(It.IsAny <VolunteerTaskDetailForNotificationQuery>())).ReturnsAsync(model);

            var handler = new NotifyVolunteerForVolunteerTaskUnenrollHandler(mockMediator.Object, null);
            await handler.Handle(notification);

            mockMediator.Verify(x => x.SendAsync(It.IsAny <NotifyVolunteersCommand>()), Times.Never);
        }