/// <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)); }
public IActionResult CalculaJurosPost([FromBody] MathSoft mathSoft) { if (mathSoft == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(this.MathCore.CalculateInterest(mathSoft))); }
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); }
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); }