Esempio n. 1
0
        public async Task <Unit> Handle(SendEmailToChangePasswordCommand request, CancellationToken cancellationToken)
        {
            var email   = new ChangePasswordEmail(request, _config);
            var command = new SendEmailCommand(email.TemplateId, email.RecipientAddress, email.Tokens);
            await _notificationService.Send(command);

            return(Unit.Value);
        }
Esempio n. 2
0
        public async Task <Response> Execute(Enum emailType)
        {
            FromEmail = await _appSettings.AdminEmail;
            FromName  = await _appSettings.AdminName;

            var apiKey = await _appSettings.SendGridAPIKey;
            var client = new SendGridClient(apiKey);
            var from   = new EmailAddress(FromEmail, FromName);
            var to     = new EmailAddress(_toEmail, _toName);

            _token = HttpUtility.UrlEncode(_token);


            switch (emailType)
            {
            case EmailType.AccountVerification:
                var accountVerification = new AccountVerificationEmail(_appSettings);
                accountVerification._email = _email;
                accountVerification._token = _token;
                _template = accountVerification;

                break;

            case EmailType.ScoreDetail:
                var scoreDetails = new ScoreDetailsEmail();
                scoreDetails._score = _score;
                _template           = scoreDetails;
                break;

            case EmailType.Purchase:
                var purchaseDetails = new PurchaseDetailsEmail();
                purchaseDetails._coin = _coin;
                _template             = purchaseDetails;
                break;

            case EmailType.ChangePassword:
                var changePasswordEmail = new ChangePasswordEmail(_appSettings);
                changePasswordEmail._email = _email;
                changePasswordEmail._token = _token;
                _template = changePasswordEmail;
                break;

            default:
                break;
            }
            var item = await _template.Template();

            var msg      = MailHelper.CreateSingleEmail(from, to, item.Subject, item.PlainTextContent, item.HtmlContent);
            var response = await client.SendEmailAsync(msg);

            return(response);
        }
        public void Then_Values_Are_Set_Correctly(
            SendEmailToChangePasswordCommand command, ApimDeveloperMessagingConfiguration config)
        {
            var expectedTokens = new Dictionary <string, string>
            {
                { "Contact", $"{command.FirstName} {command.LastName}" },
                { "ChangePasswordURL", command.ChangePasswordUrl }
            };

            var email = new ChangePasswordEmail(command, config);

            email.TemplateId.Should().Be(config.ChangePasswordTemplateId);
            email.RecipientAddress.Should().Be(command.Email);
            email.ReplyToAddress.Should().Be(EmailConstants.ReplyToAddress);
            email.Tokens.Should().BeEquivalentTo(expectedTokens);
        }
Esempio n. 4
0
        public async Task Then_A_Notification_Is_Sent_And_Api_Called(
            SendEmailToChangePasswordCommand command,
            [Frozen] Mock <IOptions <ApimDeveloperMessagingConfiguration> > mockOptions,
            [Frozen] Mock <INotificationService> mockNotificationService,
            SendEmailToChangePasswordCommandHandler handler)
        {
            //Arrange
            SendEmailCommand actualEmail = null;

            mockNotificationService
            .Setup(service => service.Send(It.IsAny <SendEmailCommand>()))
            .Callback((SendEmailCommand args) => actualEmail = args)
            .Returns(Task.CompletedTask);
            var expectedEmail = new ChangePasswordEmail(command, mockOptions.Object.Value);


            //Act
            await handler.Handle(command, CancellationToken.None);

            //Assert
            actualEmail.Tokens.Should().BeEquivalentTo(expectedEmail.Tokens);
            actualEmail.RecipientsAddress.Should().BeEquivalentTo(expectedEmail.RecipientAddress);
            actualEmail.TemplateId.Should().BeEquivalentTo(expectedEmail.TemplateId);
        }