Inheritance: IReplCommand
Exemplo n.º 1
0
            public void PrintsCommandsToConsole()
            {
                // arrange
                var console = new Mock<IConsole>();
                var repl = new Mock<IRepl>();
                var clearCommand = new ClearCommand(console.Object);
                var exitCommand = new ExitCommand(console.Object);

                var commands = new Dictionary<string, IReplCommand>
                {
                    {clearCommand.CommandName, clearCommand},
                    {exitCommand.CommandName, exitCommand},
                };

                repl.Setup(x => x.Commands).Returns(commands);

                var cmd = new HelpCommand(console.Object);

                // act
                cmd.Execute(repl.Object, null);

                // assert
                console.Verify(x => x.WriteLine(It.IsAny<string>()), Times.Exactly(3));
                console.Verify(x => x.WriteLine(It.Is<string>(f => f.StartsWith(":" + clearCommand.CommandName) && f.Contains(clearCommand.Description))), Times.Once);
                console.Verify(x => x.WriteLine(It.Is<string>(f => f.StartsWith(":" + exitCommand.CommandName) && f.Contains(exitCommand.Description))), Times.Once);
            }
Exemplo n.º 2
0
            public void ReturnsExit()
            {
                // act
                var cmd = new ExitCommand(new Mock<IConsole>().Object);

                // assert
                Assert.Equal("exit", cmd.CommandName);
            }
Exemplo n.º 3
0
            public void PromptsUserBeforeExiting()
            {
                // arrange
                var console = new Mock<IConsole>();
                console.Setup(x => x.ReadLine(message)).Returns("n");
                var executor = new Mock<IRepl>();
                var cmd = new ExitCommand(console.Object);

                // act
                cmd.Execute(executor.Object, null);

                // assert
                console.Verify(x => x.ReadLine(message));
            }
Exemplo n.º 4
0
            public void ExitsWhenUserAnswersYes()
            {
                // arrange
                var console = new Mock<IConsole>();
                console.Setup(x => x.ReadLine(message)).Returns("y");

                var executor = new Mock<IRepl>();
                var cmd = new ExitCommand(console.Object);

                // act
                cmd.Execute(executor.Object, null);

                // assert
                executor.Verify(x => x.Terminate());
            }
Exemplo n.º 5
0
            public void DoesNotExitWhenUserAnswersNo()
            {
                // arrange
                var console = new Mock<IConsole>();
                console.Setup(x => x.ReadLine()).Returns("n");

                var executor = new Mock<IRepl>();
                var cmd = new ExitCommand(console.Object);

                // act
                cmd.Execute(executor.Object, null);

                // assert
                executor.Verify(x => x.Terminate(), Times.Never);
            }
Exemplo n.º 6
0
            public void PromptsUserBeforeExiting()
            {
                // arrange
                const string message = "Are you sure you wish to exit? (y/n): ";
                var console = new Mock<IConsole>();
                console.Setup(x => x.ReadLine()).Returns("n");
                var executor = new Mock<IRepl>();
                var cmd = new ExitCommand(console.Object);

                // act
                cmd.Execute(executor.Object, null);

                // assert
                console.Verify(x => x.Write(message));
            }