public void TestAddingTwoPositiveNumbers()
        {
            decimal leftNumber  = 1M;
            decimal rightNumber = 2M;
            decimal expected    = leftNumber + rightNumber;

            decimal actual = calculator.Add(leftNumber, rightNumber);

            Assert.AreEqual(expected, actual);
        }
 public decimal Get([FromQuery] decimal leftNumber, [FromQuery] decimal rightNumber)
 {
     return(calculator.Add(leftNumber, rightNumber));
 }
Exemplo n.º 3
0
    protected void ProcessOperator(string curOperator)
    {
        //this method is the heart of the operation
        //it gets the operator
        string op = curOperator;

        //first it tests to see if it is a valid numerical entry
        //by checking to see if the ParseTextEntry() method returns
        //a true or a false
        //if false than it launches a javascript alert
        if (!ParseTextEntry())
        {
            Response.Write("<script type='Text/JavaScript'>alert('Enter only valid Numbers')</script>");


            return;
        }
        //if it is good it writes the current operator
        //to the operator session
        Session["operator"] = op;

        //next it checks whether there is anything in
        //the answr session
        //if there is it determins the operator
        //and calls the appropriate method
        //from the SimpleCalc class
        if (Session["answr"] != null)
        {
            number1          = (double)Session["answr"];
            Session["answr"] = null;
            switch (op)
            {
            case "+":
                answer = calc.Add(number1, number2);
                break;

            case "-":
                answer = calc.Subtract(number1, number2);
                break;

            case "*":
                answer = calc.Multiply(number1, number2);
                break;

            case "/":
                answer = calc.Divide(number1, number2);
                break;

            default:
                Response.Write("<script type='Text/JavaScript'>alert('Invalid Operator')</script>");
                break;
            }
            //it writes the answer to the textbox
            txtEntry.Text = answer.ToString();
            //and clears the session
            Session["answr"] = null;
        }
        else
        {
            //otherwise it writes the number from the textbox
            //to the session variable
            Session["answr"] = number2;
        }
    }