Esempio n. 1
0
        public JsonResult Calculate()
        {
            WageCalculatorModel model = new WageCalculatorModel();
            string hours = HttpContext.Request["hours"];
            string wage  = HttpContext.Request["wage"];
            string tax   = HttpContext.Request["tax"];

            if (model.validation(hours, wage, tax))
            {
                //string json = "{hours: "+hours+"}";
                //calculations

                //new json string totalHours: xxxx incomeBeforeTax: xxxx IncomeAfterTax: xxxx
                var result = new JObject();

                result["totalHoursTime"]   = model.totalHours(hours);
                result["totalHoursDouble"] = model.parseIntoDouble(model.totalHours(hours));
                result["incomeBeforeTax"]  = model.incomeBeforeTax(wage, hours);
                result["incomeAfterTax"]   = model.incomeAfterTax(wage, hours, tax);

                var serialized = JsonConvert.SerializeObject(result);

                return(Json(serialized, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(JsonConvert.SerializeObject("Bad input"), JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 2
0
        public void IncomeAfterTax()

        {
            // Arrange
            WageCalculatorModel model = new WageCalculatorModel();

            // Act
            String time = "9:00+12:00;8:30+16:00";
            String wage = "100";
            String tax  = "50";

            // Assert
            Assert.AreEqual(model.incomeAfterTax(wage, time, tax), "525");
        }
Esempio n. 3
0
        public void IncomeAfterTaxWithDotSeparated()

        {
            // Arrange
            WageCalculatorModel model = new WageCalculatorModel();

            // Act
            String time = "8:30+19:00";
            String wage = "100,00";
            String tax  = "50.00";

            // Assert
            Assert.AreEqual(model.incomeAfterTax(wage, time, tax), "525");
        }
Esempio n. 4
0
        public void IncomeAfterTaxToFail()

        {
            // Arrange
            WageCalculatorModel model = new WageCalculatorModel();

            // Act
            String time = "8:30+19:00";
            String wage = "100";
            String tax  = "40";

            // Assert
            Assert.AreNotEqual(model.incomeAfterTax(wage, time, tax), "525");
        }
Esempio n. 5
0
        public void Calculate()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act

            WageCalculatorModel model = new WageCalculatorModel();

            var result = new JObject();

            result["totalHoursTime"]   = model.totalHours("9:00+12:00;8:30+16:00");
            result["totalHoursDouble"] = model.parseIntoDouble(model.totalHours("9:00+12:00;8:30+16:00"));
            result["incomeBeforeTax"]  = model.incomeBeforeTax("100", "9:00+12:00;8:30+16:00");
            result["incomeAfterTax"]   = model.incomeAfterTax("100", "9:00+12:00;8:30+16:00", "50");

            var serialized = JsonConvert.SerializeObject(result);

            // Assert

            Assert.AreEqual(serialized, "{\"totalHoursTime\":\"10:30\",\"totalHoursDouble\":10.5,\"incomeBeforeTax\":\"1050\",\"incomeAfterTax\":\"525\"}");
        }