コード例 #1
0
        public void Fail()
        {
            var processRunner = new LoggingProcessRunner <LoggingProcessRunnerTests>(new ProcessRunner(), mockup.Get <ILogger <LoggingProcessRunnerTests> >());
            var startInfo     = new ProcessStartInfo("pwsh", "asdfasdfdsa");
            var result        = processRunner.Run(startInfo);

            Assert.Equal(64, result);
        }
コード例 #2
0
        public void EchoError()
        {
            var processRunner = new LoggingProcessRunner <LoggingProcessRunnerTests>(new ProcessRunner(), mockup.Get <ILogger <LoggingProcessRunnerTests> >());
            var startInfo     = new ProcessStartInfo("pwsh", "-c Write-Error 'hi'");
            var result        = processRunner.Run(startInfo);

            Assert.Equal(1, result);
        }
コード例 #3
0
        private static IProcessRunner CreateRunner(IServiceProvider s, ThreaxProcessHelperOptions options)
        {
            IProcessRunner runner = new ProcessRunner();

            if (options.IncludeLogOutput)
            {
                try
                {
                    var logger = s.GetRequiredService <ILogger <DefaultLog> >();
                    runner = new LoggingProcessRunner <DefaultLog>(runner, logger);
                }
                catch (ObjectDisposedException)
                {
                    //Sometimes this is called after the context is disposed.
                    //If that happens it is ok, logging will not be included.
                }
            }
            if (options.DecorateProcessRunner != null)
            {
                runner = options.DecorateProcessRunner.Invoke(runner);
            }
            return(runner);
        }