/// <summary>
        /// Make instances of <see cref="ITestCommand"/> objects for the given class and method.
        /// </summary>
        /// <param name="classCommand">The class command</param>
        /// <param name="method">The method under test</param>
        /// <returns>The set of <see cref="ITestCommand"/> objects</returns>
        public static IEnumerable <ITestCommand> Make(ITestClassCommand classCommand,
                                                      IMethodInfo method)
        {
            foreach (var testCommand in classCommand.EnumerateTestCommands(method))
            {
                ITestCommand wrappedCommand = testCommand;

                // Timeout (if they have one) -> Capture -> Timed -> Lifetime (if we need an instance) -> BeforeAfter

                wrappedCommand = new BeforeAfterCommand(wrappedCommand, method.MethodInfo);

                if (testCommand.ShouldCreateInstance)
                {
                    wrappedCommand = new LifetimeCommand(wrappedCommand, method);
                }

                wrappedCommand = new ExceptionAndOutputCaptureCommand(wrappedCommand, method);
                wrappedCommand = new TimedCommand(wrappedCommand);

                if (wrappedCommand.Timeout > 0)
                {
                    wrappedCommand = new TimeoutCommand(wrappedCommand, wrappedCommand.Timeout, method);
                }

                yield return(wrappedCommand);
            }
        }
            public void ShouldWrapExceptionDetailsWhenExceptionIsThrown()
            {
                ExceptionThrowingCommand innerCmd = new ExceptionThrowingCommand();
                MethodInfo method = typeof(ExceptionThrowingCommand).GetMethod("Execute");
                var command = new ExceptionAndOutputCaptureCommand(innerCmd, Reflector.Wrap(method));

                MethodResult result = command.Execute(null);

                FailedResult failed = Assert.IsType<FailedResult>(result);
                Assert.Equal(method.Name, failed.MethodName);
                Assert.Equal(method.DeclaringType.FullName, failed.TypeName);
                Assert.Equal(typeof(TargetInvocationException).FullName, failed.ExceptionType);
                Assert.Contains("ExceptionThrowingCommand.Execute", failed.StackTrace);
            }
        /// <summary>
        /// Make instances of <see cref="ITestCommand"/> objects for the given class and method.
        /// </summary>
        /// <param name="classCommand">The class command</param>
        /// <param name="method">The method under test</param>
        /// <returns>The set of <see cref="ITestCommand"/> objects</returns>
        public static IEnumerable<ITestCommand> Make(ITestClassCommand classCommand,
            IMethodInfo method)
        {
            foreach (var testCommand in classCommand.EnumerateTestCommands(method))
            {
                ITestCommand wrappedCommand = testCommand;

                // Timeout (if they have one) -> Capture -> Timed -> Lifetime (if we need an instance) -> BeforeAfter

                wrappedCommand = new BeforeAfterCommand(wrappedCommand, method.MethodInfo);

                if (testCommand.ShouldCreateInstance)
                    wrappedCommand = new LifetimeCommand(wrappedCommand, method);

                wrappedCommand = new TimedCommand(wrappedCommand);
                wrappedCommand = new ExceptionAndOutputCaptureCommand(wrappedCommand, method);

                if (wrappedCommand.Timeout > 0)
                    wrappedCommand = new TimeoutCommand(wrappedCommand, wrappedCommand.Timeout, method);

                yield return wrappedCommand;
            }
        }
            public void ConsoleOutAndErrorAreReplacedDuringTestExecution()
            {
                TextWriter originalOut = Console.Out;
                TextWriter originalError = Console.Error;

                try
                {
                    TextWriter newOut = new StringWriter();
                    TextWriter newError = new StringWriter();
                    Console.SetOut(newOut);
                    Console.SetError(newError);
                    StubCommand cmd = new StubCommand();
                    var outputCmd = new ExceptionAndOutputCaptureCommand(cmd, null);

                    outputCmd.Execute(null);

                    Assert.Empty(newOut.ToString());
                    Assert.Empty(newError.ToString());
                }
                finally
                {
                    Console.SetOut(originalOut);
                    Console.SetError(originalError);
                }
            }
            public void ConsoleOutAndErrorAndTraceIsCapturedAndPlacedInMethodResult()
            {
                string expected = "Standard Output" + Environment.NewLine +
                                  "Standard Error" + Environment.NewLine +
                                  "Trace" + Environment.NewLine;

                StubCommand cmd = new StubCommand();
                var outputCmd = new ExceptionAndOutputCaptureCommand(cmd, null);

                MethodResult result = outputCmd.Execute(null);

                Assert.Equal(expected, result.Output);
            }
        public void ConsoleOutAndErrorAndTraceIsCapturedAndPlacedInMethodResult()
        {
            const string expected =
            @"Standard Output
            Standard Error
            Trace
            ";

            StubCommand cmd = new StubCommand();
            var outputCmd = new ExceptionAndOutputCaptureCommand(cmd, null);

            MethodResult result = outputCmd.Execute(null);

            Assert.Equal(expected, result.Output);
        }