private async Task Handle(TransactionProcessedEvent evt, ICommandSender sender)
        {
            ChaosKitty.Meow();

            var clientAcc = await _clientAccountClient.GetByIdAsync(evt.ClientId);

            var sendEmailCommand = new SendNoRefundDepositDoneMailCommand
            {
                Email   = clientAcc.Email,
                Amount  = evt.Amount,
                AssetId = evt.Asset.Id
            };

            sender.SendCommand(sendEmailCommand, "email");

            ChaosKitty.Meow();

            var pushSettings = await _clientAccountClient.GetPushNotificationAsync(evt.ClientId);

            if (pushSettings.Enabled)
            {
                var sendNotificationCommand = new SendNotificationCommand
                {
                    NotificationId = clientAcc.NotificationsId,
                    Type           = NotificationType.TransactionConfirmed,
                    Message        = string.Format(TextResources.CashInSuccessText, new decimal(evt.Amount).TruncateDecimalPlaces(evt.Asset.Accuracy), evt.Asset.Id)
                };
                sender.SendCommand(sendNotificationCommand, "notifications");
            }
        }
Beispiel #2
0
        public SendNotificationCommand SendNotificationAboutMessage(MessageSetup message)
        {
            var command = new SendNotificationCommand();

            command.Message = message;
            return(command);
        }
        public async Task <CommandHandlingResult> Handle(SendNotificationCommand command)
        {
            ChaosKitty.Meow();

            await _appNotifications.SendTextNotificationAsync(new [] { command.NotificationId }, command.Type, command.Message);

            return(CommandHandlingResult.Ok());
        }
        public async Task ThenSendsEmailToNotificationApi(
            SendNotificationCommand command,
            [Frozen] Mock <IBackgroundNotificationService> mockNotificationsApi,
            SendNotificationCommandHandler sut)
        {
            await sut.Handle(command);

            mockNotificationsApi.Verify(api => api.SendEmail(command.Email), Times.Once);
        }
 public NotificationViewModel()
 {
     Notification = new Notification()
     {
         Content = "", SinglePerson = false, PassengerSeat = "", Title = ""
     };
     Client           = new HttpClient();
     SendNotification = new SendNotificationCommand(this);
 }
        public async Task ThenItValidatesTheCommand(
            SendNotificationCommand command,
            [Frozen] Mock <IValidator <SendNotificationCommand> > mockValidator,
            SendNotificationCommandHandler sut)
        {
            await sut.Handle(command);

            mockValidator.Verify(validator => validator.Validate(command), Times.Once);
        }
        public Task Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next, Document document)
        {
            var notificationDto = new NotificationBuilder()
                                  .SetNotificationType(_notificationProvider.GetNotificationType())
                                  .SetTitle(_notificationProvider.GetTitle(document))
                                  .SetMessage(_notificationProvider.GetMessage(document))
                                  .Build()
                                  .ToDto();

            var sendNotificationCommand = new SendNotificationCommand(context.Instance.CorrelationId, notificationDto);

            context.Send(sendNotificationCommand);
            return(next.Execute(context));
        }
        public async Task <CommandResult> Send([FromServices] SendNotificationCommand sendNotificationCommand, [FromBody] SendNotificationInput saveUserInput)
        {
            var userInput = new UserInput <SendNotificationInput>
            {
                UserId = User.GetUserId(),
                Data   = saveUserInput
            };

            var result = await
                         Business.InvokeAsync <SendNotificationCommand, UserInput <SendNotificationInput>, CommandResult>(
                sendNotificationCommand, userInput);

            return(result);
        }
        public void Setup()
        {
            _validCommand = new SendNotificationCommand
            {
                Email = new Email
                {
                    RecipientsAddress = "*****@*****.**",
                    ReplyToAddress    = "*****@*****.**",
                    Subject           = "Test Subject",
                    TemplateId        = "ABC123",
                }
            };

            _handler = new SendNotificationCommandHandler(new SendNotificationCommandValidator(), Mock.Of <IBackgroundNotificationService>(), Mock.Of <ILog>());
        }
        public void ThenThrowsInvalidRequestExceptionIfCommandInvalid(
            SendNotificationCommand command,
            ValidationFailure validationFailure,
            ValidationResult validationResult,
            InvalidRequestException validationException)
        {
            validationResult.Errors.Add(validationFailure);

            _mockValidator
            .Setup(validator => validator.Validate(command))
            .Returns(validationResult);

            Func <Task> act = async() => { await _sut.Handle(command, new CancellationToken()); };

            act.ShouldThrowExactly <ValidationException>()
            .Which.Errors.ToList().Contains(validationFailure).Should().BeTrue();
        }
