Example #1
0
        public void GivenNPVRequestAndParametersAreValidReturnResult()
        {
            var request = new NPVRequest
            {
                CashFlows = new List <CashFlow>
                {
                    new CashFlow {
                        Amount = 200
                    },
                    new CashFlow {
                        Amount = 300
                    },
                },
                DiscountIncrement = 1,
                InitialInvestment = 1000,
                LowerDiscount     = 1,
                UpperDiscount     = 5
            };

            A.CallTo(() => _npvService.Calculate(A <NPVRequest> .Ignored)).Returns(new NPVResponse());

            var result   = _npvController.Calculate(request);
            var content  = result as OkObjectResult;
            var response = content.Value as NPVResponse;

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <OkObjectResult>(result);
            Assert.IsNotNull(response);
        }
Example #2
0
        public IActionResult Calculate([FromBody] NPVRequest request)
        {
            try
            {
                var result = _npvCalculatorService.Calculate(request);

                if (result != null)
                {
                    return(Ok(result));
                }

                return(BadRequest("Something went wrong."));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }