public async Task AddDespesaMensalCommandValidar()
        {
            var commandBuilder = new AddDespesaMensalCommandBuilder().Instanciar();

            commandBuilder.IsValid();

            _mocker.GetMock <IMediator>().Setup(x => x.Publish(It.IsAny <DomainNotification>(), default))
            .Returns(Task.CompletedTask)
            .Callback <DomainNotification, CancellationToken>((notification, token) =>
            {
                notification.Should().NotBeNull();
                commandBuilder.ValidationResult.Errors
                .FirstOrDefault(x => x.PropertyName == notification.Key && x.ErrorMessage == notification.Value)
                .Should().NotBeNull();
                token.IsCancellationRequested.Should().BeFalse();
            });

            var resultado = await _commandHandler.Handle(commandBuilder, default);

            resultado.Should().BeFalse();
            commandBuilder.ValidationResult.Errors.Should().HaveCount(4);
            commandBuilder.IsValid().Should().BeFalse();
            _mocker.Verify <IMediator>(x => x.Publish(It.IsAny <DomainNotification>(), default), Times.Exactly(4));
            _mocker.Verify <IDespesaMensalRepository>(x => x.AddAsync(It.IsAny <DespesaMensal>(), default), Times.Never);
            _mocker.Verify <IDespesaMensalRepository>(x => x.UpdateAsync(It.IsAny <DespesaMensal>(), default), Times.Never);
            _mocker.Verify <IDespesaMensalRepository>(x => x.DeleteAsync(It.IsAny <DespesaMensal>(), default), Times.Never);
            _mocker.Verify <ISalarioRepository>(x => x.GetByIdAsync(It.IsAny <Guid>(), default), Times.Never);
            _mocker.Verify <ISalarioRepository>(x => x.AddAsync(It.IsAny <Salario>(), default), Times.Never);
            _mocker.Verify <ISalarioRepository>(x => x.UpdateAsync(It.IsAny <Salario>(), default), Times.Never);
            _mocker.Verify <ISalarioRepository>(x => x.DeleteAsync(It.IsAny <Salario>(), default), Times.Never);
        }
Example #2
0
        public void AddDespesaMensalNaoDeveApresentarMensagensValidacao()
        {
            var command = new AddDespesaMensalCommandBuilder()
                          .ComIdSalario(new Guid("10AFDB5E-D7D1-4773-B040-F7B6F610484F"))
                          .ComDescricao("Teste")
                          .ComValor(decimal.One)
                          .ComData(DateTime.Now)
                          .Instanciar();

            command.IsValid();

            command.ValidationResult.IsValid.Should().BeTrue();
            command.ValidationResult.Errors.Count.Should().BeLessThan(1);
        }
Example #3
0
        public void AddDespesaMensalDeveValidarIdSalario()
        {
            var command = new AddDespesaMensalCommandBuilder()
                          .ComDescricao("teste")
                          .ComValor(decimal.One)
                          .ComData(DateTime.Now)
                          .Instanciar();

            command.IsValid();

            command.ValidationResult.IsValid.Should().BeFalse();
            command.ValidationResult.Errors.Count.Should().Be(1);
            command.ValidationResult.Errors[0].ErrorMessage.Should().Be("Id salário inválido");
        }
Example #4
0
        public void AddDespesaMensalDeveValidarData()
        {
            var command = new AddDespesaMensalCommandBuilder()
                          .ComIdSalario(new Guid("10AFDB5E-D7D1-4773-B040-F7B6F610484F"))
                          .ComDescricao("Teste")
                          .ComValor(decimal.One)
                          .ComData(DateTime.MinValue)
                          .Instanciar();

            command.IsValid();

            command.ValidationResult.IsValid.Should().BeFalse();
            command.ValidationResult.Errors.Count.Should().Be(1);
            command.ValidationResult.Errors[0].ErrorMessage.Should().Be("Data inválida");
        }
Example #5
0
        public void AddDespesaMensalDeveValidarValor(decimal valor)
        {
            var command = new AddDespesaMensalCommandBuilder()
                          .ComIdSalario(new Guid("10AFDB5E-D7D1-4773-B040-F7B6F610484F"))
                          .ComDescricao("Teste")
                          .ComValor(valor)
                          .ComData(DateTime.Now)
                          .Instanciar();

            command.IsValid();

            command.ValidationResult.IsValid.Should().BeFalse();
            command.ValidationResult.Errors.Count.Should().Be(1);
            command.ValidationResult.Errors[0].ErrorMessage.Should().Be("O valor Pagamento deve ser maior que zero");
        }
        public async Task AddDespesaMensalCommand()
        {
            var salario   = new Salario(decimal.One, decimal.One);
            var idSalario = salario.Id;

            var commandBuilder = new AddDespesaMensalCommandBuilder()
                                 .ComDescricao("Cartão")
                                 .ComIdSalario(idSalario)
                                 .ComData(DateTime.Now)
                                 .ComValor(decimal.One)
                                 .Instanciar();

            commandBuilder.IsValid();

            _mocker.GetMock <IDespesaMensalRepository>().Setup(x => x.AddAsync(It.IsAny <DespesaMensal>(), default))
            .Returns(Task.CompletedTask)
            .Callback <DespesaMensal, CancellationToken>((objeto, token) =>
            {
                objeto.Id.Should().NotBeEmpty();
                objeto.Descricao.Should().Be(commandBuilder.Descricao);
                objeto.Data.Should().Be(commandBuilder.Data);
                objeto.Valor.Should().Be(commandBuilder.Valor);
                objeto.Status.Should().BeTrue();
                objeto.Salario.Id.Should().Be(salario.Id);
            });
            _mocker.GetMock <ISalarioRepository>().Setup(x => x.GetByIdAsync(idSalario, default)).ReturnsAsync(salario);
            _mocker.GetMock <IMediator>().Setup(x => x.Publish(It.IsAny <DomainNotification>(), default)).Returns(Task.CompletedTask);

            var resultado = await _commandHandler.Handle(commandBuilder, default);

            resultado.Should().BeTrue();
            _mocker.Verify <IMediator>(x => x.Publish(It.IsAny <DomainNotification>(), default), Times.Never);
            _mocker.Verify <IDespesaMensalRepository>(x => x.UpdateAsync(It.IsAny <DespesaMensal>(), default), Times.Never);
            _mocker.Verify <IDespesaMensalRepository>(x => x.DeleteAsync(It.IsAny <DespesaMensal>(), default), Times.Never);
            _mocker.Verify <ISalarioRepository>(x => x.AddAsync(It.IsAny <Salario>(), default), Times.Never);
            _mocker.Verify <ISalarioRepository>(x => x.UpdateAsync(It.IsAny <Salario>(), default), Times.Never);
            _mocker.Verify <ISalarioRepository>(x => x.DeleteAsync(It.IsAny <Salario>(), default), Times.Never);
            _mocker.Verify <IDespesaMensalRepository>(x => x.AddAsync(It.IsAny <DespesaMensal>(), default), Times.Once);
            _mocker.Verify <ISalarioRepository>(x => x.GetByIdAsync(It.IsAny <Guid>(), default), Times.Once);
        }