Exemplo n.º 1
0
        public void CalculateTipTest()
        {
            var calculator = new TipCalculator();
            var request = new TipCalculationRequest {MealCost = 100, TipPercent = .2M};
            var result = calculator.CalculateTip(request);

            Assert.AreEqual(result.TipAmount, 20M);
            Assert.AreEqual(result.TotalCost, 120M);
        }
Exemplo n.º 2
0
        public TipCalculationResponse CalculateTip(TipCalculationRequest request)
        {
            var response = new TipCalculationResponse();
              response.TipPercent = request.TipPercent;
              response.MealCost = request.MealCost;
              response.TipAmount = response.TipPercent*response.MealCost;
              response.TotalCost = response.MealCost + response.TipAmount;

              response.TipAmount = Math.Round(response.TipAmount, 2); //limits response to two decimal places for currency
              response.TotalCost = Math.Round(response.TotalCost, 2);
              return response;
        }
Exemplo n.º 3
0
        public ActionResult TipCalculator(TipCalculatorRequest request)
        {
            if (ModelState.IsValid)
            {
                var calc = new TipCalculator();

                var tipData = new MVCappLabs.Models.Level1.TipCalculationRequest();
                tipData.MealCost   = request.MealCost.Value;
                tipData.TipPercent = request.TipPercent.Value / 100;

                var response = calc.CalculateTip(tipData);

                return(View("TipCalculatorResponse", response));
            }
            return(View("TipCalculator"));
        }
Exemplo n.º 4
0
        public ActionResult TipCalculator(TipCalculatorRequest request)
        {
            if (ModelState.IsValid)
            {

                var calc = new TipCalculator();

                var tipData = new MVCappLabs.Models.Level1.TipCalculationRequest();
                tipData.MealCost = request.MealCost.Value;
                tipData.TipPercent = request.TipPercent.Value / 100;

                var response = calc.CalculateTip(tipData);

                return View("TipCalculatorResponse", response);

            }
            return View("TipCalculator");
        }