Пример #1
0
        public async Task ExternalTool_WhenAsync_StandardOutputIsCaptured()
        {
            const string canary = "146adgha4";

            using (var cancel = new CancellationTokenSource(ExecuteTimeout))
            {
                var result = await ExternalTool.ExecuteAsync(TestData.CommandHandler, TestData.MakeCommandString(string.Format("echo {0}", canary)), cancel.Token);

                Assert.AreEqual(0, result.ExitCode);
                Assert.IsTrue(result.StandardOutput.Contains(canary));
            }
        }
Пример #2
0
        private static async Task VerifyTshark(CancellationToken cancel)
        {
            _log.Debug("Verifying that TShark is installed.");

            ExternalToolResult tsharkCheckResult;

            try
            {
                tsharkCheckResult = await ExternalTool.ExecuteAsync(Constants.TsharkExecutableName, "--version", cancel);
            }
            catch (Exception ex)
            {
                throw new EnvironmentException("This app requires TShark to be installed. Attempt to execute TShark failed: " + ex.Message, ex);
            }

            if (!tsharkCheckResult.StandardOutput.StartsWith("TShark (Wireshark)"))
            {
                throw new NotSupportedException("Unrecognized TShark version/build.");
            }
        }
Пример #3
0
        public async Task ExternalTool_WhenAsync_ConsumingResultWithStandardErrorOutput_ThrowsException()
        {
            const string canary = "6h4sb6455t";

            using (var cancel = new CancellationTokenSource(ExecuteTimeout))
            {
                // Just echo something to stderr.
                await Assert.ThrowsExceptionAsync <EnvironmentException>(async() => await ExternalTool.ExecuteAsync(TestData.CommandHandler, TestData.MakeCommandString(string.Format("echo {0} 1>&2", canary)), cancel.Token));
            }
        }
Пример #4
0
 public async Task ExternalTool_WhenAsync_ConsumingResultWithFailureExitCode_ThrowsException()
 {
     using (var cancel = new CancellationTokenSource(ExecuteTimeout))
     {
         await Assert.ThrowsExceptionAsync <EnvironmentException>(async() => await ExternalTool.ExecuteAsync(TestData.CommandHandler, TestData.MakeCommandString("exit 1"), cancel.Token));
     }
 }