Example #1
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()));
        }
Example #2
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);
        }
Example #3
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()));
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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);
        }