public FloorCalculation CalculateFloor(FloorCalculation fc) { fc.Area = fc.Width*fc.Length; fc.FlooringCost = fc.Area*fc.CostPerUnit; fc.LaborCost = Math.Ceiling(fc.Area / 5) * 21.50M; fc.TotalCostEstimate = fc.LaborCost + fc.FlooringCost; return fc; }
public void CalculateFlooring() { var calculator = new FlooringCalculator(); var calculation = new FloorCalculation{Length = 10, Width = 10, CostPerUnit = 2}; var result = calculator.CalculateFloor(calculation); Assert.AreEqual(result.Area, 100); Assert.AreEqual(result.FlooringCost, 200); Assert.AreEqual(result.TotalCostEstimate,630 ); }
public ActionResult FlooringCalculator(FloorInputs inputs) { if (ModelState.IsValid) { var calc = new FlooringCalculator(); var floorData = new FloorCalculation(); floorData.Width = inputs.Width.Value; //what does .Value do here? allows nullabe decimal to convert to target type decimal? floorData.Length = inputs.Length.Value; floorData.CostPerUnit = inputs.CostPerUnit.Value; var result = calc.CalculateFloor(floorData); inputs.FlooringCost = result.FlooringCost; inputs.Area = result.Area; inputs.LaborCost = result.LaborCost; inputs.TotalCostEstimate = result.TotalCostEstimate; return View("FlooringCalculator", inputs); } else { return View("FlooringCalculator"); } }