public void EstateRequestHandler_CreateEstateUserRequest_IsHandled()
        {
            Mock <IEstateDomainService> estateDomainService = new Mock <IEstateDomainService>();
            EstateRequestHandler        handler             = new EstateRequestHandler(estateDomainService.Object);

            CreateEstateUserRequest request = TestData.CreateEstateUserRequest;

            Should.NotThrow(async() =>
            {
                await handler.Handle(request, CancellationToken.None);
            });
        }
示例#2
0
        /// <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(CreateEstateUserRequest request,
                                        CancellationToken cancellationToken)
        {
            Guid userId = await this.EstateDomainService.CreateEstateUser(request.EstateId,
                                                                          request.EmailAddress,
                                                                          request.Password,
                                                                          request.GivenName,
                                                                          request.MiddleName,
                                                                          request.FamilyName,
                                                                          cancellationToken);

            return(userId);
        }
示例#3
0
        public void CreateEstateUserRequest_CanBeCreated_IsCreated()
        {
            CreateEstateUserRequest createEstateUserRequest = CreateEstateUserRequest.Create(TestData.EstateId,
                                                                                             TestData.EstateUserEmailAddress,
                                                                                             TestData.EstateUserPassword,
                                                                                             TestData.EstateUserGivenName,
                                                                                             TestData.EstateUserMiddleName,
                                                                                             TestData.EstateUserFamilyName);

            createEstateUserRequest.ShouldNotBeNull();
            createEstateUserRequest.EstateId.ShouldBe(TestData.EstateId);
            createEstateUserRequest.EmailAddress.ShouldBe(TestData.EstateUserEmailAddress);
            createEstateUserRequest.Password.ShouldBe(TestData.EstateUserPassword);
            createEstateUserRequest.GivenName.ShouldBe(TestData.EstateUserGivenName);
            createEstateUserRequest.MiddleName.ShouldBe(TestData.EstateUserMiddleName);
            createEstateUserRequest.FamilyName.ShouldBe(TestData.EstateUserFamilyName);
        }
示例#4
0
        /// <summary>
        /// Creates the estate user.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="createEstateUserRequest">The create estate user request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <CreateEstateUserResponse> CreateEstateUser(String accessToken,
                                                                      Guid estateId,
                                                                      CreateEstateUserRequest createEstateUserRequest,
                                                                      CancellationToken cancellationToken)
        {
            CreateEstateUserResponse response = null;

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

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

                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 <CreateEstateUserResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error creating new estate user Estate Id {estateId} Email Address {createEstateUserRequest.EmailAddress}.", ex);

                throw exception;
            }

            return(response);
        }
示例#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}");
                }
            }
        }