public void WhenProcessSpecHasNoEnvironment()
                {
                    var io      = Substitute.For <IProcessIO>();
                    var process = Container.Run(Spec, io);

                    var actualSpec = ProcessRunner.Captured(x => x.Run(null)).Arg <ProcessRunSpec>();

                    Assert.Equal(ContainerEnvironment, actualSpec.Environment);
                }
            public void WhenContainerNotActive_Throws()
            {
                var io = Substitute.For <IProcessIO>();

                Container.Stop(false);
                Action action = () => Container.Run(Spec, io);

                Assert.Throws <InvalidOperationException>(action);
            }
                public void WhenPathMappingIsDisabled_DoesNotMapExecutablePath()
                {
                    var io = Substitute.For <IProcessIO>();

                    Spec.DisablePathMapping = true;
                    Spec.ExecutablePath     = "cmd.exe";

                    var process = Container.Run(Spec, io);

                    Assert.NotNull(process);
                    var actual = ConstrainedProcessRunner.Captured(x => x.Run(null)).Arg <ProcessRunSpec>();

                    Assert.Equal("cmd.exe", actual.ExecutablePath);
                }
                public void ProcessIoCanBeNull()
                {
                    var io = new TestProcessIO();

                    io.Output = null;
                    io.Error  = null;

                    Container.Run(Spec, io);

                    var proc = ConstrainedProcessRunner.Captured(x => x.Run(null)).Arg <ProcessRunSpec>();

                    Assert.Equal(null, proc.OutputCallback);
                    Assert.Equal(null, proc.ErrorCallback);
                }
                public void WhenProcessEnvironmentConflictsWithContainerEnvironment()
                {
                    Spec.Environment = new Dictionary <string, string>
                    {
                        { "Handle", "procHandle" },
                        { "ProcEnv", "ProcEnv" }
                    };

                    var io      = Substitute.For <IProcessIO>();
                    var process = Container.Run(Spec, io);

                    var actualSpec = ProcessRunner.Captured(x => x.Run(null)).Arg <ProcessRunSpec>();

                    Assert.Equal(Spec.Environment, actualSpec.Environment);
                }
                public void RunsTheProcessRemotely()
                {
                    var io = Substitute.For <IProcessIO>();

                    var process = Container.Run(Spec, io);

                    Assert.NotNull(process);
                    var actual = ConstrainedProcessRunner.Captured(x => x.Run(null)).Arg <ProcessRunSpec>();

                    Assert.Equal(ExpectedRunSpec.ExecutablePath, actual.ExecutablePath);
                    Assert.Equal(ExpectedRunSpec.Arguments, actual.Arguments);
                    Assert.Superset(
                        new HashSet <string>(ExpectedRunSpec.Environment.Keys),
                        new HashSet <string>(actual.Environment.Keys));
                    Assert.Equal(ExpectedRunSpec.WorkingDirectory, actual.WorkingDirectory);
                }
                public void ProcessIoIsRedirected()
                {
                    var io            = new TestProcessIO();
                    var remoteProcess = Substitute.For <IProcess>();

                    ConstrainedProcessRunner.Run(Arg.Any <ProcessRunSpec>()).Returns(remoteProcess)
                    .AndDoes(call =>
                    {
                        var runSpec = call.Arg <ProcessRunSpec>();
                        runSpec.OutputCallback("This is STDOUT");
                        runSpec.ErrorCallback("This is STDERR");
                    });

                    Container.Run(Spec, io);

                    Assert.Equal("This is STDOUT", io.Output.ToString());
                    Assert.Equal("This is STDERR", io.Error.ToString());
                }