Beispiel #11
0
        public async Task <IActionResult> SendBatchNotification([FromBody] SendNotificationCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await mediator.Send(command);

                return(Ok());
            }
            catch (InvalidAppException)
            {
                return(BadRequest("InvalidApp"));
            }
        }
        public void ThenThrowsInvalidRequestExceptionIfCommandInvalid(
            SendNotificationCommand command,
            string propertyName,
            ValidationResult validationResult,
            InvalidRequestException validationException,
            [Frozen] Mock <IValidator <SendNotificationCommand> > mockValidator,
            SendNotificationCommandHandler sut)
        {
            validationResult.AddError(propertyName);

            mockValidator
            .Setup(validator => validator.Validate(command))
            .Returns(validationResult);

            Func <Task> act = async() => { await sut.Handle(command); };

            act.ShouldThrowExactly <InvalidRequestException>()
            .Which.ErrorMessages.ContainsKey(propertyName).Should().BeTrue();
        }
        public async Task ShouldCallSendNotificationCommandForCohortReview()
        {
            SendNotificationCommand arg = null;

            _validCommand.LastAction = LastAction.Amend;
            _mockEmailLookup
            .Setup(x => x.GetEmailsAsync(It.IsAny <long>(), It.IsAny <string>()))
            .ReturnsAsync(new List <string> {
                "*****@*****.**"
            });

            _mockMediator.Setup(x => x.SendAsync(It.IsAny <SendNotificationCommand>()))
            .ReturnsAsync(new Unit()).Callback <SendNotificationCommand>(x => arg = x);

            await _handler.Handle(_validCommand);

            _mockMediator.Verify(x => x.SendAsync(It.IsAny <SendNotificationCommand>()));
            arg.Email.TemplateId.Should().Be("ProviderCommitmentNotification");
            arg.Email.Tokens["type"].Should().Be("review");
        }
        public async Task ShouldCallSendNotificationCommandForCohortSecondApproval()
        {
            SendNotificationCommand arg = null;

            _validCommand.LastAction = LastAction.Approve;
            _repositoryCommitment.AgreementStatus = AgreementStatus.ProviderAgreed;

            _mockEmailLookup
            .Setup(x => x.GetEmailsAsync(It.IsAny <long>(), It.IsAny <string>()))
            .ReturnsAsync(new List <string> {
                "*****@*****.**"
            });

            _mockMediator.Setup(x => x.SendAsync(It.IsAny <SendNotificationCommand>()))
            .ReturnsAsync(new Unit()).Callback <SendNotificationCommand>(x => arg = x);

            await _handler.Handle(_validCommand);

            _mockMediator.Verify(x => x.SendAsync(It.IsAny <SendNotificationCommand>()));
            arg.Email.TemplateId.Should().Be("ProviderCohortApproved");
            arg.Email.Tokens["type"].Should().Be("approval");
        }
