Пример #1
0
        public async Task RunAsync_ReturnsSuccessCode()
        {
            //Arrange
            using (var tempFile = new TemporaryFile("bat"))
            {
                var batchScript = @"
                    @echo off
                    EXIT /B 0
                ";

                File.WriteAllText(tempFile.FileName, batchScript);

                var processTask = new ProcessTask(tempFile.FileName, cancellationToken);


                //Act
                var result = await processTask.RunAsync();

                //Assert
                Assert.AreEqual(0, result);
            }
        }
Пример #2
0
        public async Task RunAsync_ErrorCodePropregated()
        {
            //Arrange
            using (var temp = new TemporaryFile("bat"))
            {
                using (var innerFile = new TemporaryFile("bat"))
                {
                    var batchScript = @"
                        @echo off
                        exit /B 1
                    ";

                    File.WriteAllText(innerFile.FileName, batchScript);

                    var outerScript = $@"
                        @echo off
                        call {innerFile.FileName}
                        @if errorlevel 1 goto err
                        @GOTO DONE 
                        :ERR 
                        EXIT/B 1
                        @GOTO COMPLETE
                        :DONE
                        :COMPLETE
                    ";

                    File.WriteAllText(temp.FileName, outerScript);

                    var processTask = new ProcessTask(temp.FileName, cancellationToken);

                    //Act
                    var result = await processTask.RunAsync();

                    //Assert
                    Assert.AreEqual(1, result);
                }
            }
        }
Пример #3
0
        public async Task RunAsync_HandlesNestedScripts()
        {
            //Arrange
            using (var temp = new TemporaryFile("bat"))
            {
                using (var innerFile = new TemporaryFile("bat"))
                {
                    var batchScript = $@"
                        @echo off 
                        echo Testing
                    ";

                    File.WriteAllText(innerFile.FileName, batchScript);

                    var outerScript = $@"
                        @echo off
                        call {innerFile.FileName}
                        @if errorlevel 1 goto err
                        @GOTO DONE 
                        :ERR 
                        EXIT/B 1
                        :DONE
                    ";

                    File.WriteAllText(temp.FileName, outerScript);

                    var processTask = new ProcessTask(temp.FileName, cancellationToken);

                    //Act
                    var result = await processTask.RunAsync();

                    //Assert
                    Assert.AreEqual(0, result);
                }
            }
        }