public async Task AddSalarioCommandValidar()
        {
            var commandBuilder = new AddSalarioCommandBuilder().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(2);
            commandBuilder.IsValid().Should().BeFalse();
            _mocker.Verify <IMediator>(x => x.Publish(It.IsAny <DomainNotification>(), default), Times.Exactly(2));
            _mocker.Verify <ISalarioRepository>(x => x.AddAsync(It.IsAny <Salario>(), default), Times.Never);
        }
        public async Task AddSalarioCommand()
        {
            var commandBuilder = new AddSalarioCommandBuilder()
                                 .ComPagamento(decimal.One)
                                 .ComAdiantamento(decimal.One)
                                 .Instanciar();

            commandBuilder.IsValid();

            _mocker.GetMock <ISalarioRepository>().Setup(x => x.AddAsync(It.IsAny <Salario>(), default))
            .Returns(Task.CompletedTask)
            .Callback <Salario, CancellationToken>((objeto, token) =>
            {
                objeto.Id.Should().NotBeEmpty();
                objeto.Pagamento.Should().Be(commandBuilder.Pagamento);
                objeto.Adiantamento.Should().Be(commandBuilder.Adiantamento);
                objeto.Status.Should().BeTrue();
            });
            _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 <ISalarioRepository>(x => x.AddAsync(It.IsAny <Salario>(), default), Times.Once);
        }
Пример #3
0
        public void NaoDeveApresentarMensagensValidacao()
        {
            var command = new AddSalarioCommandBuilder()
                          .ComAdiantamento(decimal.One)
                          .ComPagamento(decimal.One)
                          .Instanciar();

            command.IsValid();

            command.ValidationResult.IsValid.Should().BeTrue();
            command.ValidationResult.Errors.Count.Should().BeLessThan(1);
        }
Пример #4
0
        public void DeveValidarAdiantamento(decimal valor)
        {
            var command = new AddSalarioCommandBuilder()
                          .ComAdiantamento(valor)
                          .ComPagamento(decimal.One)
                          .Instanciar();

            command.IsValid();

            command.ValidationResult.IsValid.Should().BeFalse();
            command.ValidationResult.Errors[0].ErrorMessage.Should().Be("O valor Adiantamento deve ser maior que zero");
        }