Beispiel #1
0
        /// <summary>
        /// Validates the voucher issue.
        /// </summary>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="operatorIdentifier">The operator identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="NotFoundException">
        /// Estate Id [{estateId}] is not a valid estate
        /// or
        /// Estate {estate.EstateName} has no operators defined
        /// or
        /// Operator Identifier [{operatorIdentifier}] is not a valid for estate [{estate.EstateName}]
        /// </exception>
        /// <exception cref="System.Exception">Estate Id [{estateId}] is not a valid estate
        /// or
        /// Operator Identifier [{operatorIdentifier}] is not a valid for estate [{estate.EstateName}]</exception>
        private async Task <EstateResponse> ValidateVoucherIssue(Guid estateId, String operatorIdentifier, CancellationToken cancellationToken)
        {
            EstateResponse estate = null;

            // Validate the Estate Record is a valid estate
            try
            {
                estate = await this.GetEstate(estateId, cancellationToken);
            }
            catch (Exception ex) when(ex.InnerException != null && ex.InnerException.GetType() == typeof(KeyNotFoundException))
            {
                throw new NotFoundException($"Estate Id [{estateId}] is not a valid estate");
            }

            if (estate.Operators == null || estate.Operators.Any() == false)
            {
                throw new NotFoundException($"Estate {estate.EstateName} has no operators defined");
            }

            EstateOperatorResponse estateOperator = estate.Operators.SingleOrDefault(o => o.Name == operatorIdentifier);

            if (estateOperator == null)
            {
                throw new NotFoundException($"Operator Identifier [{operatorIdentifier}] is not a valid for estate [{estate.EstateName}]");
            }

            return(estate);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the estate.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task <EstateResponse> GetEstate(String accessToken,
                                                     Guid estateId,
                                                     CancellationToken cancellationToken)
        {
            EstateResponse response = null;

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

            try
            {
                // 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.GetAsync(requestUri, 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 <EstateResponse>(content);
            }
            catch (Exception ex)
            {
                // An exception has occurred, add some additional information to the message
                Exception exception = new Exception($"Error getting estate Id {estateId}.", ex);

                throw exception;
            }

            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the estate.
        /// </summary>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task <EstateResponse> GetEstate(Guid estateId,
                                                      CancellationToken cancellationToken)
        {
            this.TokenResponse = await this.GetToken(cancellationToken);

            EstateResponse estate = await this.EstateClient.GetEstate(this.TokenResponse.AccessToken, estateId, cancellationToken);

            return(estate);
        }
        public void ModelFactory_Estate_NullInput_IsConverted()
        {
            Estate estateModel = null;

            ModelFactory modelFactory = new ModelFactory();

            EstateResponse estateResponse = modelFactory.ConvertFrom(estateModel);

            estateResponse.ShouldBeNull();
        }
        public async Task WhenICreateTheFollowingEstates(Table table)
        {
            foreach (TableRow tableRow in table.Rows)
            {
                String estateName = SpecflowTableHelper.GetStringRowValue(tableRow, "EstateName");

                CreateEstateRequest createEstateRequest = new CreateEstateRequest
                {
                    EstateId   = Guid.NewGuid(),
                    EstateName = estateName
                };

                CreateEstateResponse response = null;
                try
                {
                    response = await this.TestingContext.DockerHelper.EstateClient
                               .CreateEstate(this.TestingContext.AccessToken, createEstateRequest, CancellationToken.None)
                               .ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    this.TestingContext.DockerHelper.Logger.LogInformation(e.Message);
                    if (e.InnerException != null)
                    {
                        this.TestingContext.DockerHelper.Logger.LogInformation(e.InnerException.Message);
                        if (e.InnerException.InnerException != null)
                        {
                            this.TestingContext.DockerHelper.Logger.LogInformation(e.InnerException.InnerException.Message);
                        }
                    }
                }

                response.ShouldNotBeNull();
                response.EstateId.ShouldNotBe(Guid.Empty);

                // Cache the estate id
                this.TestingContext.AddEstateDetails(response.EstateId, estateName);

                //this.TestingContext.Logger.LogInformation($"Estate {estateName} created with Id {response.EstateId}");
            }

            foreach (TableRow tableRow in table.Rows)
            {
                EstateDetails  estateDetails = this.TestingContext.GetEstateDetails(tableRow);
                EstateResponse estate        = null;
                await Retry.For(async() =>
                {
                    estate = await this.TestingContext.DockerHelper.EstateClient
                             .GetEstate(this.TestingContext.AccessToken, estateDetails.EstateId, CancellationToken.None).ConfigureAwait(false);
                });

                estate.ShouldNotBeNull();
                estate.EstateName.ShouldBe(estateDetails.EstateName);
            }
        }
        public void ModelFactory_Estate_WithNoOperatorsOrSecurityUsers_IsConverted()
        {
            Estate estateModel = TestData.EstateModel;

            ModelFactory modelFactory = new ModelFactory();

            EstateResponse estateResponse = modelFactory.ConvertFrom(estateModel);

            estateResponse.ShouldNotBeNull();
            estateResponse.EstateId.ShouldBe(estateModel.EstateId);
            estateResponse.EstateName.ShouldBe(estateModel.Name);
        }
        public async Task WhenICreateTheFollowingEstates(Table table)
        {
            foreach (TableRow tableRow in table.Rows)
            {
                String estateName = SpecflowTableHelper.GetStringRowValue(tableRow, "EstateName");
                // Setup the subscriptions for the estate
                await Retry.For(async() => { await this.TestingContext.DockerHelper.PopulateSubscriptionServiceConfiguration(estateName).ConfigureAwait(false); },
                                retryFor : TimeSpan.FromMinutes(2),
                                retryInterval : TimeSpan.FromSeconds(30));
            }

            foreach (TableRow tableRow in table.Rows)
            {
                String estateName = SpecflowTableHelper.GetStringRowValue(tableRow, "EstateName");

                CreateEstateRequest createEstateRequest = new CreateEstateRequest
                {
                    EstateId   = Guid.NewGuid(),
                    EstateName = estateName
                };
                CreateEstateResponse response = null;
                await Retry.For(async() =>
                {
                    response = await this.TestingContext.DockerHelper.EstateClient
                               .CreateEstate(this.TestingContext.AccessToken, createEstateRequest, CancellationToken.None)
                               .ConfigureAwait(false);

                    response.ShouldNotBeNull();
                    response.EstateId.ShouldNotBe(Guid.Empty);
                }, retryFor : TimeSpan.FromMinutes(1),
                                retryInterval : TimeSpan.FromSeconds(30));


                this.TestingContext.Logger.LogInformation($"Estate {estateName} created with Id {response.EstateId}");

                EstateResponse estate = null;
                await Retry.For(async() =>
                {
                    estate = await this.TestingContext.DockerHelper.EstateClient
                             .GetEstate(this.TestingContext.AccessToken, response.EstateId, CancellationToken.None).ConfigureAwait(false);
                    estate.ShouldNotBeNull();

                    // Cache the estate id
                    this.TestingContext.AddEstateDetails(estate.EstateId, estate.EstateName);
                },
                                TimeSpan.FromMinutes(3),
                                TimeSpan.FromSeconds(30)).ConfigureAwait(false);

                estate.EstateName.ShouldBe(estateName);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Validates the voucher redemption.
        /// </summary>
        /// <param name="estateId">The estate identifier.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="NotFoundException">Estate Id [{estateId}] is not a valid estate</exception>
        private async Task <EstateResponse> ValidateVoucherRedemption(Guid estateId, CancellationToken cancellationToken)
        {
            EstateResponse estate = null;

            // Validate the Estate Record is a valid estate
            try
            {
                estate = await this.GetEstate(estateId, cancellationToken);
            }
            catch (Exception ex) when(ex.InnerException != null && ex.InnerException.GetType() == typeof(KeyNotFoundException))
            {
                throw new NotFoundException($"Estate Id [{estateId}] is not a valid estate");
            }

            return(estate);
        }
Beispiel #9
0
        /// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="estate">The estate.</param>
        /// <returns></returns>
        public EstateResponse ConvertFrom(Estate estate)
        {
            if (estate == null)
            {
                return(null);
            }

            EstateResponse estateResponse = new EstateResponse
            {
                EstateName    = estate.Name,
                EstateId      = estate.EstateId,
                Operators     = new List <EstateOperatorResponse>(),
                SecurityUsers = new List <SecurityUserResponse>()
            };

            if (estate.Operators != null && estate.Operators.Any())
            {
                estate.Operators.ForEach(o => estateResponse.Operators.Add(new EstateOperatorResponse
                {
                    Name       = o.Name,
                    OperatorId = o.OperatorId,
                    RequireCustomMerchantNumber = o.RequireCustomMerchantNumber,
                    RequireCustomTerminalNumber = o.RequireCustomTerminalNumber
                }));
            }

            if (estate.SecurityUsers != null && estate.SecurityUsers.Any())
            {
                estate.SecurityUsers.ForEach(s => estateResponse.SecurityUsers.Add(new SecurityUserResponse
                {
                    EmailAddress   = s.EmailAddress,
                    SecurityUserId = s.SecurityUserId
                }));
            }

            return(estateResponse);
        }