コード例 #1
0
        public void Then_Values_Are_Set_Correctly(
            CreateUserCommand command, ApimDeveloperMessagingConfiguration config)
        {
            var expectedTokens = new Dictionary <string, string>
            {
                { "Contact", $"{command.FirstName} {command.LastName}" },
                { "ConfirmEmailURL", command.ConfirmationEmailLink }
            };

            var email = new VerifyThirdyPartyAccountEmail(command, config);

            email.TemplateId.Should().Be(config.VerifyThirdPartyAccountTemplateId);
            email.RecipientAddress.Should().Be(command.Email);
            email.ReplyToAddress.Should().Be(EmailConstants.ReplyToAddress);
            email.Tokens.Should().BeEquivalentTo(expectedTokens);
        }
        public async Task Then_The_Request_Is_Sent_To_Create_User_And_Email_Sent(
            CreateUserCommand command,
            [Frozen] Mock <IApimDeveloperApiClient <ApimDeveloperApiConfiguration> > client,
            [Frozen] Mock <INotificationService> mockNotificationService,
            [Frozen] Mock <IOptions <ApimDeveloperMessagingConfiguration> > mockOptions,
            CreateUserCommandHandler handler)
        {
            //arrange
            client.Setup(
                x => x.PostWithResponseCode <object>(It.Is <PostCreateUserRequest>(c =>
                                                                                   c.PostUrl.Contains(command.Id.ToString()) &&
                                                                                   ((UserRequestData)c.Data).Email.Equals(command.Email) &&
                                                                                   ((UserRequestData)c.Data).Password.Equals(command.Password) &&
                                                                                   ((UserRequestData)c.Data).FirstName.Equals(command.FirstName) &&
                                                                                   ((UserRequestData)c.Data).LastName.Equals(command.LastName) &&
                                                                                   ((UserRequestData)c.Data).ConfirmationEmailLink.Equals(command.ConfirmationEmailLink) &&
                                                                                   ((UserRequestData)c.Data).State.Equals(0)
                                                                                   ))).ReturnsAsync(new ApiResponse <object>(null, HttpStatusCode.Created, ""));
            SendEmailCommand actualEmail = null;

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

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

            //assert
            client.Verify(
                x => x.PostWithResponseCode <object>(It.Is <PostCreateUserRequest>(c =>
                                                                                   c.PostUrl.Contains(command.Id.ToString()) &&
                                                                                   ((UserRequestData)c.Data).Email.Equals(command.Email) &&
                                                                                   ((UserRequestData)c.Data).Password.Equals(command.Password) &&
                                                                                   ((UserRequestData)c.Data).FirstName.Equals(command.FirstName) &&
                                                                                   ((UserRequestData)c.Data).LastName.Equals(command.LastName) &&
                                                                                   ((UserRequestData)c.Data).ConfirmationEmailLink.Equals(command.ConfirmationEmailLink) &&
                                                                                   ((UserRequestData)c.Data).State.Equals(0)
                                                                                   )), Times.Once);

            actualEmail.Tokens.Should().BeEquivalentTo(expectedEmail.Tokens);
            actualEmail.RecipientsAddress.Should().BeEquivalentTo(expectedEmail.RecipientAddress);
            actualEmail.TemplateId.Should().BeEquivalentTo(expectedEmail.TemplateId);
        }
コード例 #3
0
        public async Task <Unit> Handle(CreateUserCommand request, CancellationToken cancellationToken)
        {
            var actual = await _apimDeveloperApiClient.PostWithResponseCode <object>(new PostCreateUserRequest(request.Id, new UserRequestData
            {
                Email = request.Email,
                Password = request.Password,
                FirstName = request.FirstName,
                LastName = request.LastName,
                ConfirmationEmailLink = request.ConfirmationEmailLink,
                State = 0
            }));

            if (actual.StatusCode != HttpStatusCode.Created)
            {
                throw new HttpRequestContentException("Error creating user", actual.StatusCode, actual.ErrorContent);
            }

            var email   = new VerifyThirdyPartyAccountEmail(request, _config);
            var command = new SendEmailCommand(email.TemplateId, email.RecipientAddress, email.Tokens);
            await _notificationService.Send(command);

            return(Unit.Value);
        }