Esempio n. 1
0
        public void MerchantRequestHandler_CreateMerchantUserRequest_IsHandled()
        {
            Mock <IMerchantDomainService> merchantDomainService = new Mock <IMerchantDomainService>();
            MerchantRequestHandler        handler = new MerchantRequestHandler(merchantDomainService.Object);

            CreateMerchantUserRequest request = TestData.CreateMerchantUserRequest;

            Should.NotThrow(async() =>
            {
                await handler.Handle(request, CancellationToken.None);
            });
        }
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <Guid> Handle(CreateMerchantUserRequest request,
                                        CancellationToken cancellationToken)
        {
            Guid userId = await this.MerchantDomainService.CreateMerchantUser(request.EstateId,
                                                                              request.MerchantId,
                                                                              request.EmailAddress,
                                                                              request.Password,
                                                                              request.GivenName,
                                                                              request.MiddleName,
                                                                              request.FamilyName,
                                                                              cancellationToken);

            return(userId);
        }
Esempio n. 3
0
        public void CreateMerchantUserRequest_CanBeCreated_IsCreated()
        {
            CreateMerchantUserRequest createMerchantUserRequest = CreateMerchantUserRequest.Create(TestData.EstateId,
                                                                                                   TestData.MerchantId,
                                                                                                   TestData.EstateUserEmailAddress,
                                                                                                   TestData.EstateUserPassword,
                                                                                                   TestData.EstateUserGivenName,
                                                                                                   TestData.EstateUserMiddleName,
                                                                                                   TestData.EstateUserFamilyName);

            createMerchantUserRequest.ShouldNotBeNull();
            createMerchantUserRequest.EstateId.ShouldBe(TestData.EstateId);
            createMerchantUserRequest.MerchantId.ShouldBe(TestData.MerchantId);
            createMerchantUserRequest.EmailAddress.ShouldBe(TestData.EstateUserEmailAddress);
            createMerchantUserRequest.Password.ShouldBe(TestData.EstateUserPassword);
            createMerchantUserRequest.GivenName.ShouldBe(TestData.EstateUserGivenName);
            createMerchantUserRequest.MiddleName.ShouldBe(TestData.EstateUserMiddleName);
            createMerchantUserRequest.FamilyName.ShouldBe(TestData.EstateUserFamilyName);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the merchant user.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="merchantId">The merchant identifier.</param>
        /// <param name="createMerchantUserRequest">The create merchant user request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <CreateMerchantUserResponse> CreateMerchantUser(String accessToken,
                                                                          Guid estateId,
                                                                          Guid merchantId,
                                                                          CreateMerchantUserRequest createMerchantUserRequest,
                                                                          CancellationToken cancellationToken)
        {
            CreateMerchantUserResponse response = null;

            String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants/{merchantId}/users");

            try
            {
                String requestSerialised = JsonConvert.SerializeObject(createMerchantUserRequest);

                StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");

                // Add the access token to the client headers
                this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // Make the Http Call here
                HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);

                // Process the response
                String content = await this.HandleResponse(httpResponse, cancellationToken);

                // call was successful so now deserialise the body to the response object
                response = JsonConvert.DeserializeObject <CreateMerchantUserResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error creating new mercant user Merchant Id {estateId} Email Address {createMerchantUserRequest.EmailAddress}.",
                                                    ex);

                throw exception;
            }

            return(response);
        }
Esempio n. 5
0
        public async Task WhenICreateTheFollowingSecurityUsers(Table table)
        {
            foreach (TableRow tableRow in table.Rows)
            {
                // lookup the estate id based on the name in the table
                EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow);

                if (tableRow.ContainsKey("EstateName") && tableRow.ContainsKey("MerchantName") == false)
                {
                    // Creating an Estate User
                    CreateEstateUserRequest createEstateUserRequest = new CreateEstateUserRequest
                    {
                        EmailAddress = SpecflowTableHelper.GetStringRowValue(tableRow, "EmailAddress"),
                        FamilyName   = SpecflowTableHelper.GetStringRowValue(tableRow, "FamilyName"),
                        GivenName    = SpecflowTableHelper.GetStringRowValue(tableRow, "GivenName"),
                        MiddleName   = SpecflowTableHelper.GetStringRowValue(tableRow, "MiddleName"),
                        Password     = SpecflowTableHelper.GetStringRowValue(tableRow, "Password")
                    };

                    CreateEstateUserResponse createEstateUserResponse =
                        await this.TestingContext.DockerHelper.EstateClient.CreateEstateUser(this.TestingContext.AccessToken,
                                                                                             estateDetails.EstateId,
                                                                                             createEstateUserRequest,
                                                                                             CancellationToken.None);

                    createEstateUserResponse.EstateId.ShouldBe(estateDetails.EstateId);
                    createEstateUserResponse.UserId.ShouldNotBe(Guid.Empty);

                    estateDetails.SetEstateUser(createEstateUserRequest.EmailAddress, createEstateUserRequest.Password);

                    //this.TestingContext.Logger.LogInformation($"Security user {createEstateUserRequest.EmailAddress} assigned to Estate {estateDetails.EstateName}");
                }
                else if (tableRow.ContainsKey("MerchantName"))
                {
                    // Creating a merchant user
                    String token = this.TestingContext.AccessToken;
                    if (String.IsNullOrEmpty(estateDetails.AccessToken) == false)
                    {
                        token = estateDetails.AccessToken;
                    }

                    // lookup the merchant id based on the name in the table
                    String merchantName = SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName");
                    Guid   merchantId   = estateDetails.GetMerchantId(merchantName);

                    CreateMerchantUserRequest createMerchantUserRequest = new CreateMerchantUserRequest
                    {
                        EmailAddress = SpecflowTableHelper.GetStringRowValue(tableRow, "EmailAddress"),
                        FamilyName   = SpecflowTableHelper.GetStringRowValue(tableRow, "FamilyName"),
                        GivenName    = SpecflowTableHelper.GetStringRowValue(tableRow, "GivenName"),
                        MiddleName   = SpecflowTableHelper.GetStringRowValue(tableRow, "MiddleName"),
                        Password     = SpecflowTableHelper.GetStringRowValue(tableRow, "Password")
                    };

                    CreateMerchantUserResponse createMerchantUserResponse =
                        await this.TestingContext.DockerHelper.EstateClient.CreateMerchantUser(token,
                                                                                               estateDetails.EstateId,
                                                                                               merchantId,
                                                                                               createMerchantUserRequest,
                                                                                               CancellationToken.None);

                    createMerchantUserResponse.EstateId.ShouldBe(estateDetails.EstateId);
                    createMerchantUserResponse.MerchantId.ShouldBe(merchantId);
                    createMerchantUserResponse.UserId.ShouldNotBe(Guid.Empty);

                    estateDetails.AddMerchantUser(merchantName, createMerchantUserRequest.EmailAddress, createMerchantUserRequest.Password);

                    //this.TestingContext.Logger.LogInformation($"Security user {createMerchantUserRequest.EmailAddress} assigned to Merchant {merchantName}");
                }
            }
        }