public PartData CalculateLineTotals(PartData line) { var curline = line; var extendedPrice = curline.UnitPrice * curline.Quantity; var totalDiscount = extendedPrice * curline.DiscountPercent; extendedPrice = extendedPrice - totalDiscount; curline.UpfrontAmount = extendedPrice * (curline.UpfrontPercent); curline.FinancedAmount = extendedPrice - curline.UpfrontAmount; return curline; }
public PartData LoadLineData(PartData line) { var curline = line; var part = _partsRepo.GetPartByName(line.PartName); if (curline.UnitPrice == 0) curline.UnitPrice = part.UnitPrice; if (curline.UpfrontPercent == 0) curline.UpfrontPercent = part.UpfrontPercent; curline.DiscountPercent = curline.DiscountPercent / 100; return curline; }
public void Should_be_able_to_load_missing_part_data() { var line = new PartData {PartName = "Basic Microcontroller"}; line = DefaultContext.FinanceTask.LoadLineData(line); Assert.AreEqual(.1M,line.UpfrontPercent); Assert.AreEqual(125M,line.UnitPrice); }
public void Should_calculate_amount_down_after_discount() { var line = new PartData { DiscountPercent = .25M, Quantity = 1, UnitPrice = 100, UpfrontPercent = .1M}; var expectedBalance = 67.5M; var expectedDue = 7.5M; line = DefaultContext.FinanceTask.CalculateLineTotals(line); Assert.AreEqual(expectedBalance, line.FinancedAmount); Assert.AreEqual(expectedDue, line.UpfrontAmount); }
public void Should_be_able_to_calculate_extended_costs() { var line = new PartData { DiscountPercent = .25M, Quantity = 2, UnitPrice = 100 }; var expectedBalance = 150M; line = DefaultContext.FinanceTask.CalculateLineTotals(line); Assert.AreEqual(expectedBalance, line.FinancedAmount); }