Ejemplo n.º 1
0
        public void assert_mandatory_success_with_failures_of_negative_number_error_code()
        {
            var procReturn = new ProcessReturn()
            {
                ExitCode = -532462766,
                OutputText = "something"
            };

            var log = new PackageLog();
            LogWriter.WithLog(log, procReturn.AssertMandatorySuccess);

            log.FullTraceText().ShouldEqual(procReturn.OutputText + System.Environment.NewLine);
            log.Success.ShouldBeFalse();
        }
Ejemplo n.º 2
0
        public void assert_optional_success_with_no_failures()
        {
            var procReturn = new ProcessReturn(){
                ExitCode = 0,
                OutputText = "something"
            };

            var log = MockRepository.GenerateMock<IPackageLog>();
            LogWriter.WithLog(log, () =>
            {
                procReturn.AssertOptionalSuccess();
            });

            log.AssertWasCalled(x => x.Trace(procReturn.OutputText));
        }
Ejemplo n.º 3
0
        public void assert_optional_success_with_failures_still_only_traces()
        {
            var procReturn = new ProcessReturn()
            {
                ExitCode = 11,
                OutputText = "something"
            };

            var log = new PackageLog();
            LogWriter.WithLog(log, () =>
            {
                procReturn.AssertOptionalSuccess();
            });

            log.FullTraceText().ShouldEqual(procReturn.OutputText + System.Environment.NewLine);
        }
Ejemplo n.º 4
0
        public void assert_mandatory_success_with_no_failures()
        {
            var procReturn = new ProcessReturn()
            {
                ExitCode = 0,
                OutputText = "something"
            };

            var log = new PackageLog();
            LogWriter.WithLog(log, () =>
            {
                procReturn.AssertMandatorySuccess();
            });

            log.FullTraceText().ShouldEqual(procReturn.OutputText + System.Environment.NewLine);
        }
Ejemplo n.º 5
0
        public void assert_mandatory_success_with_failures()
        {
            var procReturn = new ProcessReturn()
            {
                ExitCode = 11,
                OutputText = "something"
            };

            var log = MockRepository.GenerateMock<IPackageLog>();
            LogWriter.WithLog(log, () =>
            {
                procReturn.AssertMandatorySuccess();
            });

            log.AssertWasCalled(x => x.MarkFailure(procReturn.OutputText));
        }
Ejemplo n.º 6
0
        public ProcessReturn Run(ProcessStartInfo info, TimeSpan waitDuration)
        {
            //use the operating system shell to start the process
            //this allows credentials to flow through.
            //info.UseShellExecute = true;
            info.UseShellExecute = false;
            info.Verb = "runas";

            //don't open a new terminal window
            info.CreateNoWindow = true;

            info.RedirectStandardError = info.RedirectStandardOutput = true;

            LogWriter.Current.Trace("Running process at {0} {1}\nIn working directory {2}", info.FileName, info.Arguments, info.WorkingDirectory);

            if (!Path.IsPathRooted(info.FileName))
            {
                info.FileName = info.WorkingDirectory.AppendPath(info.FileName);
            }

            validate(info);

            ProcessReturn returnValue = null;
            var output = new StringBuilder();
            int pid = 0;
            using (var proc = Process.Start(info))
            {
                pid = proc.Id;
                proc.OutputDataReceived += (sender, outputLine) =>
                {
                    output.AppendLine(outputLine.Data);
                };

                proc.BeginOutputReadLine();
                proc.WaitForExit((int)waitDuration.TotalMilliseconds);

                killProcessIfItStillExists(pid);

                returnValue = new ProcessReturn(){
                    ExitCode = proc.ExitCode,
                    OutputText = output.ToString()
                };
            }

            return returnValue;
        }