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()); }
/// <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; } }
public void CalculateTest(string name, Type type) { var calculator = TwoArgumentCalculatorFactory.CreateCalculator(name); Assert.IsInstanceOf(type, calculator); }