コード例 #1
0
        public void NotificacaoCpfJaCadastrado()
        {
            //Arrange
            var cpf = "448.028.616-05";

            _contribuinteRepository.IsCpfRegistered(cpf).Returns(true);
            var handler = new IncluirContribuinteHandler(_uow, _notifications, _mediator, _contribuinteRepository);
            var command = new IncluirContribuinteCommand(cpf, "Diego Matheus Porto", 2, 2335);

            //Act
            handler.Handle(command, new CancellationToken(false));
            //Assert
            _mediator.ReceivedWithAnyArgs(1).Publish((INotification)null);
        }
コード例 #2
0
        public Task Handle(IncluirContribuinteCommand request, CancellationToken cancellationToken)
        {
            if (!IsValidCommand(request))
            {
                return(Task.CompletedTask);
            }

            if (_contribuinteRepository.IsCpfRegistered(request.CPF))
            {
                return(Notify(nameof(request.CPF), "Cpf já cadastrado."));
            }

            var contribuinte = new Contribuinte(request.CPF, request.Nome, request.NumeroDependentes, request.RendaBrutaMensal);

            _contribuinteRepository.Add(contribuinte);

            Commit();

            return(Task.CompletedTask);
        }