Esempio n. 1
0
        public async Task <IActionResult> CalculateNetworth([FromBody] NetworthRequest networthRequest)
        {
            var test  = CurrentUser;
            var limit = await _userTierService.GetFieldCountLimitAsync();

            return(new ObjectResult(_calculatorService.CalculateNetworth(networthRequest, limit)));
        }
Esempio n. 2
0
        public NetworthResult CalculateNetworth(NetworthRequest networthRequest, int fieldLengthLimit)
        {
            try {
                ValidateValues(networthRequest.Assets, fieldLengthLimit);
                ValidateValues(networthRequest.Liabilities, fieldLengthLimit);

                var assetTotal     = GetTotal(networthRequest.Assets);
                var liabilityTotal = GetTotal(networthRequest.Liabilities);
                return(new NetworthResult(assetTotal, liabilityTotal));
            } catch (NullReferenceException) {
                _validationService.ThrowValidationErrors("Field list not initialized");
            }

            return(new NetworthResult());
        }
Esempio n. 3
0
        public void CalculatorServiceTest_DynamicFieldLengthDisallowedTest()
        {
            var networthReq = new NetworthRequest();

            networthReq.Assets      = new List <FinancialEntity>();
            networthReq.Liabilities = new List <FinancialEntity>();

            var asset = new FinancialEntity();

            asset.StaticFields  = new List <LabelValue>();
            asset.DynamicFields = new List <LabelValue>();

            asset.StaticFields.Add(new LabelValue {
                Label = "Chequing", Value = -1000
            });
            asset.StaticFields.Add(new LabelValue {
                Label = "Primary Home", Value = 500000
            });

            asset.DynamicFields.Add(new LabelValue {
                Label = "Investment 1", Value = 2000
            });
            asset.DynamicFields.Add(new LabelValue {
                Label = "Investment 2", Value = 5000
            });

            var liability = new FinancialEntity();

            liability.StaticFields  = new List <LabelValue>();
            liability.DynamicFields = new List <LabelValue>();

            liability.StaticFields.Add(new LabelValue {
                Label = "Loan", Value = 10000
            });
            liability.DynamicFields.Add(new LabelValue {
                Label = "Credit Card 1", Value = 2000
            });

            networthReq.Assets.Add(asset);
            networthReq.Liabilities.Add(liability);

            Action testAction = () => _calculatorService.CalculateNetworth(networthReq, 1);

            Assert.Throws <ValidationErrorException>(testAction);
        }
Esempio n. 4
0
        public void CalculatorServiceTest_HappyPathTest()
        {
            var networthReq = new NetworthRequest();

            networthReq.Assets      = new List <FinancialEntity>();
            networthReq.Liabilities = new List <FinancialEntity>();

            var asset = new FinancialEntity();

            asset.StaticFields  = new List <LabelValue>();
            asset.DynamicFields = new List <LabelValue>();

            asset.StaticFields.Add(new LabelValue {
                Label = "Chequing", Value = 1000
            });
            asset.StaticFields.Add(new LabelValue {
                Label = "Primary Home", Value = 500000
            });

            asset.DynamicFields.Add(new LabelValue {
                Label = "Investment 1", Value = 2000
            });

            var liability = new FinancialEntity();

            liability.StaticFields  = new List <LabelValue>();
            liability.DynamicFields = new List <LabelValue>();

            liability.StaticFields.Add(new LabelValue {
                Label = "Loan", Value = 10000
            });
            liability.DynamicFields.Add(new LabelValue {
                Label = "Credit Card 1", Value = 2000
            });

            networthReq.Assets.Add(asset);
            networthReq.Liabilities.Add(liability);

            var result = _calculatorService.CalculateNetworth(networthReq, 1);

            Assert.Equal(503000, result.TotalAssets);
            Assert.Equal(12000, result.TotalLiabilities);
            Assert.Equal(491000, result.NetWorth);
        }