Exemple #1
0
        public void SubstracterMustSubstract()
        {
            Substracter theSubstracter = new Substracter(100, 10);

            theSubstracter.Calculate();
            Assert.Equal(90, theSubstracter.Result);
        }
Exemple #2
0
        public ActionResult <Adder> Post([FromBody] CalculatorRequest calculatorRequest)
        {
            CalculatorOperatorBase calculator;

            switch (calculatorRequest.CalculatorOperatorType)
            {
            case CalculatorOperatorTypeEnum.Adder:
            {
                calculator = new Adder(calculatorRequest.LeftVal, calculatorRequest.RightVal);
                break;
            }

            case CalculatorOperatorTypeEnum.Substracter:
            {
                calculator = new Substracter(calculatorRequest.LeftVal, calculatorRequest.RightVal);
                break;
            }

            case CalculatorOperatorTypeEnum.Multiplier:
            {
                calculator = new Multiplier(calculatorRequest.LeftVal, calculatorRequest.RightVal);
                break;
            }

            case CalculatorOperatorTypeEnum.Divider:
            {
                calculator = new Divider(calculatorRequest.LeftVal, calculatorRequest.RightVal);
                break;
            }

            default:
            {
                return(BadRequest("Invalid CalculatorOperatorType"));
            }
            }

            calculator.Calculate();

            var calculatorResponse = new CalculatorResponse
            {
                Result = calculator.Result
            };

            return(Ok(calculatorResponse));
        }