Ejemplo n.º 1
0
        public void ExecuteAsync_KnownEndpointWithRequestMethods_NoWarning()
        {
            ChangeDirectoryCommand command = new ChangeDirectoryCommand();

            Setup(commandText: "cd AnEndpoint", out MockedShellState mockedShellState, out HttpState httpState, out ICoreParseResult parseResult);

            DirectoryStructure directoryStructure = new DirectoryStructure(null);
            DirectoryStructure childDirectory     = directoryStructure.DeclareDirectory("AnEndpoint");
            RequestInfo        childRequestInfo   = new RequestInfo();

            childRequestInfo.AddMethod("GET");
            childDirectory.RequestInfo = childRequestInfo;
            ApiDefinition apiDefinition = new ApiDefinition()
            {
                DirectoryStructure = directoryStructure
            };

            httpState.ApiDefinition = apiDefinition;

            string expectedOutput = "/AnEndpoint    [GET]";

            command.ExecuteAsync(mockedShellState, httpState, parseResult, CancellationToken.None);

            Assert.Single(mockedShellState.Output);
            Assert.Equal(expectedOutput, mockedShellState.Output[0]);
        }
        public void AssignmentTest()
        {
            ICommand command = new ChangeDirectoryCommand();

            Assert.AreEqual(command.FullName, "ChangeDirectory");
            Assert.AreEqual(command.ShortName, "cd");
        }
        public void ExecuteAbsolutePathTest()
        {
            var      initualDir   = Directory.GetCurrentDirectory();
            ICommand command      = new ChangeDirectoryCommand();
            var      newDirectory = Directory.GetParent(initualDir);
            string   newDirectoryPath;

            if (newDirectory == null)
            {
                newDirectoryPath = Directory.GetCurrentDirectory();
            }
            else
            {
                newDirectoryPath = newDirectory.FullName;
            }

            var arguments = new List <string>()
            {
                newDirectoryPath
            };

            command.Execute(arguments);

            Assert.AreEqual(newDirectoryPath, Directory.GetCurrentDirectory());
            Directory.SetCurrentDirectory(initualDir);
        }
        public void ExecuteInvalidArgumentsTest()
        {
            ICommand command          = new ChangeDirectoryCommand();
            string   newDirectoryPath = "Invalid arguments";
            var      commandResult    = command.Execute(null);

            Assert.IsNotNull(commandResult);
            Assert.IsTrue(commandResult.Count() == 1);
            Assert.AreEqual(newDirectoryPath, commandResult.First());
        }
        public void ExecuteChangeDriveTest()
        {
            var      initualDir       = Directory.GetCurrentDirectory();
            ICommand command          = new ChangeDirectoryCommand();
            string   newDirectoryPath = DriveInfo.GetDrives().First().Name;
            var      arguments        = new List <string>()
            {
                newDirectoryPath
            };

            command.Execute(arguments);
            Assert.AreEqual(newDirectoryPath, Directory.GetCurrentDirectory());
            Directory.SetCurrentDirectory(initualDir);
        }
Ejemplo n.º 6
0
        private void ExecuteOpenWithExplorerCommand()
        {
            switch (CurrentRow.Type)
            {
            case ItemType.Directory:
            case ItemType.File:
                Process.Start(CurrentRow.Path);
                break;

            case ItemType.Link:
                ChangeDirectoryCommand.Execute(null);
                break;
            }
        }
