public async Task <RendaPorPessoaDto> Armazenar(RendaPorPessoaDto dto) { if (!ValidarDto(dto)) { return(null); } var rendaPorPessoa = new RendaPorPessoa( dto.PessoaId, dto.NomePessoa, dto.Valor); if (rendaPorPessoa.Invalid) { Notificador.Notificar(rendaPorPessoa.Notificacoes); return(null); } await _rendaPorPessoaRepositorio.Incluir(rendaPorPessoa); await _rendaPorPessoaRepositorio.Salvar(); var retorno = new RendaPorPessoaDto { Id = rendaPorPessoa.Id, PessoaId = rendaPorPessoa.PessoaId, NomePessoa = rendaPorPessoa.NomePessoa, Valor = rendaPorPessoa.Valor }; _alteradorDePontosPorInsercaoDeRenda.Alterar(retorno); return(retorno); }
private bool ValidarDto(RendaPorPessoaDto dto) { if (dto == null) { Notificador.Notificar("Dto", RendaPorPessoaDicionarioDeMensagensDeValidacao.MensagemDtoInvalido); return(false); } return(true); }
public async Task NaoDeveArmazenarRendaPorPessoaQuandoDtoForInvalido() { //Given RendaPorPessoaDto dtoInvalido = null; //When var retorno = await _armanezadorDeRendaPorPessoa.Armazenar(dtoInvalido); //Then _rendaPorPessoaRepositorioMock.Verify(repositorio => repositorio.Incluir(It.IsAny <RendaPorPessoa>()), Times.Never); _rendaPorPessoaRepositorioMock.Verify(repositorio => repositorio.Salvar(), Times.Never); _notificadorMock.Verify(notificador => notificador.Notificar(It.IsAny <string>(), RendaPorPessoaDicionarioDeMensagensDeValidacao.MensagemDtoInvalido)); Assert.Null(retorno); }
public async Task DeveInserirPessoa() { //Given var dto = new RendaPorPessoaDto { PessoaId = _faker.Random.Guid(), NomePessoa = _faker.Person.FullName, Valor = _faker.Random.Decimal(30, 567) }; var(response, retorno) = await PostRendaPorPessoa(dto); //Then Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(retorno); Assert.Equal(dto.PessoaId, retorno.PessoaId); Assert.Equal(dto.NomePessoa, retorno.NomePessoa); Assert.Equal(dto.Valor, retorno.Valor); }
public async Task NaoDeveArmazenarRendaPorPessoaQuandoObjetoRendaPorPessoaForInvalido() { //Given string nomePessoaInvalido = null; var dto = new RendaPorPessoaDto { PessoaId = _faker.Random.Guid(), NomePessoa = nomePessoaInvalido, Valor = _faker.Random.Decimal(40) }; //When var retorno = await _armanezadorDeRendaPorPessoa.Armazenar(dto); //Then _rendaPorPessoaRepositorioMock.Verify(repositorio => repositorio.Incluir(It.IsAny <RendaPorPessoa>()), Times.Never); _rendaPorPessoaRepositorioMock.Verify(repositorio => repositorio.Salvar(), Times.Never); _notificadorMock.Verify(notificador => notificador.Notificar(It.IsAny <IReadOnlyCollection <Notification> >()), Times.Once); Assert.Null(retorno); }
public async Task DeveArmazenarRendaPorPessoa() { //Given var dto = new RendaPorPessoaDto { PessoaId = _faker.Random.Guid(), NomePessoa = _faker.Person.FullName, Valor = _faker.Random.Decimal(40) }; //When var retorno = await _armanezadorDeRendaPorPessoa.Armazenar(dto); //Then _rendaPorPessoaRepositorioMock.Verify(repositorio => repositorio.Incluir(It.IsAny <RendaPorPessoa>()), Times.Once); _rendaPorPessoaRepositorioMock.Verify(repositorio => repositorio.Salvar(), Times.Once); _alteradorDePontosPorInsercaoDeRendaMock.Verify(servico => servico.Alterar(It.IsAny <RendaPorPessoaDto>()), Times.Once); _notificadorMock.Verify(notificador => notificador.Notificar(It.IsAny <string>(), It.IsAny <string>()), Times.Never); _notificadorMock.Verify(notificador => notificador.Notificar(It.IsAny <IReadOnlyCollection <Notification> >()), Times.Never); Assert.NotNull(retorno); }
private async Task <(HttpResponseMessage, RendaPorPessoaDto)> PostRendaPorPessoa(RendaPorPessoaDto dto) { var json = JsonConvert.SerializeObject(dto); var data = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PostAsync("/api/rendaporpessoa", data); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); return( response, JsonConvert.DeserializeObject <RendaPorPessoaDto>(responseString) ); }
public void Alterar(RendaPorPessoaDto dto) { _enviarRendaParaPontuacao.EnviarParaFila(_configuracaoDeEnvioDeMensagem, dto); }
public async Task <ActionResult> Salvar([FromServices] IArmazenadorDeRendaPorPessoa servico, [FromBody] RendaPorPessoaDto dto) => Ok(await servico.Armazenar(dto));
public void ProcessarMensagem(RendaPorPessoaDto dto) { // TODO: Chamar serviço de alteração }