Beispiel #1
0
        public void Deve_Validar_Alteracaoes_Entre_Objetos(decimal valorCorrente, decimal valorNovo, bool resultaEsperado)
        {
            var novaTaxa     = ValorTaxaCobranca.Create(valorNovo);
            var taxaCorrente = ValorTaxaCobranca.Create(valorCorrente);

            var validarTaxaTrocou = taxaCorrente.Value.Equals(novaTaxa.Value);

            validarTaxaTrocou.Should().Be(resultaEsperado);
        }
Beispiel #2
0
        public void Deve_Criar_ValorTaxaCobranca_Sucesso()
        {
            const decimal valorTaxa = 5;
            var           taxa      = ValorTaxaCobranca.Create(valorTaxa);

            taxa.Should().NotBeNull();
            taxa.IsSuccess.Should().BeTrue();
            taxa.Value.Valor.Should().Be(valorTaxa);
        }
Beispiel #3
0
        public void Deve_Falhar_Criacao_ValorTaxaCobranca_Quando_Valor_For_Invalido()
        {
            const decimal valorTaxa = -1;
            var           taxa      = ValorTaxaCobranca.Create(valorTaxa);

            taxa.Should().NotBeNull();
            taxa.IsSuccess.Should().BeFalse();
            taxa.IsFailure.Should().BeTrue();
        }
Beispiel #4
0
        public void Deve_Validar_Alteracao_ValueObject_ValorTaxaCobranca(decimal valorCorrente, decimal valorNovo, bool resultaEsperado)
        {
            var novoId             = Guid.NewGuid().ToString();
            var valorTaxaCobranaca = ValorTaxaCobranca.Create(valorCorrente);
            var novaTaxaCobranca   = new TaxaCobranca(novoId, valorTaxaCobranaca.Value, TipoSegmento.Varejo);

            var novoValorTaxaCobranaca = ValorTaxaCobranca.Create(valorNovo);

            var resutado = novaTaxaCobranca.AtualizarTaxa(novoValorTaxaCobranaca.Value);

            resutado.IsSuccess.Should().Be(resultaEsperado);
        }
Beispiel #5
0
        public void Deve_Criar_TaxaCobranca_Valida()
        {
            const decimal valorTaxa = 5;

            var novoId             = Guid.NewGuid().ToString();
            var valorTaxaCobranaca = ValorTaxaCobranca.Create(valorTaxa);

            var novaTaxaCobranca = new TaxaCobranca(novoId, valorTaxaCobranaca.Value, TipoSegmento.Varejo);

            novaTaxaCobranca.TaxaCobrancaId.Should().Be(novoId);
            novaTaxaCobranca.ValorTaxa.Valor.Should().Be(valorTaxa);
        }
Beispiel #6
0
        private void CriarNovoValorTaxa(AtualizarTaxaCommand request, AtualizarTaxaResponse response)
        {
            var novoValorCobranca = ValorTaxaCobranca.Create(request.NovaTaxa);

            if (novoValorCobranca.IsFailure)
            {
                response.AddError(Errors.General
                                  .InvalidCommandArguments()
                                  .AddErroDetail(Errors.General.InvalidArgument("ValorNovaTaxaInvalido", string.Join("|", novoValorCobranca.Messages))));

                Logger.LogWarning($"{response.ErrorResponse}");
                return;
            }

            ValorTaxaCobranca = novoValorCobranca.Value;
        }
Beispiel #7
0
        public async Task <RegistrarNovaTaxaResponse> Handle(RegistrarNovaTaxaCommand request, CancellationToken cancellationToken)
        {
            var response = (RegistrarNovaTaxaResponse)request.Response;

            RegistrarNovaTaxaCommandValidator.ValidarCommand(request, response);
            if (response.IsFailure)
            {
                return(response);
            }

            var valorTaxaCobranca = ValorTaxaCobranca.Create(request.ValorTaxa);

            if (valorTaxaCobranca.IsFailure)
            {
                response.AddError(Errors.General.InvalidCommandArguments()
                                  .AddErroDetail(Errors.General.InvalidArgument("ValorTaxaInvalido", string.Join("|", valorTaxaCobranca.Messages))));
                return(response);
            }

            ObterTipoSegmentoPorId(request, response);
            if (response.IsFailure)
            {
                return(response);
            }

            await VerficarSegmentoJaRegistrado(request, response);

            if (response.IsFailure)
            {
                return(response);
            }

            TaxaCobranca = new TaxaCobranca(Guid.NewGuid().ToString(), valorTaxaCobranca.Value, TipoSegmento);

            await Registrar(request, response);

            if (response.IsFailure)
            {
                return(response);
            }

            await Mediator.DispatchDomainEvents(TaxaCobranca);

            response.SetPayLoad(TaxaCobranca.ConverterEntidadeParaResponse());

            return(response);
        }