Example #1
0
            public void CorrectlyPrintsCommandsToConsoleAfterAlias()
            {
                // arrange
                var console = new Mock<IConsole>();
                var repl = new Mock<IRepl>();
                var clearCommand = new ClearCommand(console.Object);
                var aliasCommand = new AliasCommand(console.Object);

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

                repl.Setup(x => x.Commands).Returns(commands);
                var cmd = new HelpCommand(console.Object);

                aliasCommand.Execute(repl.Object, new[] { "clear", "clr" });

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

                // assert
                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(":" + aliasCommand.CommandName) && f.Contains(aliasCommand.Description))), Times.Once);
                console.Verify(x => x.WriteLine(It.Is<string>(f => f.StartsWith(":clr") && f.Contains(clearCommand.Description))), Times.Once);
            }
Example #2
0
            public void ShouldReturnAlias()
            {
                // act
                var cmd = new AliasCommand(new Mock<IConsole>().Object);

                // assert
                cmd.CommandName.ShouldEqual("alias");
            }
Example #3
0
            public void ShouldNotThrowAnExceptionWhenAnUnknownCommandIsPassed()
            {
                // arrange
                var command = new AliasCommand(new Mock<IConsole>().Object);

                // act
                var exception = Record.Exception(() => command.Execute(new Mock<IRepl>().Object, null));

                // assert
                exception.ShouldBeNull();
            }
Example #4
0
            public void ShouldAliasCommandWithNewName()
            {
                // arrange
                var currentDir = @"C:\";
                var dummyCommand = new Mock<IReplCommand>();
                dummyCommand.Setup(x => x.CommandName).Returns("foo");

                var fs = new Mock<IFileSystem>();
                fs.Setup(x => x.BinFolder).Returns(Path.Combine(currentDir, "bin"));
                fs.Setup(x => x.DllCacheFolder).Returns(Path.Combine(currentDir, "cache"));

                var console = new Mock<IConsole>();
                var executor = new Repl(null, fs.Object, null, null, null, null, null, new List<IReplCommand> { dummyCommand.Object });

                var cmd = new AliasCommand(console.Object);

                // act
                cmd.Execute(executor, new[] { "foo", "bar" });

                // assert
                executor.Commands.Count.ShouldEqual(2);
                executor.Commands["bar"].ShouldBeSameAs(executor.Commands["foo"]);
            }
Example #5
0
            public void ShouldAliasCommandWithNewName(
                Mock<IFileSystem> fileSystem,
                Mock<IScriptEngine> engine,
                Mock<IObjectSerializer> serializer,
                Mock<ILog> logger,
                Mock<IScriptLibraryComposer> composer,
                Mock<IConsole> console,
                Mock<IFilePreProcessor> filePreProcessor)
            {
                // arrange
                var currentDir = @"C:\";
                var dummyCommand = new Mock<IReplCommand>();
                dummyCommand.Setup(x => x.CommandName).Returns("foo");

                fileSystem.Setup(x => x.BinFolder).Returns(Path.Combine(currentDir, "bin"));
                fileSystem.Setup(x => x.DllCacheFolder).Returns(Path.Combine(currentDir, "cache"));

                var executor = new Repl(
                    new string[0],
                    fileSystem.Object,
                    engine.Object,
                    serializer.Object,
                    logger.Object,
                    composer.Object,
                    console.Object,
                    filePreProcessor.Object,
                    new List<IReplCommand> { dummyCommand.Object });

                var cmd = new AliasCommand(console.Object);

                // act
                cmd.Execute(executor, new[] { "foo", "bar" });

                // assert
                executor.Commands.Count.ShouldEqual(2);
                executor.Commands["bar"].ShouldBeSameAs(executor.Commands["foo"]);
            }