コード例 #1
0
        public void WhenProcessCommandExcutes_DelegatesCreationToContainer()
        {
            container.CreateProcess(null).ReturnsForAnyArgs(process);
            var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args");

            cmd.Execute();

            container.Received().CreateProcess(Arg.Any <CreateProcessStartInfo>());
        }
コード例 #2
0
        public void ReturnsResultWithExitCode()
        {
            container.CreateProcess(null).ReturnsForAnyArgs(process);
            process.ExitCode.Returns(100);

            var cmd    = new TestableProcessCommand(container, tempDir, "some.exe", "some args");
            var result = cmd.Execute();

            Assert.Equal(100, result.ExitCode);
        }
コード例 #3
0
        public void AwaitsProcessExit()
        {
            container.CreateProcess(null).ReturnsForAnyArgs(process);

            var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args");

            cmd.Execute();

            process.Received().WaitForExit();
        }
コード例 #4
0
        public void WhenNotPrivileged_ShouldImpersonateRestrictedUser()
        {
            CreateProcessStartInfo si = null;

            container.CreateProcess(null).ReturnsForAnyArgs(c =>
            {
                si = c.Arg <CreateProcessStartInfo>();
                return(process);
            });

            var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args", false);

            cmd.Execute();

            container.Received().CreateProcess(Arg.Any <CreateProcessStartInfo>(), true);
        }
コード例 #5
0
        public void SetsTheWorkingDirectoryInStartInfo()
        {
            CreateProcessStartInfo si = null;

            container.CreateProcess(null).ReturnsForAnyArgs(c =>
            {
                si = c.Arg <CreateProcessStartInfo>();
                return(process);
            });

            var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args", true);

            cmd.Execute();

            Assert.Equal(tempDir, si.WorkingDirectory);
        }
コード例 #6
0
        private string InvokeCommandAndGetLogContent(string logRelativePath)
        {
            string content = null;

            // When Wait for exit is called, get the content of the env log.
            string expectedEnvPath = Path.Combine(tempDir, logRelativePath);

            process.When(p => p.WaitForExit()).Do(c => content = File.ReadAllText(expectedEnvPath));
            process.Id.Returns(100);

            container.ContainerDirectoryPath.Returns(tempDir);
            container.CreateProcess(null).ReturnsForAnyArgs(process);

            var env = new Dictionary <string, string> {
                { "env1", "val1" }, { "env2", "val2" }, { "rootedenv", "@ROOT@\\sub\\dir" }
            };
            var cmd = new TestableProcessCommand(container, tempDir, "some.exe", "some args", environment: env);

            cmd.Execute();

            return(content);
        }