Beispiel #15
0
        public Task Handle(OrderProcessedEvent message, IMessageHandlerContext context)
        {
            // handle response
            Console.WriteLine($"Step 3: Order {message.TransactionId} has been process with results: {message.Results}");
            //log.Info($"Step 3: Order {message.TransactionId} has been process with results: {message.Results}");

            var format     = "{Application}.{Service}.{Operation}-{TransactionId}: {LogMessage}";
            var logMessage = $"Step 3: Order {message.TransactionId} has been process with results: {message.Results}";

            try
            {
                log.InfoFormat(format, "Lhi.NsbDemo.Orders", "OrdersSaga", "Handle-OrderProcessedEvent", message.TransactionId, logMessage);
            }
            catch { }

            _promCounter.Labels(Environment.MachineName, "processed").Inc();

            // if order processing failed, send a notification command
            if (message.Results == "failed")
            {
                var sendNotificationCommand = new SendNotificationCommand
                {
                    TransactionId = message.TransactionId,
                    Message       = $"Order {message.TransactionId} could not be procceeded. Please try again!"
                };

                try
                {
                    context.Send(sendNotificationCommand);
                }
                catch (Exception ex)
                {
                    var errorMessage = $"Could not send SendNotificationCommand. Error: {ex.Message}";
                    log.ErrorFormat(format, "Lhi.NsbDemo.Orders", "OrdersSaga", "Handle-OrderProcessedEvent", message.TransactionId, errorMessage);
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #16
0
        public void Arrange()
        {
            _mediator = new Mock <IMediator>();
            _mediator.Setup(m => m.SendAsync(It.IsAny <SendNotificationCommand>()))
            .Callback <IAsyncRequest <Unit> >(c => _sendNotificationCommand = c as SendNotificationCommand)
            .Returns(Task.FromResult(new Unit()));

            _hashingService = new Mock <IHashingService>();

            _employermailNotificationService =
                new EmployerEmailNotificationService(_mediator.Object, Mock.Of <ILog>(), _hashingService.Object);

            _exampleCommitmentView = new CommitmentView
            {
                EmployerLastUpdateInfo = new LastUpdateInfo {
                    EmailAddress = EmployersEmailAddress
                },
                EmployerAccountId = EmployerAccountId,
                LegalEntityName   = EmployerName,
                Reference         = CohortReference,
                TransferSender    = new TransferSender
                {
                    Name = SenderName
                }
            };

            _transferApprovalStatus = TransferApprovalStatus.Approved;

            _tokens = new Dictionary <string, string>
            {
                { "cohort_reference", CohortReference },
                { "employer_name", EmployerName },
                { "sender_name", SenderName },
                { "employer_hashed_account", HashedEmployerAccountId },
            };

            _act = async() =>
                   await _employermailNotificationService.SendSenderApprovedOrRejectedCommitmentNotification(_exampleCommitmentView, _transferApprovalStatus);
        }
Beispiel #17
0
        public async Task ThenTheNotificationClientIsCalled()
        {
            //Arrange
            var sendNotificationCommand = new SendNotificationCommand {
                Email = new Email {
                    RecipientsAddress = "*****@*****.**", ReplyToAddress = "*****@*****.**", Subject = "Test Subject", SystemId = "123", TemplateId = "12345", Tokens = new Dictionary <string, string> {
                        { "string", "value" }
                    }
                }
            };

            //Act
            await _sendNotificationCommandHandler.Handle(sendNotificationCommand);

            //Assert
            _notificationClient.Verify(x => x.SendEmail(It.Is <Email>(c =>
                                                                      c.RecipientsAddress.Equals(sendNotificationCommand.Email.RecipientsAddress) &&
                                                                      c.ReplyToAddress.Equals(sendNotificationCommand.Email.ReplyToAddress) &&
                                                                      c.Subject.Equals(sendNotificationCommand.Email.Subject) &&
                                                                      c.SystemId.Equals(sendNotificationCommand.Email.SystemId) &&
                                                                      c.TemplateId.Equals(sendNotificationCommand.Email.TemplateId) &&
                                                                      c.Tokens.Count.Equals(1)
                                                                      )), Times.Once);
        }
        public async Task ThenItValidatesTheCommand(SendNotificationCommand command)
        {
            await _sut.Handle(command, new CancellationToken());

            _mockValidator.Verify(validator => validator.Validate(command), Times.Once);
        }
        public async Task ThenSendsEmailToNotificationApi(SendNotificationCommand command)
        {
            await _sut.Handle(command, new CancellationToken());

            _backgroundNotificationService.Verify(api => api.SendEmail(command.Email), Times.Once);
        }
        public async Task <IActionResult> SendNotification([FromBody] SendNotificationCommand cmd)
        {
            var result = await bus.Send(cmd);

            return(Ok());
        }
Beispiel #21
0
 public void TearDown()
 {
     _sendNotificationCommand = null;
 }