Ejemplo n.º 7
0
        public void ExecuteAsync_UnknownEndpoint_DisplaysWarning()
        {
            ChangeDirectoryCommand command = new ChangeDirectoryCommand();

            Setup(commandText: "cd NotAnEndpoint", out MockedShellState mockedShellState, out HttpState httpState, out ICoreParseResult parseResult);

            httpState.Structure = new DirectoryStructure(null);

            string expectedFirstLine  = string.Format(Resources.Strings.ChangeDirectoryCommand_Warning_UnknownEndpoint, "/NotAnEndpoint").SetColor(httpState.WarningColor);
            string expectedSecondLine = "/NotAnEndpoint    []";

            command.ExecuteAsync(mockedShellState, httpState, parseResult, CancellationToken.None);

            Assert.Equal(2, mockedShellState.Output.Count);
            Assert.Equal(expectedFirstLine, mockedShellState.Output[0]);
            Assert.Equal(expectedSecondLine, mockedShellState.Output[1]);
        }
Ejemplo n.º 8
0
        public void ExecuteAsync_KnownEndpointWithSubdirectory_NoWarning()
        {
            ChangeDirectoryCommand command = new ChangeDirectoryCommand();

            Setup(commandText: "cd AnEndpoint", out MockedShellState mockedShellState, out HttpState httpState, out ICoreParseResult parseResult);

            DirectoryStructure directoryStructure  = new DirectoryStructure(null);
            DirectoryStructure childDirectory      = directoryStructure.DeclareDirectory("AnEndpoint");
            DirectoryStructure grandchildDirectory = childDirectory.DeclareDirectory("AnotherEndpoint");

            httpState.Structure = directoryStructure;

            string expectedOutput = "/AnEndpoint    []";

            command.ExecuteAsync(mockedShellState, httpState, parseResult, CancellationToken.None);

            Assert.Single(mockedShellState.Output);
            Assert.Equal(expectedOutput, mockedShellState.Output[0]);
        }
        public void ExecuteMoveToTheSpecifiedDirectory()
        {
            var      initualDir = Directory.GetCurrentDirectory();
            ICommand command    = new ChangeDirectoryCommand();
            var      arguments  = new List <string>()
            {
                ".."
            };
            var newDirectoryPath = Directory.GetCurrentDirectory();
            var newDirectory     = newDirectoryPath.Split('\\').Last();

            command.Execute(arguments);

            arguments = new List <string>()
            {
                newDirectory
            };
            command.Execute(arguments);

            Assert.AreEqual(newDirectoryPath, Directory.GetCurrentDirectory());
            Directory.SetCurrentDirectory(initualDir);
        }
Ejemplo n.º 10
0
        public IList <string> InitializeCommandState(
            CommandState commandState,
            TerminalState terminalState,
            FileSystemState fileSystemState,
            DirectoryController directoryController)
        {
            var commandsInitialized = new List <string>();

            var helpCommand         = new HelpCommand(commandState);
            var isAddCommandSuccess = commandState.TryAddAvailableCommand(helpCommand.GetCommandName(), helpCommand);

            Debug.Assert(isAddCommandSuccess, "Failed to add `help` command to available command state");
            commandsInitialized.Add(helpCommand.GetCommandName());

            var clearCommand = new ClearCommand(terminalState);

            isAddCommandSuccess = commandState.TryAddAvailableCommand(clearCommand.GetCommandName(), clearCommand);

            Debug.Assert(isAddCommandSuccess, "Failed to add `clear` command to available command state");
            commandsInitialized.Add(clearCommand.GetCommandName());

            var listCommand = new ListCommand(fileSystemState, directoryController);

            isAddCommandSuccess = commandState.TryAddAvailableCommand(listCommand.GetCommandName(), listCommand);

            Debug.Assert(isAddCommandSuccess, "Failed to add `ls` command to available command state");
            commandsInitialized.Add(listCommand.GetCommandName());

            var changeDirectoryCommand = new ChangeDirectoryCommand(fileSystemState, directoryController);

            isAddCommandSuccess = commandState.TryAddAvailableCommand(changeDirectoryCommand.GetCommandName(), changeDirectoryCommand);

            Debug.Assert(isAddCommandSuccess, "Failed to add `cd` command to available command state");
            commandsInitialized.Add(changeDirectoryCommand.GetCommandName());

            return(commandsInitialized);
        }