/// <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);
            }
        }
示例#2
0
    public void TestFinshedOnTimePassedResult()
    {
        Mock<ITestCommand> testCommand = new Mock<ITestCommand>();
        testCommand.Setup(tc => tc.Execute(null))
                   .Returns(new PassedResult(GetMethodInfo(), null));
        TimeoutCommand command = new TimeoutCommand(testCommand.Object, 10000, GetMethodInfo());

        MethodResult result = command.Execute(null);

        Assert.IsType<PassedResult>(result);
    }
示例#3
0
    public void TestTookTooLongFailedResult()
    {
        Mock<ITestCommand> testCommand = new Mock<ITestCommand>();
        testCommand.Setup(tc => tc.Execute(null))
                   .Callback<object>(_ => Thread.Sleep(500));
        TimeoutCommand command = new TimeoutCommand(testCommand.Object, 20, GetMethodInfo());

        MethodResult result = command.Execute(null);

        FailedResult failedResult = Assert.IsType<FailedResult>(result);
        Assert.Equal("Test execution time exceeded: 20ms", failedResult.Message);
    }
示例#4
0
        /// <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;
            }
        }