示例#1
0
 protected override void Given()
 {
     string _app = "adasdasd";
     if (Os.IsWindows) {_app = @"cmd.exe"; _arguments=@"/c if %CD%==c:\ exit /b 41";}
     if (Os.IsUnix) {_app = "/bin/bash"; _arguments = @"-c ""test `pwd` == '/usr/bin' && (echo 'matches'; exit 41)""";}
     _task = new OSExecuatableTask(_app, _arguments, "task_name", (p1, p2, p3) => new ProcessWrapper(p1, p2, p3));
 }
示例#2
0
 public void SetUp()
 {
     CreateProcessExecutorMock(DefaultExecutable);
     task            = new ExecutableTask((ProcessExecutor)mockProcessExecutor.Object);
     task.Executable = DefaultExecutable;
     task.BuildArgs  = DefaultArgs;
 }
示例#3
0
        public void PopulateFromReflector()
        {
            const string xml = @"
    <exec>
        <executable>mybatchfile.bat</executable>
        <baseDirectory>C:\</baseDirectory>
	<buildArgs>myarg1 myarg2</buildArgs>
	<buildTimeoutSeconds>123</buildTimeoutSeconds>
        <environment>
		<variable name=""name1"" value=""value1""/>
		<variable><name>name2</name></variable>
		<variable name=""name3""><value>value3</value></variable>
	</environment>
    <priority>BelowNormal</priority>
	<successExitCodes>0,1,3,5</successExitCodes>
    </exec>";

            task = (ExecutableTask)NetReflector.Read(xml);
            Assert.AreEqual(@"C:\", task.ConfiguredBaseDirectory, "Checking ConfiguredBaseDirectory property.");
            Assert.AreEqual("mybatchfile.bat", task.Executable, "Checking property.");
            Assert.AreEqual(123, task.BuildTimeoutSeconds, "Checking BuildTimeoutSeconds property.");
            Assert.AreEqual("myarg1 myarg2", task.BuildArgs, "Checking BuildArgs property.");
            Assert.AreEqual(3, task.EnvironmentVariables.Length, "Checking environment variable array size.");
            Assert.AreEqual("name1", task.EnvironmentVariables[0].name, "Checking name1 environment variable.");
            Assert.AreEqual("value1", task.EnvironmentVariables[0].value, "Checking name1 environment value.");
            Assert.AreEqual("name2", task.EnvironmentVariables[1].name, "Checking name2 environment variable.");
            Assert.AreEqual("", task.EnvironmentVariables[1].value, "Checking name2 environment value.");
            Assert.AreEqual("name3", task.EnvironmentVariables[2].name, "Checking name3 environment variable.");
            Assert.AreEqual("value3", task.EnvironmentVariables[2].value, "Checking name3 environment value.");
            Assert.AreEqual("0,1,3,5", task.SuccessExitCodes);
            Assert.AreEqual(ProcessPriorityClass.BelowNormal, task.Priority);
            Verify();
        }
示例#4
0
        public async Task <IActionResult> CreateAsync([FromBody] ExecutableTaskCreateRequest request)
        {
            ExecutableTask task;

            if (request.PreviousTaskId != null)
            {
                var previousTask = await _context.Tasks.ByIdOrNullAsync(request.PreviousTaskId);

                task = new ExecutableTask(request.Name, previousTask);
            }
            else if (request.PipelineId != null)
            {
                var pipeline = await _context.Pipelines.ByIdOrNullAsync(request.PipelineId);

                task = new ExecutableTask(request.Name, pipeline);
            }
            else
            {
                return(new BadRequestResult());
            }

            await _context.Tasks.InsertOneAsync(task);

            return(Ok(new
            {
                taskId = task.Id
            }));
        }
示例#5
0
        public void ExecutableOutputShouldBeBuildResults()
        {
            ExecutableTask xmlTestTask = new ExecutableTask((ProcessExecutor)mockProcessExecutor.Object);

            xmlTestTask.Executable = DefaultExecutable;
            xmlTestTask.BuildArgs  = DefaultArgs;
            ExpectToExecuteArguments(DefaultArgs);

            IIntegrationResult result = IntegrationResult();

            xmlTestTask.Run(result);

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(IntegrationStatus.Success, result.Status);

            StringWriter buffer = new StringWriter();

            new ReflectorTypeAttribute("task").Write(new XmlTextWriter(buffer), xmlTestTask);

            // TODO: The following only works correctly when ProcessResultOutput is a single non-empty line.
            // That is always the case, courtesy of our superclass' initialization.  If that should ever
            // change, this test needs to be adjusted accordingly.
            Assert.AreEqual(System.Environment.NewLine + "<buildresults>" + System.Environment.NewLine
                            + buffer.ToString() + System.Environment.NewLine + "  <message>"
                            + ProcessResultOutput + "</message>" + System.Environment.NewLine + "</buildresults>"
                            + System.Environment.NewLine, result.TaskOutput);
            Verify();
        }
示例#6
0
        /// <summary>
        /// Creates a PowerShell object.
        /// </summary>
        protected override void ProcessRecord()
        {
            TaskBase t;

            switch (Type)
            {
            case TaskType.BatchFile:
                if (ForceBatchFileTaskType)
                {
#pragma warning disable CS0618 // Type or member is obsolete
                    t = new BatchFileTask(Path);
#pragma warning restore CS0618 // Type or member is obsolete
                }
                else
                {
                    t = new CommandLineTask(Path);
                }
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            case TaskType.Executable:
                t           = new ExecutableTask(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            case TaskType.External:
                t           = new ExternalTask(Name);
                t.Arguments = Arguments;
                break;

            case TaskType.PowerShell:
                t           = new PowerShellTask(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            case TaskType.TAEFDll:
                t           = new TAEFTest(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            case TaskType.UWP:
                t           = new UWPTask(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            default:
                throw new FactoryOrchestratorException(Resources.InvalidTaskRunTypeException);
            }

            this.WriteObject(t);
        }
示例#7
0
        public TaskWindowViewModel(ExecutableTask task)
        {
            _task   = task;
            _uiTask = new ExecutableTask(_task);

            OkCommand                    = new DelegateCommand(OkExecute);
            CancelCommand                = new DelegateCommand(CancelExecute);
            TestCommand                  = new DelegateCommand(TestExecute);
            SelectExecutableCommand      = new DelegateCommand(SelectExecutableExecute);
            SelectExecutionFolderCommand = new DelegateCommand(SelectExecutionFolderExecute);
        }
示例#8
0
        public void SleepReturnsFalseIfInterrupted()
        {
            // given
            const int sleepTime = 1000;
            var       target    = CreateInstance();
            var       task      = new ExecutableTask(target, sleepTime);

            // when
            var thread = ThreadSurrogate.Create("test").Start(task.Process);

            thread.Join(500);

            // then
            Assert.That(task.SleepOutCome, Is.EqualTo(0));
        }
示例#9
0
        public void PopulateFromConfigurationUsingOnlyRequiredElementsAndCheckDefaultValues()
        {
            const string xml = @"
    <exec>
        <executable>mybatchfile.bat</executable>
    </exec>";

            task = (ExecutableTask)NetReflector.Read(xml);
            Assert.AreEqual("mybatchfile.bat", task.Executable, "Checking property.");
            Assert.AreEqual(600, task.BuildTimeoutSeconds, "Checking BuildTimeoutSeconds property.");
            Assert.AreEqual("", task.BuildArgs, "Checking BuildArgs property.");
            Assert.AreEqual(0, task.EnvironmentVariables.Length, "Checking environment variable array size.");
            Assert.AreEqual("", task.SuccessExitCodes);
            Assert.AreEqual(ProcessPriorityClass.Normal, task.Priority);
            Verify();
        }
示例#10
0
        private void AddNewTaskExecute()
        {
            //TODO open display box
            var newTask             = new ExecutableTask();
            var taskWindowViewModel = new TaskWindowViewModel(newTask);
            var taskWindow          = new TaskWindowView(taskWindowViewModel);

            taskWindow.Topmost = true;
            taskWindow.ShowDialog();

            if (taskWindowViewModel.IsModificationValidated)
            {
                _repository.AddNewExecutableTask(newTask);
                _taskList.Add(new ExecutableTaskViewModel(newTask));
            }
        }
示例#11
0
        /// <summary>
        /// Creates a PowerShell object.
        /// </summary>
        protected override void ProcessRecord()
        {
            TaskBase t;

            switch (Type)
            {
            case TaskType.BatchFile:
                t           = new BatchFileTask(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            case TaskType.Executable:
                t           = new ExecutableTask(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            case TaskType.External:
                t           = new ExternalTask(Name);
                t.Arguments = Arguments;
                break;

            case TaskType.PowerShell:
                t           = new PowerShellTask(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            case TaskType.TAEFDll:
                t           = new TAEFTest(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            case TaskType.UWP:
                t           = new UWPTask(Path);
                t.Arguments = Arguments;
                t.Name      = Name;
                break;

            default:
                throw new FactoryOrchestratorException(Resources.InvalidTaskRunTypeException);
            }

            this.WriteObject(t);
        }
示例#12
0
        public void WakeUpInterruptsSleep()
        {
            // given
            const int sleepTime = 5000;
            var       target    = CreateInstance();
            var       task      = new ExecutableTask(target, sleepTime);

            // when
            var thread = ThreadSurrogate.Create("test-thread").Start(task.Process);

            target.WakeUp();

            thread.Join(sleepTime);

            // then
            Assert.That(task.SleptTime, Is.LessThan(sleepTime));
        }
示例#13
0
        private bool IsExecutionSuccessful(ExecutableTask taskToRun)
        {
            var pInfo = new ProcessStartInfo
            {
                FileName         = taskToRun.ExecutableFullPath,
                Arguments        = taskToRun.ExecutableArgs,
                WorkingDirectory = taskToRun.ExecutionFolder,
                WindowStyle      = ProcessWindowStyle.Hidden
            };

            //var p = new Process();
            var p = Process.Start(pInfo);

            p?.WaitForExit(2 * 60 * 1000);
            var exitCode = p?.ExitCode;

            return(exitCode == taskToRun.ExpectedReturnCode);
        }
        public void ShouldBeAbleToSaveProjectsThatALoaderCanLoad()
        {
            ExecutableTask builder = new ExecutableTask();

            builder.Executable = "foo";
            FileSourceControl sourceControl = new FileSourceControl();

            sourceControl.RepositoryRoot = "bar";
            // Setup
            Project project1 = new Project();

            project1.Name          = "Project One";
            project1.SourceControl = sourceControl;
            Project project2 = new Project();

            project2.Name          = "Project Two";
            project2.SourceControl = sourceControl;
            ProjectList projectList = new ProjectList();

            projectList.Add(project1);
            projectList.Add(project2);

            var mockConfiguration = new Mock <IConfiguration>();

            mockConfiguration.SetupGet(_configuration => _configuration.Projects).Returns(projectList).Verifiable();

            FileInfo configFile = new FileInfo(TempFileUtil.CreateTempFile(TempFileUtil.CreateTempDir(this), "loadernet.config"));

            // Execute
            DefaultConfigurationFileSaver saver = new DefaultConfigurationFileSaver(new NetReflectorProjectSerializer());

            saver.Save((IConfiguration)mockConfiguration.Object, configFile);

            DefaultConfigurationFileLoader loader = new DefaultConfigurationFileLoader();
            IConfiguration configuration2         = loader.Load(configFile);

            // Verify
            Assert.IsNotNull(configuration2.Projects["Project One"]);
            Assert.IsNotNull(configuration2.Projects["Project Two"]);
            mockConfiguration.Verify();
        }
示例#15
0
 public StateFluentBuilder <TOuterBuilder> AddOnExit(ExecutableTask task) => AddOnExit(new RuntimeAction(task));
示例#16
0
 public FinalFluentBuilder <TOuterBuilder> AddOnEntry(ExecutableTask task) => AddOnEntry(new RuntimeAction(task));
        public TransitionFluentBuilder <TOuterBuilder> AddOnTransition(ExecutableTask task)
        {
            _builder.AddAction(new RuntimeAction(task));

            return(this);
        }
 protected override void Given()
 {
     task = new OSExecuatableTask("ruby", "-e ' STDERR.sync = true; $stderr.puts \"error output\";'", "name", (p1, p2, p3) => new ProcessWrapper(p1, p2, p3));
 }
 protected override void Given()
 {
     task = new OSExecuatableTask("flipflof", "-e ' STDERR.sync = true; $stderr.puts \"error output\";'", "name", (p1, p2, p3) => new ProcessWrapper(p1, p2, p3));
     task.OnTerminalOutputUpdate += s => errOutput += s;
 }
示例#20
0
文件: TaskSpec.cs 项目: pshomov/frog
 protected override void Given()
 {
     _task = new OSExecuatableTask("ruby", @"-e 'exit 0'", "task_name", (p1, p2, p3) => new ProcessWrapper(p1, p2, p3));
 }
示例#21
0
文件: TaskSpec.cs 项目: pshomov/frog
 protected override void Given()
 {
     _task = new OSExecuatableTask("ad43wsWasdasd", "", "task_name", (p1, p2, p3) => new ProcessWrapper(p1, p2, p3));
 }
 protected override void Given()
 {
     task = new OSExecuatableTask("ruby", "-e ' STDOUT.sync = true; puts \"output\";'", "name", (p1, p2, p3) => new ProcessWrapper(p1, p2, p3));
     task.OnTerminalOutputUpdate += s => stdOutput += s;
 }
        private TaskBase CreateTestFromFlyout(TaskType testType)
        {
            activeTaskIsNowBg = false;
            if (activeTask == null)
            {
                activeTaskIndex = -1;
                switch (testType)
                {
                case TaskType.ConsoleExe:
                    activeTask = new ExecutableTask(TaskPathBox.Text);
                    break;

                case TaskType.UWP:
                    activeTask = new UWPTask(AppComboBox.SelectedItem.ToString());
                    break;

                case TaskType.External:
                    activeTask = new ExternalTask(TaskPathBox.Text);
                    break;

                case TaskType.TAEFDll:
                    activeTask = new TAEFTest(TaskPathBox.Text);
                    break;

                case TaskType.BatchFile:
                    if (supportsCommandLineTask)
                    {
                        activeTask = new CommandLineTask(TaskPathBox.Text);
                    }
                    else
                    {
#pragma warning disable CS0618 // Type or member is obsolete
                        activeTask = new BatchFileTask(TaskPathBox.Text);
#pragma warning restore CS0618 // Type or member is obsolete
                    }
                    break;

                case TaskType.PowerShell:
                    activeTask = new PowerShellTask(TaskPathBox.Text);
                    break;
                }
            }

            if (!String.IsNullOrWhiteSpace(TestNameBox.Text))
            {
                activeTask.Name = TestNameBox.Text;
            }

            if (!string.IsNullOrWhiteSpace(TimeoutBox.Text))
            {
                try
                {
                    activeTask.TimeoutSeconds = Int32.Parse(TimeoutBox.Text, CultureInfo.CurrentCulture);
                }
                catch (Exception)
                {
                    activeTask.TimeoutSeconds = -1;
                }
            }
            else
            {
                activeTask.TimeoutSeconds = -1;
            }

            if (!string.IsNullOrWhiteSpace(RetryBox.Text))
            {
                try
                {
                    activeTask.MaxNumberOfRetries = UInt32.Parse(RetryBox.Text, CultureInfo.CurrentCulture);
                }
                catch (Exception)
                {
                    activeTask.MaxNumberOfRetries = 0;
                }
            }
            else
            {
                activeTask.MaxNumberOfRetries = 0;
            }

            switch (testType)
            {
            case TaskType.ConsoleExe:
            case TaskType.BatchFile:
            case TaskType.PowerShell:
            case TaskType.TAEFDll:
            case TaskType.External:
                var task = activeTask as TaskBase;
                task.Path      = TaskPathBox.Text;
                task.Arguments = ArgumentsBox.Text;
                break;

            case TaskType.UWP:
                var uwpTask = activeTask as UWPTask;
                uwpTask.Path                 = AppComboBox.SelectedItem.ToString();
                uwpTask.Arguments            = ArgumentsBox.Text;
                uwpTask.AutoPassedIfLaunched = (bool)AutoPassCheck.IsChecked;
                uwpTask.TerminateOnCompleted = (bool)TerminateOnCompleteCheck.IsChecked;
                break;
            }

            switch (testType)
            {
            case TaskType.ConsoleExe:
            case TaskType.BatchFile:
            case TaskType.PowerShell:
                var task = activeTask as ExecutableTask;
                task.BackgroundTask = (bool)BgTaskBox.IsChecked;
                if (task.BackgroundTask)
                {
                    activeTaskIsNowBg = true;
                }
                break;

            default:
                break;
            }

            activeTask.AbortTaskListOnFailed = (bool)AbortOnFailBox.IsChecked;
            activeTask.RunInContainer        = (bool)ContainerBox.IsChecked;

            return(activeTask);
        }