public Policy GetPolicyFromJsonString(string policyJson) { //throw new System.NotImplementedException(); var serializer = new PolicySerializer(); return(serializer.GetPolicyFromJsonString(policyJson)); }
public void ReturnsDefaultPolicyFromEmptyJsonString() { var inputJson = "{}"; var serializer = new PolicySerializer(); var result = serializer.GetPolicyFromJsonString(inputJson); var policy = new Policy(); Assert.Equal(result.Amount, policy.Amount); // AssertPoliciesEqual(result, policy); }
public void Rate() { Logger.Log("Starting ExecuteSomething"); string policyJson = PolicySource.GetPolicyFromSource(); var policy = PolicySerializer.GetPolicyFromJsonString(policyJson); switch (policy.Type) { case PolicyType.Auto: Logger.Log("Rating AUTO policy..."); if (policy.Make == "BMW") { if (policy.Deductible < 500) { Rating = 1000m; } Rating = 900m; } break; case PolicyType.Land: Logger.Log("Rating LAND policy..."); if (policy.BondAmount == 0 || policy.Valuation == 0) { Console.WriteLine("Land policy must specify Bond Amount and Valuation."); return; } Rating = policy.BondAmount * 0.05m; break; case PolicyType.Life: Logger.Log("Rating LIFE policy..."); int age = DateTime.Today.Year - policy.DateOfBirth.Year; decimal baseRate = policy.Amount * age / 200; if (policy.IsSmoker) { Rating = baseRate * 2; break; } Rating = baseRate; break; default: Logger.Log("Unknown policy type"); break; } }
public void ReturnsSimpleAutoPolicyFromValidJsonString() { var inputJson = @"{ ""type"": ""Auto"", ""make"": ""BMW"" } "; var serializer = new PolicySerializer(); var result = serializer.GetPolicyFromJsonString(inputJson); var policy = new Policy { Type = PolicyType.Auto, Make = "BMW" }; AssertPoliciesEqual(result, policy); }
public void Rate() { Logger.Log("Starting rate."); Logger.Log("Loading policy."); string policyJson = PolicySource.GetPolicyFromSource(); var policy = PolicySerializer.GetPolicyFromJsonString(policyJson); var factory = new RaterFactory(); var rater = factory.Create(policy, this); rater?.Rate(policy); Logger.Log("Rating completed."); }
public void Rate() { Logger.Log("Starting rate."); Logger.Log("Loading policy."); var policyJson = PolicySource.GetPolicyFromSource(); var policy = PolicySerializer.GetPolicyFromJsonString(policyJson); switch (policy.Type) { case PolicyType.Auto: Logger.Log("Rating AUTO policy..."); Logger.Log("Validating policy."); if (string.IsNullOrEmpty(policy.Make)) { Logger.Log("Auto policy must specify make"); return; } if (policy.Make == "BMW") { if (policy.Deductible < 500) { Rating = 1000m; } Rating = 900m; } break; case PolicyType.Land: Logger.Log("Rating LAND policy."); Logger.Log("Validating policy."); if (policy.BondAmount == 0 || policy.Valuation == 0) { Logger.Log("Land policy must specify Bond Amount and Valuation."); return; } if (policy.BondAmount < 0.8m * policy.Valuation) { Logger.Log("Insufficient bond amount"); return; } Rating = policy.BondAmount * 0.05m; break; default: Logger.Log("Unknown policy type."); break; } Logger.Log("Rating completed."); }