Beispiel #1
0
        public async Task E_Possivel_Executar_Metodo_Get_Complete_by_IBGE()
        {
            _serviceMock = new Mock <IMunicipioService>();
            _serviceMock.Setup(m => m.GetCompleteByIBGE(CodigoIBGEMunicipio)).ReturnsAsync(municipioDtoCompleto);
            _service = _serviceMock.Object;

            var result = await _service.GetCompleteByIBGE(CodigoIBGEMunicipio);

            Assert.NotNull(result);
            Assert.True(result.Id == IdMunicipio);
            Assert.Equal(NomeMunicipio, result.Nome);
            Assert.Equal(CodigoIBGEMunicipio, result.CodIBGE);
            Assert.NotNull(result.Uf);
        }
        public async Task <ActionResult> GetCompleteByIBGE(int codIBGE)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); //400 bad request - solicitacao inválida
            }
            try
            {
                var result = await _service.GetCompleteByIBGE(codIBGE);

                if (result == null)
                {
                    return(NotFound());
                }
                return(Ok(result));
            }
            catch (ArgumentException e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }