/// <summary> /// Initializes a new instance of the <see cref="ThrottleProcesser"/> class. /// By default, the <see cref="QuotaExceededResponseCode"/> property /// is set to 429 (Too Many Requests). /// </summary> public ThrottleProcesser( ThrottlePolicy policy, IIpAddressParser ipAddressParser, IPolicyRepository policyRepo = null, IThrottleRepository throttleRepo = null) { Logger = new DefaultThrottleLogger(); QuotaExceededResponseCode = (HttpStatusCode)429; processResult = new ThrottleProcessResult { IsPass = true }; ThrottleRepo = throttleRepo; if (ThrottleRepo == null) { ThrottleRepo = new WebCacheThrottleRepository(); } ThrottlingCore = new ThrottlingCore(ipAddressParser); ThrottlingCore.ThrottleRepo = ThrottleRepo; PolicyRepo = policyRepo; if (PolicyRepo == null) { PolicyRepo = new WebCachePolicyRepository(); } Policy = policy; PolicyRepo.Save(ThrottleManager.GetPolicyKey(), policy); }
public void RepoFailTest(int policyId) { Mock <IPolicyRepo> mock = new Mock <IPolicyRepo>(); mock.Setup(p => p.GetChainOfProviders(policyId)).Returns(providerPolicies); PolicyRepo pr = new PolicyRepo(); var result = pr.GetChainOfProviders(policyId); Assert.AreEqual(0, result.Count()); }
public void PolicyGetProviderList_Repo_InvalidInput_ReturnsWrongValue(int policyId) { Mock <IPolicyRepo> mock = new Mock <IPolicyRepo>(); mock.Setup(p => p.GetChainOfProviders(policyId)).Returns(providerPolicies); PolicyRepo pr = new PolicyRepo(); var result = pr.GetChainOfProviders(policyId); Assert.AreEqual(0, result.Count()); }
public ThrottleProcessResult Process(RequestIdentity identity, IEnableThrottlingAttribute attrPolicy = null) { Identity = identity; Policy = PolicyRepo.FirstOrDefault(ThrottleManager.GetPolicyKey()); if (Policy != null) { Checking(attrPolicy); } return(processResult); }
public void EligibleBenefitTest_Repo_InvalidInput_ReturnsWrongValue(int policyId, int memberId) { string p = ""; Mock <IPolicyRepo> policyContextMock = new Mock <IPolicyRepo>(); var policyRepo = new PolicyRepo(); policyContextMock.Setup(x => x.GetEligibleBenefits(policyId, memberId)).Returns(p); var result = policyRepo.GetEligibleBenefits(policyId, memberId); Assert.AreNotEqual("MedicalCheckup", result); Assert.AreEqual("Invalid Data", result); }
public void RepoTestFail(int policyId, int memberId, int benefitId) { //double d = 0.0; Mock <IPolicyRepo> policyContextMock = new Mock <IPolicyRepo>(); var policyRepo = new PolicyRepo(); policyContextMock.Setup(x => x.GetEligibleClaimAmount(policyId, memberId, benefitId)).Returns(d); var result = policyRepo.GetEligibleClaimAmount(policyId, memberId, benefitId); Assert.AreEqual(-1, result); Assert.AreNotEqual(100000.00, result); }
public void GetEligbleClaimAmount_Repo_ValidInput_ReturnsRightValue(int policyId, int memberId, int benefitId) { double d = 0.0; Mock <IPolicyRepo> policyContextMock = new Mock <IPolicyRepo>(); var policyRepo = new PolicyRepo(); policyContextMock.Setup(x => x.GetEligibleClaimAmount(policyId, memberId, benefitId)).Returns(d); var result = policyRepo.GetEligibleClaimAmount(policyId, memberId, benefitId); Assert.IsNotNull(result); Assert.AreEqual(100000.00, result); }
public void RepoTestPass(int policyId, int memberId) { string p = ""; Mock <IPolicyRepo> policyContextMock = new Mock <IPolicyRepo>(); var policyRepo = new PolicyRepo(); policyContextMock.Setup(x => x.GetEligibleBenefits(policyId, memberId)).Returns(p); var result = policyRepo.GetEligibleBenefits(policyId, memberId); Assert.IsNotNull(result); Assert.AreEqual("MedicalCheckup", result); }
public Policy SavePolicy(Guid guid, Client client, Vehicle vehicle, Broker broker) { PolicyQuote quote = QuoteRepo.GetByID(guid); if (quote == null) { throw new Exception("The supplied guid not exists"); } if (quote.Period.Count > 0) { throw new Exception("The quote already is transferred to policy"); } //check if exists policy with quote //check if the quid belong to the brokee or not //check againts quote starting date, and modify if we need!!! string policyNumber = GetNextPolicyNumber(quote.Product_ID); client.ClientCode = policyNumber; Policy policy = new Policy() { PolicyNumber = policyNumber, PolicyStartDate = quote.PolicyStartDate, PolicyEndDate = quote.PolicyEndDate, IsFixedTerm = quote.PolicyType_ID == PolicyTypes.FixedTerm ? true : false, Product_ID = Convert.ToInt32(quote.Product_ID), Status_ID = Convert.ToInt32(PolicyStatuses.Policy), Broker_ID = quote.Broker_ID, CreatedBy_ID = 1, //sysadmin, to do Client = client, Vehicle = vehicle, PolicyPeriods = new List <PolicyPeriod>() { new PolicyPeriod() { PeriodStartDate = quote.PolicyStartDate, PeriodEndDate = quote.PolicyEndDate, Premium = quote.Premium, IsLastPeriod = true, PeriodNumber = 1, PaymentType_ID = Convert.ToInt32(quote.PolicyPaymentMethod_ID), PreviousPolicyPeriod_ID = null, Quote = quote, Installment = new List <PolicyInstallment>() { new PolicyInstallment() { Nr = 1, Type = 1, DueDate = quote.PolicyStartDate, Value = quote.Premium } }, InsurancePolicies = new List <InsurancePolicy>() { new InsurancePolicy() { Company = Convert.ToInt32(quote.InsuranceCompany), PolicyNumber = quote.InsurancePolicyNumber, StartDate = quote.InsuranceStartDate, EndDate = quote.InsuranceEndDate } } } } }; Policy savedPolicy = PolicyRepo.Insert(policy); SaveChanges(); return(savedPolicy); }
public IEnumerable <Policy> GetAllPolicy() { return(PolicyRepo.GetAll()); //return Context.Policy.ToList(); }