public void Calculate_ShouldDetectInvalidInputs()
        {
            // Arrange
            ValuesController controller = new ValuesController();
            int    a  = -10;
            int    b  = 10;
            string op = "-";
            // Act
            int result   = controller.Calculate(a, b, op);
            int expected = 0;

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void Calculate_ShouldDetectWrongOperand()
        {
            // Arrange
            ValuesController controller = new ValuesController();
            int    a  = 39;
            int    b  = 10;
            string op = "*";
            // Act
            int result   = controller.Calculate(a, b, op);
            int expected = 0;

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void Calculate_ShouldAddTwoNumbers()
        {
            // Arrange
            ValuesController controller = new ValuesController();
            int    a  = 2;
            int    b  = 10;
            string op = "+";
            // Act
            int result   = controller.Calculate(a, b, op);
            int expected = a + b;

            // Assert
            Assert.AreEqual(expected, result);
        }
Esempio n. 4
0
        public void Return_BadRequestForInvalidSyntaxApi()
        {
            ValuesController controller = new ValuesController
            {
                Request = new HttpRequestMessage()
                {
                    Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }
                }
            };
            var response = controller.Calculate(new Models.CalcModel
            {
                expression = "3+"
            });

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 5
0
        public void CalculateSumOnApi()
        {
            ValuesController controller = new ValuesController
            {
                Request = new HttpRequestMessage()
                {
                    Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } }
                }
            };
            var response = controller.Calculate(new Models.CalcModel
            {
                expression = "3+5"
            });

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }