Esempio n. 1
0
        public async void TestarObterCatalogo()
        {
            var request = new ObterCatalogoRequest()
            {
                IdCatalogo = "1LY7A4ZK4L5KVAKXA7HF4T4SQC"
            };

            var response = await ObterService().ObterCatalogo(request);

            Assert.True(response.Valido && response.IdProdutos.Any());
        }
Esempio n. 2
0
        public async void TestarExceptionObterCatalogo()
        {
            var request = new ObterCatalogoRequest()
            {
                IdCatalogo = "FAIL"
            };

            var response = await ObterService().ObterCatalogo(request);

            Assert.True(!response.Valido && response.Mensagens.Any());
        }
Esempio n. 3
0
        public async Task <ObterCatalogoResponse> ObterCatalogo(ObterCatalogoRequest request)
        {
            var response = new ObterCatalogoResponse();

            try
            {
                var validationResult = request.Validate();
                if (!validationResult.IsValid)
                {
                    response.Valido = false;
                    foreach (var failure in validationResult.Errors)
                    {
                        response.AdicionarMensagemErro(TipoMensagem.Validacao, failure.ErrorMessage);
                    }
                }
                else
                {
                    var obterCatalogoResponse = await _httpService.ObterCatalogo(request);

                    obterCatalogoResponse.Valido = true;

                    return(obterCatalogoResponse);
                }
            }
            catch (BHNResponseException bhnEx)
            {
                response.Valido = false;
                response.AdicionarMensagemErro(TipoMensagem.Aplicacao, bhnEx.ToString());
            }
            catch (ApplicationException appEx)
            {
                response.Valido = false;
                response.AdicionarMensagemErro(TipoMensagem.ErroNegocio, appEx.Message);
            }
            catch (Exception ex)
            {
                response.Valido = false;
                response.AdicionarMensagemErro(TipoMensagem.ErroAplicacao, ex.StackTrace);
            }
            return(response);
        }
Esempio n. 4
0
        public async Task <ObterCatalogoResponse> ObterCatalogo(ObterCatalogoRequest request)
        {
            var response = new ObterCatalogoResponse()
            {
                DadosCatalogo = new DadosCatalogoResponse(),
                IdProdutos    = new List <string>()
            };

            using (var httpClient = HelperBHNHttpService.ObterHttpClientBhn(_dadosBhn))
            {
                var endpoint    = HelperBHNHttpService.ObterEndPoint(this._dadosBhn.DetalhesCatalogoRota, request.IdCatalogo);
                var bhnResponse = await httpClient.GetAsync(endpoint);

                var responseString = bhnResponse.ConvertToString();

                if (bhnResponse.Valido())
                {
                    JObject bhnObjectResponse = JObject.Parse(responseString);
                    response.DadosCatalogo = new DadosCatalogoResponse()
                    {
                        IdCatalogo = bhnObjectResponse["summary"]["entityId"].ToString().ObterEntityId(),
                        Nome       = bhnObjectResponse["summary"]["name"].ToString(),
                        Versao     = bhnObjectResponse["summary"]["version"].ToString(),
                    };
                    var details = bhnObjectResponse["details"]["productIds"].Children().Select(s => s.ToString().ObterEntityId()).ToList();
                    response.IdProdutos = details;
                }
                else
                {
                    var erro = JsonConvert.DeserializeObject <BHNErrorResponse>(responseString.TratarErrorResponse());
                    throw new BHNResponseException(bhnResponse.StatusCode, erro.ErrorCode, erro.Message);
                }
            }

            return(response);
        }
Esempio n. 5
0
        public async Task <ActionResult> Get(ObterCatalogoRequest request)
        {
            var response = await _catalogService.ObterCatalogo(request);

            return(this.GetHttpResponse(response));
        }