public async Task Should_Not_Calculate_Interest_Because_Has_Notification()
        {
            var calculateInterestCommand = new CalculateInterestCommand(100, 5);

            await new CalculateInterestHandler(_http, _notification, _configuration).Handle(calculateInterestCommand, new CancellationToken());

            Assert.True(_notification.HasNotifications());
        }
Exemplo n.º 2
0
        public void CalculateInterestCommand_WithoutUrl_Valid()
        {
            //Arrange
            _command = CalculateInterestCommand.CalculateInterestRateCommandFactory.Create(100, 5, "url");

            //Act
            var isValid = _command.IsValid();

            //Assert
            Assert.IsTrue(isValid);
        }
Exemplo n.º 3
0
        public void CalculateInterestCommand_WithoutTime_Invalid()
        {
            //Arrange
            _command = CalculateInterestCommand.CalculateInterestRateCommandFactory.Create(100, 0, "url");

            //Act
            var isValid = _command.IsValid();

            //Assert
            Assert.IsFalse(isValid);
        }
Exemplo n.º 4
0
        public async Task <ActionResult <RespostaRequisicao> > Post(
            decimal?valorInicial, int?meses,
            [FromServices] InterestCalculatorHandler handler,
            CancellationToken cancellationToken)
        {
            var command       = new CalculateInterestCommand(valorInicial, meses);
            var commandResult = (CommandResult)await handler.Handle(command, cancellationToken);

            return(commandResult.Sucess ?
                   new OkObjectResult(new RespostaRequisicao(true, commandResult.Message, (decimal?)commandResult.Data)) :
                   new BadRequestObjectResult(new RespostaRequisicao(false, commandResult.Message, (decimal?)null)));
        }
        public async Task Should_Calculate_Interest(double initialValue, int months, string expectedResult)
        {
            _http.GetInterestTaxAsync().ReturnsForAnyArgs(x =>
            {
                return(Task.FromResult("0.01"));
            });

            var calculateInterestCommand = new CalculateInterestCommand(initialValue, months);

            var result = await new CalculateInterestHandler(_http, _notification, _configuration).Handle(calculateInterestCommand, new CancellationToken());

            Assert.True(result == expectedResult);
            Assert.True(!_notification.HasNotifications());
        }
Exemplo n.º 6
0
        public async Task <Event <decimal> > Handler(CalculateInterestCommand command)
        {
            if (!command.IsValid())
            {
                return(Event <decimal> .CreateError("Valores inválidos."));
            }

            var interestRate = await _getInterestRateHandler.Handler(GetInterestRateCommand.GetInterestRateCommandFactory.Create(command.UrlInterestRate));

            if (!interestRate.Valid)
            {
                return(Event <decimal> .CreateError(interestRate.Error));
            }

            var interest = (decimal)Math.Pow((double)(1 + interestRate.Value), command.Time);
            var result   = command.Value * interest;

            result = Math.Truncate(result * 100) / 100; //trunc

            return(Event <decimal> .CreateSuccess(result));
        }
        public async Task <IActionResult> CalculateInterestAsync([FromQuery] CalculateInterestCommand command)
        {
            var response = await _mediator.Send(command);

            return(HandleResponse(response));
        }