public void TestAllLogic_ShouldReturnAllResults()
        {
            int     number1      = 6;
            int     number2      = 3;
            Numbers requestAdd   = new Numbers(number1, number2, "Add");
            Numbers requestSub   = new Numbers(number1, number2, "Subtract");
            Numbers requestMulty = new Numbers(number1, number2, "Multypile");
            Numbers requestDiv   = new Numbers(number1, number2, "Divide");

            int AddResult       = _chain.Calculate(requestAdd);
            int SubstractResult = _chain.Calculate(requestSub);
            int MultyResult     = _chain.Calculate(requestMulty);
            int DivResult       = _chain.Calculate(requestDiv);

            Assert.AreEqual(9, AddResult);
            Assert.AreEqual(3, SubstractResult);
            Assert.AreEqual(18, MultyResult);
            Assert.AreEqual(2, DivResult);
        }
Esempio n. 2
0
 public double?Calculate(Command command)
 {
     if (command.Operation == "+")
     {
         return(command.Number1 + command.Number2);
     }
     else
     {
         return(_next?.Calculate(command));
     }
 }
Esempio n. 3
0
 public double Calculate(Numbers request)
 {
     if (request.Operation.ToLower().Equals("multiply"))
     {
         return(request.Number1 * request.Number2);
     }
     else
     {
         return(_nextInChain.Calculate(request));
     }
 }
Esempio n. 4
0
 public void Calculate(Number number)
 {
     if (number.CalcWanted == "Add")
     {
         Console.WriteLine("ADD");
     }
     else
     {
         _nextChain.Calculate(number);
     }
 }
Esempio n. 5
0
 public double?Calculate(Command command)
 {
     if (command.Operation == "**")
     {
         return(Math.Pow(command.Number1, command.Number2));
     }
     else
     {
         return(_next?.Calculate(command));
     }
 }
Esempio n. 6
0
        public void Calculate(Numbers numbers)
        {
            if (numbers.Action.Equals("mult"))
            {
                int result = numbers.Number1 * numbers.Number2;

                Console.WriteLine($"{numbers.Number1} * {numbers.Number2} = {result}");
            }
            else
            {
                _nextChain.Calculate(numbers);
            }
        }
Esempio n. 7
0
 public int Calculate(Numbers request)
 {
     if (CanDo(request))
     {
         return(InnerCalculate(request));
     }
     else if (_nextChain != null)
     {
         return(_nextChain.Calculate(request));
     }
     else
     {
         throw new MatchingLogicNotFoundException();
     }
 }