Beispiel #1
0
        public ActionResult Index(double firstNumber, double secondNumber, string operation)
        {
            ITwoArgumentsCalculator calculator = TwoArgumentsFactory.CreateCalculate(operation);
            double result = calculator.Calculate(firstNumber, secondNumber);

            ViewBag.Result    = result;
            ViewBag.Operation = new SelectListItem[]
            {
                new SelectListItem()
                {
                    Value = "multiply", Text = "multiply"
                },
                new SelectListItem()
                {
                    Value = "sum", Text = "sum"
                },
                new SelectListItem()
                {
                    Value = "minus", Text = "minus"
                },
                new SelectListItem()
                {
                    Value = "division", Text = "division"
                }
            };
            return(View());
        }
Beispiel #2
0
 private void button4_Click_1(object sender, EventArgs e)
 {
     try
     {
         string firstArgumentString         = textBoxFirstIn.Text;
         double firstArgument               = Convert.ToDouble(firstArgumentString);
         string secondArgumentString        = textBoxSecondIn.Text;
         double secondArgument              = Convert.ToDouble(secondArgumentString);
         ITwoArgumentsCalculator calculator = TwoArgumentsFactory.CreateCalculate(((Button)sender).Name);
         double result = calculator.Calculate(firstArgument, secondArgument);
         textBoxOut.Text = result.ToString();
     }
     catch (Exception two)
     {
         textBoxOut.Text = two.Message;
     }
 }
        public void CalculateTest(string name, Type type)
        {
            var calculator = TwoArgumentsFactory.CreateCalculate(name);

            Assert.IsInstanceOf(type, calculator);
        }
Beispiel #4
0
        public void CalculateTest()
        {
            ITwoArgumentsCalculator calculator = TwoArgumentsFactory.CreateCalculate("division");

            Assert.Throws <Exception>(() => calculator.Calculate(2, 0));
        }