public async Task DespesaMensalNaoAdicionarAsyncBadRequest() { var commandModel = new AddDespesaMensalCommandView(); var command = new AddDespesaMensalCommand(); _notificationMock.Setup(x => x.HasNotifications()).Returns(true); _mapperMock.Setup(x => x.Map <AddDespesaMensalCommand>(commandModel)).Returns(command); _mediatorMock.Setup(x => x.Send(command, default)).ReturnsAsync(false); var viewResult = (await _controller.PostAsync(commandModel)) as ObjectResult; viewResult.StatusCode.Should().Be(400); viewResult.Should().BeOfType <ObjectResult>(); }
public async Task <IActionResult> PostAsync([FromBody] AddDespesaMensalCommandView commandView) { try { _logger.Information($"[DespesaMensalController] INICIANDO A EXECUAÇÃO DO CADASTRO :: {ROTA_LOGUE}/AdicionarAsync/{JsonConvert.SerializeObject(commandView)}"); var despesaMensal = _mapper.Map <AddDespesaMensalCommand>(commandView); var sucess = await _mediator.Send(despesaMensal); _logger.Information("[DespesaMensalController] FIM DA EXECUÇÃO DO CADASTRO"); return(sucess ? Response("Despesa mensal adicionado com sucesso.") : Response(statusCode: HttpStatusCode.BadRequest)); } catch (Exception erro) { _logger.Error(erro, erro.Message); NotifyError("500", "[DespesaMensalController] Erro ao processar a requisição"); return(Response(statusCode: HttpStatusCode.InternalServerError)); } }
public async Task DespesaMensalAdicionarAsyncOkResult() { var commandModel = new AddDespesaMensalCommandView { IdSalario = new Guid("10AFDB5E-D7D1-4773-B040-F7B6F610484F"), Descricao = "Cartão de Crédito", Valor = decimal.One, Data = DateTime.Now }; var command = new Mock <AddDespesaMensalCommand>().Object; _notificationMock.Setup(x => x.HasNotifications()).Returns(false); _mapperMock.Setup(x => x.Map <AddDespesaMensalCommand>(commandModel)).Returns(command); _mediatorMock.Setup(x => x.Send(command, default)).ReturnsAsync(true); var viewResult = (await _controller.PostAsync(commandModel)) as ObjectResult; viewResult.StatusCode.Should().Be(200); viewResult.Should().BeOfType <ObjectResult>(); }