private async Task <string> ObterCobrancas(BuscarTodasCobrancasCommand request)
        {
            string responsecontext = string.Empty;
            var    endpoint        = $"{request.Http.Protocol}://{request.Http.Host}{request.Http.EndPoint}";

            using (HttpRequestMessage requestMessage = new
                                                       HttpRequestMessage(new HttpMethod(request.Http.Method), endpoint))
            {
                if (request.Http.Headers.Count > 0)
                {
                    foreach (var item in request.Http.Headers)
                    {
                        requestMessage.Headers.Add(item.Key, item.Value);
                    }
                }

                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient
                    .DefaultRequestHeaders
                    .Accept
                    .Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    requestMessage.Content = new
                                             StringContent(request.Http.Content, Encoding.UTF8, "application/json");

                    var httpresult = await httpClient
                                     .SendAsync(requestMessage);

                    responsecontext = await httpresult.Content.ReadAsStringAsync();
                }
            }

            return(await Task.FromResult(responsecontext));
        }
        public async Task <List <Cobranca> > Handle(BuscarTodasCobrancasCommand request, CancellationToken cancellationToken)
        {
            var retryPolicy = Policy
                              .Handle <HttpRequestException>()
                              .WaitAndRetryAsync(request.Http.Police.Retry.MaxRetryAttempts,
                                                 i => request.Http.Police.Retry.PauseBetweenFailures);

            var result = await retryPolicy
                         .ExecuteAsync(async() =>
            {
                return(await ObterCobrancas(request));
            });

            var qg2cobrancas = JsonConvert.DeserializeObject <QG2Cobrancas>(result, new JsonSerializerSettings
            {
                ContractResolver = new LowercaseContractResolver()
            });

            List <Cobranca> cobrancas = new List <Cobranca>();

            qg2cobrancas
            .data
            .ForEach(item =>
            {
                cobrancas.Add(new Cobranca(item));
            });

            return(await Task.FromResult(cobrancas));
        }