Esempio n. 1
0
        public async Task QuandoExecutarGetPost()
        {
            _serviceMock = new Mock <IContaService>();
            _serviceMock.Setup(m => m.Post(contaDtoCreate)).ReturnsAsync(contaDtoCreateResult);
            _service = _serviceMock.Object;

            var result = await _service.Post(contaDtoCreate);

            Assert.NotNull(result);
            Assert.Equal(Name, result.Name);
            Assert.Equal(Description, result.Description);
        }
        public async Task <ActionResult> Post([FromBody] ContaDtoCreate conta)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState)); // 400 bad request
                }

                var result = await _service.Post(conta);

                if (result != null)
                {
                    return(Created(new Uri(Url.Link("GetContaWithId", new { id = result.Id })), result));
                }

                return(BadRequest());
            }
            catch (ArgumentException ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Esempio n. 3
0
 public string Post(Conta conta)
 {
     _contaService.Post(conta);
     return("");
 }