Beispiel #1
0
        public async Task QuandoExecutarGet()
        {
            _serviceMock = new Mock <IContaService>();
            _serviceMock.Setup(m => m.Get(Id)).ReturnsAsync(contaDto);
            _service = _serviceMock.Object;

            var result = await _service.Get(Id);

            Assert.NotNull(result);
            Assert.True(result.Id == Id);
            Assert.Equal(Name, result.Name);
            Assert.Equal(Description, result.Description);

            _serviceMock = new Mock <IContaService>();
            _serviceMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(Task.FromResult((ContaDto)null));
            _service = _serviceMock.Object;

            var _record = await _service.Get(Id);

            Assert.Null(_record);
        }
        public async Task <ActionResult> Get(Guid id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState)); // 400 bad request
                }
                var result = await _service.Get(id);

                if (result == null)
                {
                    return(NotFound());
                }

                return(Ok(result));
            }
            catch (ArgumentException ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Beispiel #3
0
 public Conta Get(int Num_Conta)
 {
     return(_contaService.Get(Num_Conta));
 }