Exemplo n.º 1
0
        public ActionResult Index(double firstArgument, double secondArgument, string operation)
        {
            ITwoArgumentCalculator calculator = TwoArgumentsFactory.CreateCalculator(operation);
            double result = calculator.Calculate(firstArgument, secondArgument);

            ViewBag.Result    = result;
            ViewBag.Operation = new SelectListItem[]
            {
                new SelectListItem()
                {
                    Value = "multyplication", Text = "Multi"
                },
                new SelectListItem()
                {
                    Value = "addition", Text = "Plus"
                },
                new SelectListItem()
                {
                    Value = "sabtraction", Text = "Minus"
                },
                new SelectListItem()
                {
                    Value = "division", Text = "Div"
                }
            };
            return(View());
        }
Exemplo n.º 2
0
        public ActionResult Index(double firstArgument, double secondArgument, string operation)
        {
            ViewBag.operations = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text  = "*",
                    Value = "multiplication"
                },
                new SelectListItem
                {
                    Text  = "/",
                    Value = "division"
                },
                new SelectListItem
                {
                    Text  = "+",
                    Value = "addition"
                },
                new SelectListItem
                {
                    Text  = "-",
                    Value = "subsraction"
                }
            };

            ITwoArgumentCalculator calculator = TwoArgumentCalculatorFactory.CreateCalculator(operation);
            double resultValue = calculator.Calculate(firstArgument, secondArgument);

            ViewBag.Result = resultValue;
            return(View());
        }
Exemplo n.º 3
0
 private void ClickMain(object sender, EventArgs e)
 {
     try
     {
         string firstValueText             = textBox1.Text;
         double firstValue                 = Convert.ToDouble(firstValueText);
         string secondValueText            = textBox3.Text;
         double secondValue                = Convert.ToDouble(secondValueText);
         ITwoArgumentCalculator calculator = TwoTwoArgumentsFactory.CreateCalculator(((Button)sender).Name);
         double result = calculator.Calculate(firstValue, secondValue);
         textBox2.Text = result.ToString();
     }
     catch (Exception TwoArgumentsException)
     {
         MessageBox.Show("Неверное выражение" + TwoArgumentsException);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// method for processing button clicks for two argument operations
 /// </summary>
 private void OpertionForTwoArgument(object sender, EventArgs e)
 {
     try
     {
         double firstNumber   = Convert.ToDouble(firstArgument.Text);
         double secondNumber  = Convert.ToDouble(secondArgument.Text);
         string operationName = ((Button)sender).Name;
         ITwoArgumentCalculator calculator = TwoArgumentCalculatorFactory.CreateCalculator(operationName);
         double resultValue = calculator.Calculate(firstNumber, secondNumber);
         result.Text = Convert.ToString(resultValue);
     }
     catch (FormatException exc)
     {
         result.Text = "Введите число";
     }
     catch (Exception exc)
     {
         result.Text = exc.Message;
     }
 }
Exemplo n.º 5
0
        public void CalculateDivTestException()
        {
            ITwoArgumentCalculator calculator = TwoArgumentsFactory.CreateCalculator("division");

            Assert.Throws <Exception>(() => calculator.Calculate(7, 0));
        }
Exemplo n.º 6
0
        public void CalculateDelTestStrongExpection()
        {
            ITwoArgumentCalculator calculator = TwoTwoArgumentsFactory.CreateCalculator("delSolution");

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