public ActionResult Index(double firstNumber, double secondNumber, string operation) { ITwoArgumentsCalculator calculator = TwoArgumentFactory.createCalculate(operation); double result = calculator.Calculate(firstNumber, secondNumber); ViewBag.Result = result; ViewBag.Operation = new SelectListItem[] { new SelectListItem() { Value = "Multiply", Text = "Multiply" }, new SelectListItem() { Value = "Add", Text = "Plus" }, new SelectListItem() { Value = "Substract", Text = "Minus" }, new SelectListItem() { Value = "Divide", Text = "Divide" } }; return(View()); }
private void ButtonClick(object sender, EventArgs e) { string firstValueText = TextBox1.Text; double firstValue = Convert.ToDouble(firstValueText); string secondValueText = textBox2.Text; double secondValue = Convert.ToDouble(secondValueText); string operation = ((Button)sender).Name; ITwoArgumentsCalculate calculator = TwoArgumentFactory.CreateCalculator(operation); double result = calculator.Calculate(firstValue, secondValue); label1.Text = result.ToString(); }
private void Click(object sender, EventArgs e) { string Transmission = ((Button)sender).Name; string firstValueText = textBox3.Text; double firstValue = Convert.ToDouble(firstValueText); string secondValueText = textBox4.Text; double secondValue = Convert.ToDouble(secondValueText); ITwoArgumentsCalculator calculator = TwoArgumentFactory.createCalculate(Transmission); double result = calculator.Calculate(firstValue, secondValue); textBox5.Text = result.ToString(); }
private void TwoArgumentFunction(object sender, EventArgs e) { try { double firstArgument = Convert.ToDouble(argument_1.Text); double secondArgument = Convert.ToDouble(argument_2.Text); ITwoArgumentsCalculator calculator = TwoArgumentFactory.CreateCalculator(((Button)sender).Name); double result = calculator.Calculate(firstArgument, secondArgument); TotalResult.Text = result.ToString(); } catch (Exception exc) { TotalResult.Text = exc.Message; } }
/// <summary> /// Function for calculatin with two arguments /// </summary> /// <param name="sender">Button that activated event</param> /// <param name="e">Name of operation</param> private void CalculateTwoArgument(object sender, EventArgs e) { try { double firstArgument = Validation.StringToDouble(FirstArgument.Text); double secondArgument = Validation.StringToDouble(SecondArgument.Text); string operation = (((Button)sender).Name); var op = TwoArgumentFactory.CreateCalculator(operation); double result = op.Calculate(firstArgument, secondArgument); Result.Text = Convert.ToString(result); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK); } }
/// <summary> /// Function for operations with two numbers /// </summary> /// <param name="sender">Button, that activated ivent</param> /// <param name="e">Operation type</param> private void Calculator(object sender, EventArgs e) { try { var validator = new Validator(); double firstArgument = validator.ValidateNumber(FirstInput.Text); double secondArgument = validator.ValidateNumber(SecondInput.Text); string operationName = (((Button)sender).Name); var operation = TwoArgumentFactory.CreateCalculator(operationName); double result = operation.Calculate(firstArgument, secondArgument); Value.Text = Convert.ToString(result); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK); } }
public void CalculateTest(string name, Type type) { var calculator = TwoArgumentFactory.createCalculate(name); Assert.IsInstanceOf(type, calculator); }
public void CalculateDivide2() { ITwoArgumentsCalculate calculator = TwoArgumentFactory.CreateCalculator("Divide"); Assert.Throws <Exception>(() => calculator.Calculate(7, 0)); }
public void MyCalculateTest() { ITwoArgumentsCalculator calculator = TwoArgumentFactory.createCalculate("Divide"); Assert.Throws <Exception>(() => calculator.Calculate(5, 0)); }
public void FactoryTest(Type type, string name) { Type resultType = TwoArgumentFactory.CreateCalculator(name).GetType(); Assert.AreEqual(type, resultType); }
public void MyCalculateTest3() { ITwoArgumentsCalculator calculator = TwoArgumentFactory.createCalculate("Logxy"); Assert.Throws <Exception>(() => calculator.Calculate(2, -9)); }
public void CreateCalculator(Type expectedTypeOfOperation, string nameOfOperation) { Type resultType = TwoArgumentFactory.CreateCalculator(nameOfOperation).GetType(); Assert.AreEqual(expectedTypeOfOperation, resultType); }