Beispiel #1
0
        public void ShouldExecute()
        {
            // Given
            var      processInfo = ProcessInfoExtensions.Create();
            ExitCode exitCode    = 33;

            var processListener = new Mock <IProcessListener>();

            var process = new Mock <IProcess>();

            process.Setup(i => i.Run(processListener.Object)).Returns(exitCode);

            var processFactory = new Mock <IProcessFactory>();

            processFactory.Setup(i => i.Create(processInfo)).Returns(process.Object);

            var commandLine = new CommandLineService(processFactory.Object, processListener.Object);

            // When
            var actualExitCode = commandLine.Execute(processInfo);

            // Then
            process.Verify(i => i.Run(processListener.Object));
            actualExitCode.ShouldBe(exitCode);
        }
        public void ShouldWrap(
            string envVars,
            string expectedEnvFile,
            string expectedArgs)
        {
            // Given
            var provider    = CreateInstance();
            var wrapperInfo = new DockerWrapperInfo(
                "mcr.microsoft.com/windows/servercore",
                Enumerable.Empty <DockerVolume>(),
                Enumerable.Empty <CommandLineArgument>(),
                (Enumerable <EnvironmentVariable>)envVars,
                OperatingSystem.Windows,
                true,
                DockerPullType.Missing);

            var processInfo = ProcessInfoExtensions.Create();

            // When
            var actualArgs = string.Join(" ",
                                         provider.GetArguments(wrapperInfo, processInfo).Select(i => i.Value));

            // Then
            actualArgs.ShouldBe(expectedArgs);
            _fileContent.TryGetValue("abc_env.list", out var actualEnvFile);
            actualEnvFile.ShouldBe(expectedEnvFile);
        }
        public void ShouldWrap()
        {
            // Given
            var wrapperInfo = DockerWrapperInfoExtensions.Create();
            var wrapper     = CreateInstance(wrapperInfo);
            var processInfo = ProcessInfoExtensions.Create();

            // When
            var actualProcessInfo = wrapper.Wrap(processInfo);

            // Then
            actualProcessInfo.Executable.ShouldBe("docker");
            actualProcessInfo.WorkingDirectory.ShouldBe("wd");
            actualProcessInfo.Variables.ToList().ShouldBe(new List <EnvironmentVariable>()
            {
                "var1=val1", "var2=val2"
            });
        }
Beispiel #4
0
        public void ShouldCreateProcess()
        {
            // Given
            var info    = ProcessInfoExtensions.Create();
            var factory = CreateInstance();

            // When
            factory.Create(info);

            // Then
            _processFactory.Verify(func => func(It.Is <Process>(
                                                    process =>
                                                    process.StartInfo.FileName == info.Executable.Value &&
                                                    process.StartInfo.WorkingDirectory == info.WorkingDirectory.Value &&
                                                    process.StartInfo.Arguments == info.Arguments.ToString() &&
                                                    info.Variables.All(i => process.StartInfo.Environment[i.Name] == i.Value) &&
                                                    process.StartInfo.EnvironmentVariables[ProcessFactory.FlowVersionEnvName] == "1.0.0.0"
                                                    )));
        }
        public void ShouldAppendWrapper()
        {
            // Given
            var originalProcessInfo = ProcessInfoExtensions.Create();

            _processFactory.Setup(i => i.Create(originalProcessInfo)).Returns(_process.Object);

            var processInfo = ProcessInfoExtensions.Create("run.cmd");

            _processWrapper.Setup(i => i.Wrap(originalProcessInfo)).Returns(processInfo);

            var factory = CreateInstance();

            // When
            factory.Append(_processWrapper.Object);
            factory.Create(originalProcessInfo);

            // Then
            _processFactory.Verify(i => i.Create(processInfo));
        }