public TipCalculationResult CalculateTip(TipCalculation data) { var result = new TipCalculationResult(); result.MealTotal = data.MealTotal; result.TipPercent = data.TipPercent; result.TipAmount = result.MealTotal * result.TipPercent; result.TotalAmount = result.TipAmount + result.MealTotal; return result; }
public void CalculateTipTest() { var calculator = new TipCalculator(); var request = new TipCalculation { MealTotal = 100, TipPercent = .1M }; var result = calculator.CalculateTip(request); Assert.AreEqual(result.TipAmount, 10M); Assert.AreEqual(result.TotalAmount, 110M); }
public ActionResult TipCalculator(TipCalculatorRequest request) { if (ModelState.IsValid) { var calc = new TipCalculator(); // convert tip calculator model to tip calculation var tipData = new TipCalculation(); tipData.MealTotal = request.MealTotal.Value; tipData.TipPercent = request.TipPercent.Value / 100; var result = calc.CalculateTip(tipData); return View("TipCalculatorResult", result); } else { return View(request); } }