Ejemplo n.º 1
0
        public async Task <IActionResult> CreateNewNotificationAsync(AddNotificationRequest request)
        {
            var notification = new CreateEmailNotificationCommand((NotificationType)request.NotificationType, request.ContactEmail, request.ParticipantId, request.HearingId);
            await _createNotificationService.CreateEmailNotificationAsync(notification, request.Parameters);

            return(Ok());
        }
        public async Task CreateEmailNotificationAsync(CreateEmailNotificationCommand notificationCommand, Dictionary <string, string> parameters)
        {
            var template = await _queryHandler.Handle <GetTemplateByNotificationTypeQuery, Template>(new GetTemplateByNotificationTypeQuery(notificationCommand.NotificationType));

            await _commandHandler.Handle(notificationCommand);

            var requestParameters         = parameters.ToDictionary(x => x.Key, x => (dynamic)x.Value);
            var emailNotificationResponse = await _asyncNotificationClient.SendEmailAsync(notificationCommand.ContactEmail, template.NotifyTemplateId.ToString(), requestParameters, notificationCommand.NotificationId.ToString());

            await _commandHandler.Handle(new UpdateNotificationSentCommand(notificationCommand.NotificationId, emailNotificationResponse.id, emailNotificationResponse.content.body));
        }
Ejemplo n.º 3
0
        public async Task Should_save_new_notification()
        {
            // Arrange
            var          notificationType = NotificationType.CreateIndividual;
            const string email            = "*****@*****.**";
            var          participantId    = Guid.NewGuid();
            var          hearingId        = Guid.NewGuid();
            var          command          = new CreateEmailNotificationCommand(notificationType, email, participantId, hearingId);

            // Act
            await _handler.Handle(command);

            // Assert
            await using var db = new NotificationsApiDbContext(NotifyBookingsDbContextOptions);
            var notification = await db.Notifications.SingleOrDefaultAsync(x => x.Id == command.NotificationId);

            notification.Should().NotBeNull();
            command.NotificationId.Should().NotBeEmpty();
            _notificationId = command.NotificationId;
        }
        public void Setup()
        {
            _mocker = AutoMock.GetLoose();
            _createNotificationService = _mocker.Create <CreateNotificationService>();
            _emailResponseContent      = new EmailResponseContent()
            {
                body = "Email reponse Body"
            };

            _template = new Template(Guid.NewGuid(), NotificationType.JudgeDemoOrTest, MessageType.Email, "param1, param2");
            _createEmailNotificationCommand = new CreateEmailNotificationCommand(NotificationType.JudgeDemoOrTest, "*****@*****.**", Guid.NewGuid(), Guid.NewGuid());
            _parameters = new Dictionary <string, dynamic>
            {
                { "Test param1Key", "Test param1Value" }
            };
            _emailResponseContent = new EmailResponseContent()
            {
                body = "Email reponse Body"
            };
            _expectedEmailNotificationResponse = new EmailNotificationResponse()
            {
                id        = Guid.NewGuid().ToString(),
                reference = "reference",
                uri       = "uri",
                content   = _emailResponseContent,
                template  = null
            };

            _mocker.Mock <IPollyRetryService>().Setup(x => x.WaitAndRetryAsync <Exception, EmailNotificationResponse>
                                                      (
                                                          It.IsAny <int>(), It.IsAny <Func <int, TimeSpan> >(), It.IsAny <Action <int> >(), It.IsAny <Func <EmailNotificationResponse, bool> >(), It.IsAny <Func <Task <EmailNotificationResponse> > >()
                                                      ))
            .Callback(async(int retries, Func <int, TimeSpan> sleepDuration, Action <int> retryAction, Func <EmailNotificationResponse, bool> handleResultCondition, Func <Task <EmailNotificationResponse> > executeFunction) =>
            {
                sleepDuration(1);
                retryAction(7);
                handleResultCondition(_expectedEmailNotificationResponse);
                await executeFunction();
            })
            .ReturnsAsync(_expectedEmailNotificationResponse);
        }