Ejemplo n.º 1
0
        public void GetUserOperationInputOnlyAcceptsValidOperations()
        {
            // Arrange
            IGetInput    InputMock  = Substitute.For <IGetInput>();
            IPrintOutput OutputMock = Substitute.For <IPrintOutput>();

            // As the console stays in a loop if an invallid call is received, we are forcing a return with a second valid call
            InputMock.GetUserInput().Returns("hello", "add");

            Target.Input  = InputMock;
            Target.Output = OutputMock;

            // Act
            var result = RunHelper.RunStaticMethod(typeof(CalcConsoleClient), "GetUserOperationInput", null);

            // Assert
            // Failed 4 times, one per invalid input
            OutputMock.Received(1);
            OutputMock.Received().PrintUserOutput("Please Enter a valid operation!");
        }
Ejemplo n.º 2
0
        public void GetUserNumericalInputBlocksExecutionUntilValidValueIsFound()
        {
            // Arrange
            IGetInput    InputMock  = Substitute.For <IGetInput>();
            IPrintOutput OutputMock = Substitute.For <IPrintOutput>();

            // As the console stays in a loop if an invallid call is received, we are forcing a return with a second valid call
            InputMock.GetUserInput().Returns("a", "b", "c", "&", "3");

            Target.Input  = InputMock;
            Target.Output = OutputMock;

            // Act
            var result = RunHelper.RunStaticMethod(typeof(CalcConsoleClient), "GetUserNumericalInput", null);

            // Assert
            // Failed 4 times, one per invalid input
            OutputMock.Received(4);
            OutputMock.Received().PrintUserOutput("Please Enter a valid numerical value!");
        }
Ejemplo n.º 3
0
        public void GetUserNumericalInputPrintsErrorIfIntIsOutOfRange()
        {
            // Arrange
            IGetInput    InputMock  = Substitute.For <IGetInput>();
            IPrintOutput OutputMock = Substitute.For <IPrintOutput>();

            // As the console stays in a loop if an invalid call is received, we are forcing a return with a second valid call
            InputMock.GetUserInput().Returns("2147483999", "4");

            Target.Input  = InputMock;
            Target.Output = OutputMock;

            // Act
            var result = RunHelper.RunStaticMethod(typeof(CalcConsoleClient), "GetUserNumericalInput", null);

            // Assert
            // Failed 4 times, one per invalid input
            OutputMock.Received(1);
            OutputMock.Received().PrintUserOutput("Please Enter a valid numerical value!");
        }
Ejemplo n.º 4
0
        public void GetUserNumericalInputPrintsErrorMessageWhenInputIsOtherThanInteger()
        {
            // Arrange
            IGetInput    InputMock  = Substitute.For <IGetInput>();
            IPrintOutput OutputMock = Substitute.For <IPrintOutput>();

            // As the console stays in a loop if an invallid call is received, we are forcing a return with a second valid call
            InputMock.GetUserInput().Returns("h", "3");

            Target.Input  = InputMock;
            Target.Output = OutputMock;

            // Act
            var result = RunHelper.RunStaticMethod(typeof(CalcConsoleClient), "GetUserNumericalInput", null);

            // Assert
            OutputMock.Received().PrintUserOutput("Please Enter a valid numerical value!");
        }