Beispiel #1
0
        public async void LogTheExceptionIfAnExceptionOccurs()
        {
            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <NotifyVolunteersCommand>()))
            .Throws(new InvalidOperationException("Test Exception"));

            var logger  = new Mock <ILogger <NotifyAdminForUserUnenrollsHandler> >();
            var options = new TestOptions <GeneralSettings>();

            options.Value.SiteBaseUrl = "localhost";

            var notification = new VolunteerSignedUpNotification
            {
                UserId = Context.Users.First().Id,
                TaskId = Context.Tasks.First().Id
            };

            var target = new NotifyAdminForSignupHandler(Context, mediator.Object, options, logger.Object);
            await target.Handle(notification);

            logger.Verify(x => x.Log(It.IsAny <LogLevel>(),
                                     It.IsAny <EventId>(), It.IsAny <object>(),
                                     It.IsAny <InvalidOperationException>(),
                                     It.IsAny <Func <object, Exception, string> >()), Times.AtLeastOnce);
        }
Beispiel #2
0
        public async void SkipNotificationIfAdminEmailIsNotSpecified()
        {
            var mediator = new Mock <IMediator>();
            var logger   = Mock.Of <ILogger <NotifyAdminForUserUnenrollsHandler> >();

            var options = new TestOptions <GeneralSettings>();

            options.Value.SiteBaseUrl = "localhost";

            var notification = new VolunteerSignedUpNotification
            {
                UserId = Context.Users.First().Id,
                TaskId = Context.Tasks.Skip(1).First().Id
            };

            var target = new NotifyAdminForSignupHandler(Context, mediator.Object, options, logger);
            await target.Handle(notification);

            mediator.Verify(x => x.SendAsync(It.IsAny <NotifyVolunteersCommand>()), Times.Never);
        }
Beispiel #3
0
        public async void SendToTheAdminEmail()
        {
            const string adminEmail = "AdminEmail";

            var taskDetailForNotificationModel = new TaskDetailForNotificationModel
            {
                Volunteer = new ApplicationUser {
                    Email = "VolunteerEmail", PhoneNumber = "VolunteerPhoneNumber"
                },
                CampaignContacts = new List <CampaignContact>
                {
                    new CampaignContact
                    {
                        ContactType = (int)ContactTypes.Primary,
                        Contact     = new Contact {
                            Email = adminEmail
                        }
                    }
                }
            };

            var mediator = new Mock <IMediator>();

            mediator.Setup(x => x.SendAsync(It.IsAny <TaskDetailForNotificationQuery>()))
            .ReturnsAsync(taskDetailForNotificationModel);

            var options = new TestOptions <GeneralSettings>();

            options.Value.SiteBaseUrl = "localhost";

            var notification = new VolunteerSignedUpNotification
            {
                UserId = Context.Users.First().Id,
                TaskId = Context.Tasks.First().Id
            };

            var target = new NotifyAdminForSignupHandler(Context, mediator.Object, options, null);
            await target.Handle(notification);

            mediator.Verify(x => x.SendAsync(It.Is <NotifyVolunteersCommand>(y => y.ViewModel.EmailRecipients.Contains(adminEmail))), Times.Once);
        }