Пример #1
0
        public async Task SendNotifyVolunteersCommand_WithCorrectSubject()
        {
            var userId  = "*****@*****.**";
            var subject = "allReady Task Un-enrollment Confirmation";

            var notification = new UserUnenrolls {
                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 <TaskDetailForNotificationQueryAsync>())).ReturnsAsync(model);

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

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

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

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

            var notification = new UserUnenrolls {
                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 <TaskDetailForNotificationQueryAsync>())).ReturnsAsync(model);

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

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

            var handler = new NotifyVolunteerForTaskUnenroll(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);
        }
Пример #3
0
        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 UserUnenrolls {
                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 <TaskDetailForNotificationQueryAsync>())).ReturnsAsync(model);

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

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

            var handler = new NotifyVolunteerForTaskUnenroll(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 NotSendNotifyVolunteersCommand_WhenSignupIsNull()
        {
            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<TaskDetailForNotificationQuery>())).ReturnsAsync(new TaskDetailForNotificationModel());

            var handler = new NotifyVolunteerForTaskUnenroll(mockMediator.Object, null);
            await handler.Handle(new UserUnenrolls());

            mockMediator.Verify(x => x.SendAsync(It.IsAny<NotifyVolunteersCommand>()), Times.Never);
        }
Пример #5
0
        public async Task NotSendNotifyVolunteersCommand_WhenSignupIsNull()
        {
            var mockMediator = new Mock <IMediator>();

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

            var handler = new NotifyVolunteerForTaskUnenroll(mockMediator.Object, null);
            await handler.Handle(new UserUnenrolls());

            mockMediator.Verify(x => x.SendAsync(It.IsAny <NotifyVolunteersCommand>()), Times.Never);
        }
        public async Task SendTaskDetailForNotificationQueryWithCorrectParameters()
        {
            var notification = new UserUnenrolls
            {
                UserId = "*****@*****.**",
                TaskId = 111
            };

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

            var handler = new NotifyVolunteerForTaskUnenroll(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 UserUnenrolls { 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 NotifyVolunteerForTaskUnenroll(mockMediator.Object, null);
            await handler.Handle(notification);

            mockMediator.Verify(x => x.SendAsync(It.IsAny<NotifyVolunteersCommand>()), Times.Never);
        }
Пример #8
0
        public async Task SendTaskDetailForNotificationQueryAsyncWithCorrectParameters()
        {
            var notification = new UserUnenrolls
            {
                UserId = "*****@*****.**",
                TaskId = 111
            };

            var mockMediator = new Mock <IMediator>();

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

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

            mockMediator.Verify(x => x.SendAsync(It.Is <TaskDetailForNotificationQueryAsync>(n => n.TaskId == notification.TaskId && n.UserId == notification.UserId)), Times.Once);
        }
Пример #9
0
        public async Task NotSendNotifyVolunteersCommand_WhenVolunteerIsNull()
        {
            var notification = new UserUnenrolls {
                UserId = "*****@*****.**"
            };

            var model = new TaskDetailForNotificationModel
            {
                Volunteer = null
            };

            var mockMediator = new Mock <IMediator>();

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

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

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

            var notification = new UserUnenrolls {
                UserId = userId
            };

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

            var mockMediator = new Mock <IMediator>();

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

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

            mockMediator.Verify(x => x.SendAsync(It.IsAny <NotifyVolunteersCommand>()), Times.Never);
        }
        public async Task SendNotifyVolunteersCommand_WithCorrectSubject()
        {
            var userId = "*****@*****.**";
            var subject = "allReady Task Un-enrollment Confirmation";

            var notification = new UserUnenrolls { 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 NotifyVolunteerForTaskUnenroll(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_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 UserUnenrolls { 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 NotifyVolunteerForTaskUnenroll(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 SendNotifyVolunteersCommand_ToUserEmail()
        {
            var userId = "*****@*****.**";
            var userEmail = "*****@*****.**";
            
            var notification = new UserUnenrolls { 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 NotifyVolunteerForTaskUnenroll(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);
        }