public InvestorParameters GetInvestorParameters(int investorId, RuleType ruleType)
        {
            var iInvestorParameters = InvestorParametersDAL.GetInvestorParametersDB(investorId, ruleType);
            var investorParameters  = new InvestorParameters();

            investorParameters.Balance = 0;
            decimal value;

            investorParameters.Balance = InvestorParametersDAL.InvestorsBalance.TryGetValue(investorId, out value) ? value : 0;
            if (iInvestorParameters == null)
            {
                return(investorParameters);
            }
            var dailyInvestmentAllowed  = GetParameterValue("DailyInvestmentAllowed", iInvestorParameters);
            var weeklyInvestmentAllowed = GetParameterValue("WeeklyInvestmentAllowed", iInvestorParameters);

            investorParameters.DailyAvailableAmount  = dailyInvestmentAllowed == null ? investorParameters.Balance : (decimal)dailyInvestmentAllowed - InvestorParametersDAL.GetFundedAmountPeriod(investorId, InvesmentPeriod.Day);
            investorParameters.WeeklyAvailableAmount = weeklyInvestmentAllowed == null ? investorParameters.Balance : (decimal)weeklyInvestmentAllowed - InvestorParametersDAL.GetFundedAmountPeriod(investorId, InvesmentPeriod.Week);
            investorParameters.InvestorID            = investorId;
            return(investorParameters);
        }
示例#2
0
        public void TestGetMatchedInvestorsWithComplexRule()
        {
            var container = this.InitContainer(typeof(InvestorService));

            var ruleEngineDalMock = new Mock <IRulesEngineDAL>();

            var rulesDict1 = new Dictionary <int, InvestorRule>();

            rulesDict1.Add(1, new InvestorRule {
                Operator         = (int)Operator.And,
                MemberNameSource = null,
                MemberNameTarget = null,
                IsRoot           = true,
                LeftParamID      = 2,
                RightParamID     = 3,
                InvestorID       = 1,
                RuleID           = 1,
                UserID           = 1,
                RuleType         = 1
            });

            rulesDict1.Add(2, new InvestorRule {
                Operator         = (int)Operator.IsTrue,
                MemberNameSource = null,
                MemberNameTarget = null,
                IsRoot           = false,
                LeftParamID      = -1,
                RightParamID     = -1,
                InvestorID       = 1,
                RuleID           = 2,
                UserID           = 1,
                FuncName         = "RuleBadgetLevel",
                RuleType         = 1
            });

            rulesDict1.Add(3, new InvestorRule {
                Operator         = (int)Operator.LessThan,
                MemberNameSource = "ManagerApprovedSum",
                MemberNameTarget = "DailyAvailableAmount",
                IsRoot           = false,
                LeftParamID      = -1,
                RightParamID     = -1,
                InvestorID       = 1,
                RuleID           = 3,
                UserID           = 1,
                RuleType         = 1
            });

            var investorParameters = new InvestorParameters()
            {
                InvestorID           = 1,
                DailyAvailableAmount = 700,
                Balance = 500
            };


            var investorParametersDALMock  = new Mock <IInvestorParametersDAL>();
            var investorCashRequestDALMock = new Mock <IInvestorCashRequestDAL>();
            var genericRulesMock           = new Mock <IGenericRulesBLL>();

            ruleEngineDalMock.Setup(x => x.GetRules(1, RuleType.System)).Returns(rulesDict1);
            investorCashRequestDALMock.Setup(x => x.GetInvestorLoanCashRequest(1)).Returns(new InvestorLoanCashRequest()
            {
                ManagerApprovedSum = 20, CashRequestID = 1
            });
            investorParametersDALMock.Setup(x => x.GetInvestorsIds()).Returns(new List <int>()
            {
                1
            });
            investorParametersDALMock.Setup(x => x.GetInvestorParametersDB(1, RuleType.System)).Returns(new List <I_InvestorParams>()
            {
                new I_InvestorParams()
                {
                    InvestorID = 1, Type = 1, ParameterID = 1, Value = 1000, InvestorParamsID = 1
                }
            });
            genericRulesMock.Setup(x => x.RuleBadgetLevel(1, 1, 1)).Returns(true);
            Dictionary <int, decimal> dict2 = new Dictionary <int, decimal>();

            dict2.Add(1, 3000);
            investorParametersDALMock.Setup(x => x.InvestorsBalance).Returns(dict2);

            Dictionary <int, I_Parameter> ip = new Dictionary <int, I_Parameter>();

            ip.Add(1, new I_Parameter()
            {
                ParameterID  = 1,
                Name         = "DailyInvestmentAllowed",
                ValueType    = "Decimal",
                DefaultValue = 0,
                MaxLimit     = null,
                MinLimit     = null
            });

            ip.Add(2, new I_Parameter()
            {
                ParameterID  = 2,
                Name         = "WeeklyInvestmentAllowed",
                ValueType    = "Decimal",
                DefaultValue = 0,
                MaxLimit     = null,
                MinLimit     = null
            });

            investorParametersDALMock.Setup(x => x.InvestorsParameters).Returns(ip);


            container.Configure(r => r.ForSingletonOf <IInvestorCashRequestDAL>().Use(() => investorCashRequestDALMock.Object));
            container.Configure(r => r.ForSingletonOf <IRulesEngineDAL>().Use(() => ruleEngineDalMock.Object));
            container.Configure(r => r.ForSingletonOf <IInvestorParametersDAL>().Use(() => investorParametersDALMock.Object));
            container.Configure(r => r.ForSingletonOf <IGenericRulesBLL>().Use(() => genericRulesMock.Object));


            var investorService = container.GetInstance <IInvestorService>();

            var investor = investorService.GetMatchedInvestor(1);

            Assert.IsTrue(investor != null);

            genericRulesMock.Setup(x => x.RuleBadgetLevel(1, 1, 1))
            .Returns(false);

            investor = investorService.GetMatchedInvestor(1);
            Assert.IsTrue(investor == null);
        }