Exemple #1
0
    public async Task As_Interface_With_Incorrect_Command_Type_Returns_None_With_IncorrectCommandTypeMsg()
    {
        // Arrange
        var handler = Substitute.For <CommandHandler <Command> >();
        var command = new IncorrectCommand();

        // Act
        var result = await((ICommandHandler)handler).HandleAsync(command);

        // Assert
        var none = result.AssertNone().AssertType <IncorrectCommandTypeMsg>();

        Assert.Equal(typeof(Command), none.ExpectedType);
        Assert.Equal(typeof(IncorrectCommand), none.ActualType);
    }
        static void Main(string[] args)
        {
            string command;
            var    path  = "";
            var    param = "";

            if (args.Length == 0)
            {
                Utils.PrintAvailableOperations();
                Utils.Output("Enter operation name:", ConsoleColor.Yellow);
                command = Console.ReadLine();
            }
            else
            {
                command = args[0];
                if (args.Length > 1)
                {
                    path = args[1];
                }
                if (args.Length > 2)
                {
                    param = args[2];
                }
            }

            command = command.Trim().Replace("/", "").Replace("-", "");

            if (!CmdCommands.Exists(command))
            {
                Utils.OutputError("Incorrect operation");
                Utils.PrintAvailableOperations();
                return;
            }

            if (path.Length == 0)
            {
                path = Utils.RequestPath(command.Equals(CmdCommands.BrowseFolder) ? "Enter folder path:" : "Enter file name:", !command.Equals(CmdCommands.BrowseFolder));
                if (path.Length == 0)
                {
                    return;
                }
            }

            CommonCommand cmd;

            switch (command)
            {
            case CmdCommands.ReplaceText:
                if (param.Length == 0)
                {
                    Utils.Output("Enter word to replace:", ConsoleColor.Yellow);
                    param = Console.ReadLine();
                }
                cmd = new ReplaceTextCommand(path, param);
                break;

            case CmdCommands.CountWords:
                cmd = new CountWordsCommand(path);
                break;

            case CmdCommands.ReverseWords:
                cmd = new ReverseWordsCommand(path);
                break;

            case CmdCommands.BrowseFolder:
                cmd = new BrowseFolderCommand(path);
                break;

            default:
                cmd = new IncorrectCommand(path);
                break;
            }

            cmd.DoWork();
        }