Exemplo n.º 1
0
        /// <summary>The calculate interest.</summary>
        /// <param name="mathSoft">The math soft.</param>
        /// <returns>The <see cref="decimal"/>.</returns>
        public decimal CalculateInterest(MathSoft mathSoft)
        {
            mathSoft.TotalValue = mathSoft.InitialValue;

            for (var i = 0; i < mathSoft.Month; i++)
            {
                mathSoft.TotalValue *= (decimal)(1 + this.settings.InterestCalculated);
            }

            return(mathSoft.TotalValue.TruncateWithCases(this.settings.DecimalCases));
        }
Exemplo n.º 2
0
        public IActionResult CalculaJurosPost([FromBody] MathSoft mathSoft)
        {
            if (mathSoft == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(this.MathCore.CalculateInterest(mathSoft)));
        }
Exemplo n.º 3
0
        public void ShouldBeBad()
        {
            var mathSoft = new MathSoft {
                InitialValue = 100, Month = 10, TotalValue = (decimal)105.10
            };
            var mathCore = new Mock <IMathCore>();

            mathCore.Setup(x => x.CalculateInterest(null))
            .Returns(mathSoft.TotalValue);

            var controller = new CalculaJurosController(mathCore.Object);

            var result = controller.CalculaJurosPost(null);

            Assert.True(((StatusCodeResult)result).StatusCode == 400);
        }
Exemplo n.º 4
0
        public void ShouldBeWrongValue()
        {
            var mathSoft = new MathSoft {
                InitialValue = 100, Month = 5, TotalValue = (decimal)105.10
            };
            var mathCore = new Mock <IMathCore>();

            mathCore.Setup(x => x.CalculateInterest(mathSoft))
            .Returns(mathSoft.TotalValue);

            var controller = new CalculaJurosController(mathCore.Object);

            var result = controller.CalculaJurosPost(mathSoft);

            var okObjectResult = Assert.IsType <OkObjectResult>(result);

            Assert.NotEqual((decimal)110.10, okObjectResult.Value);
        }