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 ExceptionCaptureCommand(wrappedCommand, method);

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

                yield return(wrappedCommand);
            }
        }
示例#2
0
        public void BeforeThrowsAfterThrowsShouldResultInBeforeException()
        {
            MethodInfo         methodInfo = typeof(MultipleAttributeSpy).GetMethod("PassedTest");
            StubTestCommand    stub       = new StubTestCommand();
            BeforeAfterCommand command    = new BeforeAfterCommand(stub, methodInfo);

            BeforeAfterSpyAttribute.Reset();
            BeforeAfterSpyAttribute.beforeTestThrowCount = 2;
            BeforeAfterSpyAttribute.afterTestThrowCount  = 1;

            Assert.Throws <Exception>(() => command.Execute(new MultipleAttributeSpy()));
        }
示例#3
0
        public void MethodUnderTestProvidedToBeforeAfter()
        {
            MethodInfo         methodInfo = typeof(InstrumentedTestClass).GetMethod("PassedTest");
            StubTestCommand    stub       = new StubTestCommand();
            BeforeAfterCommand command    = new BeforeAfterCommand(stub, methodInfo);

            InstrumentedTestClass.Reset();

            command.Execute(new InstrumentedTestClass());

            Assert.Same(methodInfo, BeforeAfterSpyAttribute.beforeMethod);
            Assert.Same(methodInfo, BeforeAfterSpyAttribute.afterMethod);
        }
示例#4
0
        public void TestThrowsAfterThrowsShouldResultInTestException()
        {
            MethodInfo      methodInfo = typeof(MultipleAttributeSpy).GetMethod("PassedTest");
            StubTestCommand stub       = new StubTestCommand {
                ThrowsOnExecute = true
            };
            BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo);

            BeforeAfterSpyAttribute.Reset();
            BeforeAfterSpyAttribute.afterTestThrowCount = 1;

            Assert.Throws <Exception>(() => command.Execute(new InstrumentedTestClass()));
        }
示例#5
0
        public void MultipleBeforeAfterTestAttributesAllCalled()
        {
            MethodInfo         methodInfo = typeof(BeforeAfterDoubleSpy).GetMethod("PassedTest");
            StubTestCommand    stub       = new StubTestCommand();
            BeforeAfterCommand command    = new BeforeAfterCommand(stub, methodInfo);

            BeforeAfterDoubleSpy.Reset();

            command.Execute(new BeforeAfterDoubleSpy());

            Assert.Equal(2, BeforeAfterSpyAttribute.beforeTestCount);
            Assert.Equal(1, stub.ExecuteCount);
            Assert.Equal(2, BeforeAfterSpyAttribute.afterTestCount);
        }
示例#6
0
        public void VerifyBeforeAfterTestAttributeCalledOnce()
        {
            MethodInfo         method  = typeof(SimpleTestFixtureSpy).GetMethod("PassedTest");
            BeforeAfterCommand command = new BeforeAfterCommand(new FactCommand(Reflector.Wrap(method)), method);

            SimpleTestFixtureSpy.Reset();

            ITestResult result = command.Execute(new SimpleTestFixtureSpy());

            Assert.Equal(1, BeforeAfterSpyAttribute.beforeTestCount);
            Assert.Equal(1, BeforeAfterSpyAttribute.afterTestCount);
            Assert.Equal("ctor beforetest test aftertest ", SimpleTestFixtureSpy.callOrder);
            Assert.IsType <PassedResult>(result);
        }
示例#7
0
        public void MultipleBeforeTestsSecondThrows()
        {
            MethodInfo         methodInfo = typeof(MultipleAttributeSpy).GetMethod("PassedTest");
            StubTestCommand    stub       = new StubTestCommand();
            BeforeAfterCommand command    = new BeforeAfterCommand(stub, methodInfo);

            BeforeAfterSpyAttribute.Reset();
            BeforeAfterSpyAttribute.beforeTestThrowCount = 2;

            Assert.Throws <Exception>(() => command.Execute(new MultipleAttributeSpy()));

            Assert.Equal(2, BeforeAfterSpyAttribute.beforeTestCount);
            Assert.Equal(0, stub.ExecuteCount);
            Assert.Equal(1, BeforeAfterSpyAttribute.afterTestCount);
        }
示例#8
0
        public void AfterTestThrows()
        {
            MethodInfo         methodInfo = typeof(InstrumentedTestClass).GetMethod("PassedTest");
            StubTestCommand    stub       = new StubTestCommand();
            BeforeAfterCommand command    = new BeforeAfterCommand(stub, methodInfo);

            InstrumentedTestClass.Reset();
            BeforeAfterSpyAttribute.afterTestThrowCount = 1;

            Assert.Throws <AfterTestException>(() => command.Execute(new InstrumentedTestClass()));

            Assert.Equal(1, BeforeAfterSpyAttribute.beforeTestCount);
            Assert.Equal(1, stub.ExecuteCount);
            Assert.Equal(1, BeforeAfterSpyAttribute.afterTestCount);
        }
        public static IEnumerable <ITestCommand> Make(ITestClassCommand classCommand, IMethodInfo method)
        {
            foreach (var testCommand in classCommand.EnumerateTestCommands(method))
            {
                var wrappedCommand = testCommand;

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

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

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

                // Note that we don't use a TimeoutCommand - we'll let the Silverlight framework handle that

                yield return(wrappedCommand);
            }
        }