Example #1
0
        public ActionResult Index(double firstArgument, double secondArgument, string operation)
        {
            ICalculatorTwoArguments calculator = CalculateTwoFactory.CreateCalculator(operation);
            double result = calculator.Calculate(firstArgument, secondArgument);

            ViewBag.Result    = result;
            ViewBag.Operation = new SelectListItem[]
            {
                new SelectListItem()
                {
                    Value = "Multiply", Text = "Multiply"
                },
                new SelectListItem()
                {
                    Value = "Addition", Text = "Addition"
                },
                new SelectListItem()
                {
                    Value = "Subtraction", Text = "Subtraction"
                },
                new SelectListItem()
                {
                    Value = "Division", Text = "Division"
                }
            };
            return(View());
        }
Example #2
0
 private void operations(object sender, EventArgs e)
 {
     try
     {
         string firstArgumentText           = textBox1.Text;
         double firstArgument               = Convert.ToDouble(firstArgumentText);
         string secondArgumentText          = textBox2.Text;
         double secondArgument              = Convert.ToDouble(secondArgumentText);
         string operation                   = ((Button)sender).Name;
         ICalculatorTwoArguments calculator = CalculateTwoFactory.CreateCalculator(operation);
         double result = calculator.Calculate(firstArgument, secondArgument);
         textBox3.Text = result.ToString();
     }
     catch (Exception exc)
     {
         textBox3.Text = exc.Message;
     }
 }
        public void DivisionExeptionTest()
        {
            ICalculatorTwoArguments calculator = CalculateTwoFactory.CreateCalculator("Division");

            Assert.Throws <Exception>(() => calculator.Calculate(5, 0));
        }
        public void CalculateTest(string name, Type type)
        {
            var calculator = CalculateTwoFactory.CreateCalculator(name);

            Assert.IsInstanceOf(type, calculator);
        }