public async Task E_Possivel_Executar_Metodo_Get() { _serviceMock = new Mock <IUfService>(); _serviceMock.Setup(m => m.Get(IdUf)).ReturnsAsync(ufDto); _service = _serviceMock.Object; var result = await _service.Get(IdUf); Assert.NotNull(result); Assert.True(result.Id == IdUf); Assert.Equal(Estado, result.Estado); _serviceMock = new Mock <IUfService>(); _serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(Task.FromResult((UfDto)null)); _service = _serviceMock.Object; var _record = await _service.Get(IdUf); Assert.Null(_record); }
public async Task Execute_Get() { _serviceMock = new Mock <IUfService>(); _serviceMock.Setup(m => m.Get(IdUf)).ReturnsAsync(ufDto); _service = _serviceMock.Object; var result = await _service.Get(IdUf); Assert.NotNull(result); //Assert.True(result.Id == IdUsuario); Assert.Equal(Nome, result.Nome); _serviceMock = new Mock <IUfService>(); _serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(Task.FromResult((UfDto)null)); _service = _serviceMock.Object; var _record = await _service.Get(IdUf); Assert.Null(_record); }
public async Task <ActionResult> Get(Guid id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); //400 bad request - solicitacao inválida } try { var result = await _service.Get(id); if (result == null) { return(NotFound()); } return(Ok(result)); } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }