コード例 #1
0
        public void Main_WithTwoValidCommands_ExitsProgramWhenEmptyStringIsEntered()
        {
            // Arrange
            Mock <IStringCalculator> mockCalculator = new Mock <IStringCalculator>();
            Mock <IConsole>          mockConsole    = new Mock <IConsole>();

            mockCalculator.Setup(c => c.Add("1,2,3")).Returns(6);
            mockCalculator.Setup(c => c.Add("3")).Returns(3);
            mockCalculator.Setup(c => c.Add("5")).Returns(5);

            mockConsole.SetupSequence(c => c.ReadLine())
            .Returns("3")
            .Returns("5")
            .Returns("");

            StringCalculatorConsole1 stringCalculatorConsole = CreateCalcConsole(mockCalculator, mockConsole);

            // Act
            stringCalculatorConsole.Main(new string[] { "scalc '1,2,3'" });

            // Assert
            mockConsole.Verify(c => c.WriteLine("The result is 6"));
            mockConsole.Verify(c => c.WriteLine("another input please"), Times.Exactly(3));
            mockConsole.Verify(c => c.WriteLine("The result is 3"));
            mockConsole.Verify(c => c.WriteLine("The result is 5"));
            mockConsole.Verify(c => c.ReadLine(), Times.Exactly(3));
        }
コード例 #2
0
        private void VerifyConsoleOutput(string input, string consoleOutput, Mock <IStringCalculator> mockCalculator)
        {
            // Arrange
            Mock <IConsole>          mockConsole = new Mock <IConsole>();
            StringCalculatorConsole1 scConsole   = CreateCalcConsole(mockCalculator, mockConsole);

            // Act
            scConsole.Main(new string[] { input });

            // Assert
            mockConsole.Verify(c => c.WriteLine(consoleOutput));
        }
コード例 #3
0
        public void Main_WithInvalidCommand_DisplaysNothingToTheConsole()
        {
            // Arrange
            Mock <IConsole>          mockConsole = new Mock <IConsole>();
            StringCalculatorConsole1 scConsole   = CreateCalcConsole(mockConsole);


            // Act
            scConsole.Main(new string[] { "1,2,3" });

            // Assert
            mockConsole.Verify(c => c.WriteLine(It.IsAny <string>()), Times.Never());
        }
コード例 #4
0
        public void Main_WithAValidCommand_PromptsForAnotherNumber()
        {
            // Arrange
            Mock <IStringCalculator> mockCalculator = new Mock <IStringCalculator>();
            Mock <IConsole>          mockConsole    = new Mock <IConsole>();

            mockCalculator.Setup(c => c.Add("1,2,3")).Returns(6);
            StringCalculatorConsole1 stringCalculatorConsole = CreateCalcConsole(mockCalculator, mockConsole);

            // Act
            stringCalculatorConsole.Main(new string[] { "scalc '1,2,3'" });

            // Assert
            mockConsole.Verify(c => c.WriteLine("The result is 6"));
            mockConsole.Verify(c => c.WriteLine("another input please"));
            mockConsole.Verify(c => c.ReadLine(), Times.Once());
        }