Esempio n. 1
0
        protected override Instruction CreateInstruction(Dictionary <string, string> attributes)
        {
            this.executeInstruction = new CommandLineInstruction();
            var fileName = attributes.GetValueOrDefault("FileName", string.Empty);

            this.executeInstruction.FileName = Environment.ExpandEnvironmentVariables(fileName);
            var arguments = attributes.GetValueOrDefault("Arguments", string.Empty);

            this.executeInstruction.Arguments          = Environment.ExpandEnvironmentVariables(arguments);
            this.executeInstruction.NewLineReplacement = attributes.GetValueOrDefault("NewLineReplacement", string.Empty);

            int timeoutInMilliseconds;

            if (int.TryParse(attributes.GetValueOrDefault("TimeoutInMilliseconds", string.Empty), out timeoutInMilliseconds))
            {
                this.executeInstruction.TimeoutInMilliseconds = timeoutInMilliseconds;
            }

            int expectedExitCode;

            if (int.TryParse(attributes.GetValueOrDefault("ExpectedExitCode", string.Empty), out expectedExitCode))
            {
                this.executeInstruction.ExpectedExitCode = expectedExitCode;
            }

            if (Enum.TryParse(attributes.GetValueOrDefault("ExecutionMode", string.Empty), true, out ExecutionMode executionMode))
            {
                this.executeInstruction.ExecutionMode = executionMode;
            }

            return(this.executeInstruction);
        }
 public void ExpectedExitCode0Test()
 {
     var commandLineInstruction = new CommandLineInstruction();
       commandLineInstruction.FileName = "EchoParams.bat";
       commandLineInstruction.Arguments = "0 TextParam ErrorParam";
       var result = commandLineInstruction.Execute();
       Assert.IsTrue(result);
 }
 public void ExitCodeDiffersFromExpectedExitCodeMustFail()
 {
     var commandLineInstruction = new CommandLineInstruction();
       commandLineInstruction.FileName = "EchoParams.bat";
       commandLineInstruction.Arguments = "5 TextParam";
       var result = commandLineInstruction.Execute();
       Assert.IsFalse(result);
 }
Esempio n. 4
0
        public void ExitCodeDiffersFromExpectedExitCodeMustFail()
        {
            var commandLineInstruction = new CommandLineInstruction();

            commandLineInstruction.FileName  = "EchoParams.bat";
            commandLineInstruction.Arguments = "5 TextParam";
            var result = commandLineInstruction.Execute();

            Assert.IsFalse(result);
        }
Esempio n. 5
0
        public void ExpectedExitCode0Test()
        {
            var commandLineInstruction = new CommandLineInstruction();

            commandLineInstruction.FileName  = "EchoParams.bat";
            commandLineInstruction.Arguments = "0 TextParam ErrorParam";
            var result = commandLineInstruction.Execute();

            Assert.IsTrue(result);
        }
 public void StandardErrorIsLogged()
 {
     const string standardParameterText = "TextParam";
       const string errorParameterText = "\"An error has occured\"";
       var memoryStream = new MemoryStream();
       var streamWriter = new StreamWriter(memoryStream);
       var commandLineInstruction = new CommandLineInstruction(null, streamWriter);
       commandLineInstruction.FileName = "EchoParams.bat";
       commandLineInstruction.Arguments = "0 " + standardParameterText + " " + errorParameterText;
       var result = commandLineInstruction.Execute();
       Assert.IsTrue(result);
       streamWriter.Flush();
       memoryStream.Position = 0;
       var streamReader = new StreamReader(memoryStream);
       Assert.AreEqual(errorParameterText, streamReader.ReadToEnd().Trim());
 }
Esempio n. 7
0
        public void StandardOutputIsLogged()
        {
            const string standardParameterText  = "TextParam";
            var          memoryStream           = new MemoryStream();
            var          streamWriter           = new StreamWriter(memoryStream);
            var          commandLineInstruction = new CommandLineInstruction(streamWriter, null);

            commandLineInstruction.FileName  = "EchoParams.bat";
            commandLineInstruction.Arguments = "0 " + standardParameterText;
            var result = commandLineInstruction.Execute();

            Assert.IsTrue(result);
            streamWriter.Flush();
            memoryStream.Position = 0;
            var streamReader = new StreamReader(memoryStream);

            Assert.AreEqual(standardParameterText, streamReader.ReadToEnd());
        }
Esempio n. 8
0
        public void StandardErrorIsLogged()
        {
            const string standardParameterText  = "TextParam";
            const string errorParameterText     = "\"An error has occured\"";
            var          memoryStream           = new MemoryStream();
            var          streamWriter           = new StreamWriter(memoryStream);
            var          commandLineInstruction = new CommandLineInstruction(null, streamWriter);

            commandLineInstruction.FileName  = "EchoParams.bat";
            commandLineInstruction.Arguments = "0 " + standardParameterText + " " + errorParameterText;
            var result = commandLineInstruction.Execute();

            Assert.IsTrue(result);
            streamWriter.Flush();
            memoryStream.Position = 0;
            var streamReader = new StreamReader(memoryStream);

            Assert.AreEqual(errorParameterText, streamReader.ReadToEnd().Trim());
        }
        protected override Instruction CreateInstruction(Dictionary<string, string> attributes)
        {
            this.executeInstruction = new CommandLineInstruction();
              this.executeInstruction.FileName = attributes.GetValueOrDefault("FileName", string.Empty);
              this.executeInstruction.Arguments = attributes.GetValueOrDefault("Arguments", string.Empty);
              this.executeInstruction.NewLineReplacement = attributes.GetValueOrDefault("NewLineReplacement", string.Empty);

              int timeoutInMilliseconds;
              if (int.TryParse(attributes.GetValueOrDefault("TimeoutInMilliseconds", string.Empty), out timeoutInMilliseconds))
              {
            this.executeInstruction.TimeoutInMilliseconds = timeoutInMilliseconds;
              }

              int expectedExitCode;
              if (int.TryParse(attributes.GetValueOrDefault("ExpectedExitCode", string.Empty), out expectedExitCode))
              {
            this.executeInstruction.ExpectedExitCode = expectedExitCode;
              }

              return this.executeInstruction;
        }
 public void StandardOutputIsLogged()
 {
     const string standardParameterText = "TextParam";
       var memoryStream = new MemoryStream();
       var streamWriter = new StreamWriter(memoryStream);
       var commandLineInstruction = new CommandLineInstruction(streamWriter, null);
       commandLineInstruction.FileName = "EchoParams.bat";
       commandLineInstruction.Arguments = "0 " + standardParameterText;
       var result = commandLineInstruction.Execute();
       Assert.IsTrue(result);
       streamWriter.Flush();
       memoryStream.Position = 0;
       var streamReader = new StreamReader(memoryStream);
       Assert.AreEqual(standardParameterText, streamReader.ReadToEnd());
 }