public void Execute_ReturnsVersionString() { var command = new VersionCommand(); var result = command.Execute(new VersionArgs()); StringAssert.Contains("grep", result); }
public void Run() { while (true) { string input = Console.ReadLine(); ICommand Command; switch (input.ToUpper()) { case "CLEAR": Command = new ClearCommand(); Command.Execute(); break; case "VERSION": Command = new VersionCommand(); Command.Execute(); break; default: Command = new NullCommand(); Command.Execute(); break; } } }
public void Execute_ReturnsVersionString() { var command = new VersionCommand(); var result = command.Execute(new VersionArgs()); StringAssert.Contains("grep", result); }
public static string Parse(List <string> args) { try { string result; var command = args.First(); if (command == Statics.Commands.Help) { var helpCommand = new HelpCommand(); var numberOfArgs = helpCommand.GetNumberOfArgs(); if (numberOfArgs == args.Count - 1) { result = helpCommand.Execute(new List <string>()); } else { throw new Exception("Command not recognized. Please use 'WixXmlGenerator -help' to see command the usages."); } } else if (command == Statics.Commands.Version) { var versionCommand = new VersionCommand(); var numberOfArgs = versionCommand.GetNumberOfArgs(); if (numberOfArgs == args.Count - 1) { result = versionCommand.Execute(new List <string>()); } else { throw new Exception("Command not recognized. Please use 'WixXmlGenerator -help' to see command the usages."); } } else if (command == Statics.Commands.Generate) { var generateCommand = new GenerateCommand(); var numberOfArgs = generateCommand.GetNumberOfArgs(); if (numberOfArgs == args.Count - 1) { result = generateCommand.Execute(args); } else { throw new Exception("Command not recognized. Please use 'WixXmlGenerator -help' to see command the usages."); } } else { throw new Exception("Command not recognized. Please use 'WixXmlGenerator -help' to see command the usages."); } return(result); } catch (Exception e) { throw e; } }
public void ShouldPrintCorrectVersionNumber() { var version = GetVersionFromFile(Path.Combine(TestContext.CurrentContext.WorkDirectory, "ExpectedSdkVersion.txt")); versionCommand.Execute(); output.ToString() .Should() .Contain(version); }
public async Task ShouldStartWithProperTimeout() { var starterMock = new Mock <IProcessStarter>(); starterMock.Setup(starter => starter.Start(It.IsAny <string>(), TimeSpan.FromHours(1))) .Returns(Task.FromResult(0)); var command = new VersionCommand(starterMock.Object, string.Empty); await command.Execute(TimeSpan.FromHours(1)); starterMock.Verify(starter => starter.Start(It.IsAny <string>(), TimeSpan.FromHours(1)), Times.Once()); }
public async Task ShouldStartWithProperArguments() { var starterMock = new Mock <IProcessStarter>(); starterMock.Setup(starter => starter.Start("--version", It.IsAny <TimeSpan>())) .Returns(Task.FromResult(0)); var command = new VersionCommand(starterMock.Object); await command.Execute(); starterMock.Verify(starter => starter.Start("--version", It.IsAny <TimeSpan>()), Times.Once()); }
public void Will_return_assembly_version_as_memcached_version() { var stream = new MemoryStream(); var cmd = new VersionCommand(); cmd.SetContext(stream); cmd.Execute(); Assert.AreEqual("VERSION " + typeof(VersionCommand).Assembly.GetName().Version + "\r\n", ReadAll(stream)); }
public void ShouldPrintCorrectVersionNumber() { var filename = Path.Combine(Path.GetDirectoryName(AssemblyPath()), "ExpectedSdkVersion.txt"); var version = GetVersionFromFile(filename); versionCommand.Execute(); output.ToString() .Should() .Contain(version); }
public void Version_Execute_ReturnString() { var command = new VersionCommand(_console, LoggerMock.GetLogger <VersionCommand>().Object, _versionService.Object); var resultMessage = command.Execute(); Assert.Contains("API Version: 1.0", resultMessage); Assert.Contains("CLI Version:", resultMessage); Assert.Contains("- Engine01: 1.0", resultMessage); Assert.Contains("- AspNetMvc: 1.0", resultMessage); }
public void ShouldExecuteDockerComposeWithNoArgumentsWithoutExceptions() { var starterMock = new Mock <IProcessStarter>(); starterMock.Setup(starter => starter.Start(It.IsAny <string>(), It.IsAny <TimeSpan>())) .Returns(Task.FromResult(0)); var command = new VersionCommand(starterMock.Object, string.Empty); Func <Task> execute = async() => await command.Execute(); execute.Should().NotThrow( "При условии установленного Docker Compose получение его версии всегда допустим."); }
public void Execute_WhenCalled_ReturnsViewWithVersionAsModel() { var command = new VersionCommand(); var versionArgs = new VersionArgs { Version = true }; var result = (CommandResult)command.Execute(versionArgs); var model = (VersionViewModel)result.Model; result.ViewName.ShouldEqual("Version"); model.Version.ShouldEqual("2.4.2"); }
public void ShouldCopyStandardOutputAndStandardErrorFromProcessStarterOnSuccessfulExecution() { var starterMock = new Mock <IProcessStarter>(); starterMock.Setup(starter => starter.Start(It.IsAny <string>(), It.IsAny <TimeSpan>())) .Returns(Task.FromResult(0)); starterMock.Setup(starter => starter.StandardOutput).Returns(() => new StringBuilder("stdout")); starterMock.Setup(starter => starter.StandardError).Returns(() => new StringBuilder("stderr")); var command = new VersionCommand(starterMock.Object, string.Empty); Func <Task> execute = async() => await command.Execute(); execute.Should().NotThrow(); command.StandardOutput.ToString().Should().Be("stdout"); command.StandardError.ToString().Should().Be("stderr"); }
public void ShouldThrowIfCommandExecutionExceededTimeout() { var starterMock = new Mock <IProcessStarter>(); starterMock.Setup(starter => starter.Start(It.IsAny <string>(), It.IsAny <TimeSpan>())) .Throws <TimeoutException>(); starterMock.Setup(starter => starter.StandardOutput).Returns(() => new StringBuilder()); starterMock.Setup(starter => starter.StandardError).Returns(() => new StringBuilder()); var command = new VersionCommand(starterMock.Object, string.Empty); Func <Task> execute = async() => await command.Execute(); execute.Should() .ThrowExactly <CommandExecutionException>() .WithMessage("*timeout*") .WithInnerExceptionExactly <TimeoutException>(); }
public static int Main(string[] args) { CommandLine.Initialize(); var options = new CommandLineParser(args); options.AddOptions(null, OPTIONS_GENERAL); options.AddOptions("help", OPTIONS_HELP); options.AddOptions("version", OPTIONS_VERSION); options.AddOptions("convert", OPTIONS_CONVERT); options.AddOptions("list", OPTIONS_LIST); options.AddOptions("register", OPTIONS_REGISTER); // save the error state bool invalidArguments = !options.Parse("convert"); // get the Quiet option first, before we emit anything Quiet = options.GetOptionSwitch("quiet"); if (Quiet) { Console.SetOut(new StreamWriter(Stream.Null)); Console.SetError(Console.Out); } NoLog = options.GetOptionSwitch("nolog"); if (!NoLog) { Process running_proc = Process.GetCurrentProcess(); Process[] mbinc_procs = Process.GetProcessesByName(running_proc.ProcessName); // If we only have one instance of MBINCompiler running create the usual log. // If a process starts and there is already a running MBINCompiler process, then // add the PID to the log file name so that there is no issue with two processes // attempting to write to the same log file. if (mbinc_procs.Length == 1) { Logger.Open(Path.ChangeExtension(Utils.GetExecutablePath(), ".log")); } else { Logger.Open(Path.ChangeExtension(Utils.GetExecutablePath(), $".{running_proc.Id}.log")); } Logger.EnableTraceLogging = true; Logger.LogMessage("VERSION", $"MBINCompiler v{Version.GetVersionStringCompact()}"); Logger.LogMessage("ARGS", $"\"{string.Join("\" \"", args)}\"\n"); using (var indent = new Logger.IndentScope()) { Logger.LogMessage("If you encounter any errors, please submit a bug report and include this log file.\n" + "Please check that there isn't already a similar issue open before creating a new one.\n" + "https://github.com/monkeyman192/MBINCompiler/issues\n"); } } // now we can emit an error if we need to if (invalidArguments) { return(CommandLine.ShowInvalidCommandLineArg(options)); } // initialize remaining global options DebugMode = options.GetOptionSwitch("debug"); // execute the appropriate mode try { switch (options.Verb) { case "help": return(HelpCommand.Execute(options)); case "version": return(VersionCommand.Execute(options)); case "list": return(ListCommand.Execute(options)); case "register": return(RegisterCommand.Execute(options)); default: return(ConvertCommand.Execute(options)); } } catch (System.Exception e) { return(CommandLine.ShowException(e)); } }