Exemple #1
0
        public void ParseEmptyCommandLine()
        {
            string[]           args   = { };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.AreEqual(0, result.ExitCode);
            Assert.AreEqual(0, result.CommandsToExecute.Count);

            AssertOutputIs(@"Unit test console

USAGE: unittest.exe <command> {<parameters>}

COMMANDS:
   cmd1 - performs action 1
   something to be used
   bla bla
   help - displays the command line help
   test - dummy command used for unit testing
      USAGE:
      test <arg1> [<Arg2>] [settings]

      PARAMETERS:
      arg1: a string argument
      Arg2: an int argument
      -setting1=value: an int setting (alias: s1)
      -Setting2=value: a string setting
      -switch1[=true/false]: a switch (alias: sw1)

");
            AssertErrOutputIs(string.Empty);
        }
Exemple #2
0
        public void ParseConsoleCommandSuccessfully()
        {
            string[]           args   = { "cmd1", "positional1", "-switch=true" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.IsNull(result.ExitCode);
            Assert.AreEqual(1, result.CommandsToExecute.Count);
            Assert.AreEqual("cmd1", result.CommandsToExecute[0].CommandId);
        }
Exemple #3
0
        public void RequiredArgIsMissing()
        {
            string[]           args   = { "test", "-setting1=123" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.AreEqual(2, result.ExitCode);
            AssertErrOutputIs(@"Required argument arg1 is missing
");
        }
Exemple #4
0
        public void SwitchArgumentValueIsInvalid()
        {
            string[]           args   = { "test", "value1", "-switch1=xyz" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.AreEqual(2, result.ExitCode);
            AssertErrOutputIs(@"Switch 'switch1' has an invalid value ('xyz') - it should either be empty, 'true' or 'false'
");
        }
Exemple #5
0
        public void SettingArgumentValueIsMissing()
        {
            string[]           args   = { "test", "value1", "-setting1" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.AreEqual(2, result.ExitCode);
            AssertErrOutputIs(@"Setting 'setting1' is missing the value
");
        }
Exemple #6
0
        public void SettingArgumentValueIsInvalid()
        {
            string[]           args   = { "test", "value1", "-setting1=xyz" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.AreEqual(2, result.ExitCode);
            AssertErrOutputIs(@"Setting 'setting1' has an invalid value ('xyz') - it should be an integer
");
        }
Exemple #7
0
        public void UnknownSetting()
        {
            string[]           args   = { "test", "value1", "-dont=true" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.AreEqual(2, result.ExitCode);
            AssertErrOutputIs(@"Unknown setting 'dont' specified
");
        }
Exemple #8
0
        public void SwitchArgWithValue()
        {
            string[]           args   = { "test", "value1", "-switch1=true" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.IsNull(result.ExitCode);
            TestStandardConsoleCommand parsedCmd = (TestStandardConsoleCommand)result.CommandsToExecute[0];

            Assert.IsTrue(parsedCmd.Switch1);
        }
Exemple #9
0
        public void UseSettingAlias()
        {
            string[]           args   = { "test", "xyz", "-s1=123" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.IsNull(result.ExitCode);
            TestStandardConsoleCommand parsedCmd = (TestStandardConsoleCommand)result.CommandsToExecute[0];

            Assert.AreEqual("xyz", parsedCmd.Arg1);
            Assert.AreEqual(0, parsedCmd.Arg2);
            Assert.AreEqual(123, parsedCmd.IntSetting);
        }
Exemple #10
0
        public void OptionalPositionalArgumentNotSpecified()
        {
            string[]           args   = { "test", "xyz", "-setting1=123" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.IsNull(result.ExitCode);
            TestStandardConsoleCommand parsedCmd = (TestStandardConsoleCommand)result.CommandsToExecute[0];

            Assert.AreEqual("xyz", parsedCmd.Arg1);
            Assert.AreEqual(0, parsedCmd.Arg2);
            Assert.AreEqual(123, parsedCmd.IntSetting);
        }
Exemple #11
0
        public void UnrecognizedCommand()
        {
            string[]           args   = { "cmd2" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.AreEqual(1, result.ExitCode);

            AssertOutputIs(@"Unit test console
");
            AssertErrOutputIs(@"Unknown command 'cmd2'. Type 'unittest.exe help' for the list of all commands.
");
        }
Exemple #12
0
        public void ParseStandardCommandSuccessfully()
        {
            string[]           args   = { "test", "value1", "123", "-setting1=345", "-setting2=haha" };
            ConsoleShellResult result = shell.ParseCommandLine(args);

            Assert.IsNull(result.ExitCode);
            TestStandardConsoleCommand parsedCmd = (TestStandardConsoleCommand)result.CommandsToExecute[0];

            Assert.AreEqual("value1", parsedCmd.Arg1);
            Assert.AreEqual(123, parsedCmd.Arg2);
            Assert.AreEqual(345, parsedCmd.IntSetting);
            Assert.AreEqual("haha", parsedCmd.StringSetting);
        }
Exemple #13
0
        public static int Main(string[] args)
        {
            Stopwatch commandStopwatch = new Stopwatch();

            commandStopwatch.Start();

            XmlConfigurator.Configure();

            IRazorCompiler razorCompiler = new InMemoryRazorCompiler();

            IFileSystem fileSystem = new WindowsFileSystem();
            //IFtpChannelFactory ftpChannelFactory = new FtpChannelFactoryUsingSockets ();
            //IFtpCommunicator ftpCommunicator = new FtpCommunicator ();
            //IFtpSessionFactory ftpSessionFactory = new FtpSessionFactory(ftpChannelFactory, ftpCommunicator, fileSystem);
            IFreudeTemplatingEngine freudeTemplatingEngine = new FreudeTemplatingEngine(razorCompiler);
            IWikiTextTokenizer      wikiTextTokenizer      = new WikiTextTokenizer();
            IFreudeTextParser       freudeTextParser       = new FreudeTextParser(wikiTextTokenizer);
            IProjectBuilder         projectBuilder         = new ProjectBuilder(fileSystem);

            ConsoleShell consoleShell = new ConsoleShell("Freude.Engine.exe");

            consoleShell.RegisterCommand(new BuildCommand(fileSystem, projectBuilder, freudeTextParser, freudeTemplatingEngine));
            //consoleShell.RegisterCommand (new DeployCommand(projectBuilder, ftpSessionFactory));

            try
            {
                ConsoleShellResult consoleShellResult = consoleShell.ParseCommandLine(args);

                if (consoleShellResult.ExitCode.HasValue)
                {
                    return(consoleShellResult.ExitCode.Value);
                }

                foreach (IConsoleCommand consoleCommand in consoleShellResult.CommandsToExecute)
                {
                    consoleCommand.Execute(consoleShell);
                }

                TimeSpan elapsed = commandStopwatch.Elapsed;
                log.InfoFormat("Command done in {0}", elapsed);

                return(0);
            }
            catch (Exception ex)
            {
                log.Fatal("Program failed", ex);
                return(1);
            }
        }