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()));
    }
    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);
    }
Exemple #3
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()));
        }
    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);
    }
Exemple #5
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);
        }
Exemple #6
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()));
        }
    public void BeforeTestThrows()
    {
        MethodInfo methodInfo = typeof(InstrumentedTestClass).GetMethod("PassedTest");
        StubTestCommand stub = new StubTestCommand();
        BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo);
        InstrumentedTestClass.Reset();
        BeforeAfterSpyAttribute.beforeTestThrowCount = 1;

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

        Assert.Equal(1, BeforeAfterSpyAttribute.beforeTestCount);
        Assert.Equal(0, stub.ExecuteCount);
        Assert.Equal(0, BeforeAfterSpyAttribute.afterTestCount);
    }
Exemple #8
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);
        }
    public void MultipleAfterTestsSecondThrows()
    {
        MethodInfo methodInfo = typeof(MultipleAttributeSpy).GetMethod("PassedTest");
        StubTestCommand stub = new StubTestCommand();
        BeforeAfterCommand command = new BeforeAfterCommand(stub, methodInfo);
        BeforeAfterSpyAttribute.Reset();
        BeforeAfterSpyAttribute.afterTestThrowCount = 2;

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

        Assert.Equal(3, BeforeAfterSpyAttribute.beforeTestCount);
        Assert.Equal(1, stub.ExecuteCount);
        Assert.Equal(3, BeforeAfterSpyAttribute.afterTestCount);
        Assert.Equal(2, ex.AfterExceptions.Count);
    }
Exemple #10
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);
        }
Exemple #11
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 void DoesNotIncludeCreationCommandWhenTestCommandSaysNotToCreateInstance()
    {
        MethodInfo method = typeof(TestCommandFactoryTests).GetMethod("PublicTestMethod");
        List<ITestCommand> testCommands = new List<ITestCommand>();
        StubTestClassCommand classCommand = new StubTestClassCommand();
        StubTestCommand testCommand = new StubTestCommand();
        testCommand.ShouldCreateInstance__Result = false;
        testCommands.Add(testCommand);
        classCommand.EnumerateTestCommands__Result = testCommands;

        List<ITestCommand> result = new List<ITestCommand>(TestCommandFactory.Make(classCommand, Reflector.Wrap(method)));

        Assert.Same(method, classCommand.EnumerateTestCommands_TestMethod.MethodInfo);
        Assert.Equal(testCommands.Count, result.Count);
        var timedCommand = Assert.IsType<TimedCommand>(result[0]);
        var captureCommand = Assert.IsType<ExceptionAndOutputCaptureCommand>(timedCommand.InnerCommand);
        var beforeAfterCommand = Assert.IsType<BeforeAfterCommand>(captureCommand.InnerCommand);
        Assert.Same(testCommands[0], beforeAfterCommand.InnerCommand);
    }
Exemple #13
0
        public void DoesNotIncludeCreationCommandWhenTestCommandSaysNotToCreateInstance()
        {
            MethodInfo           method       = typeof(TestCommandFactoryTests).GetMethod("PublicTestMethod");
            List <ITestCommand>  testCommands = new List <ITestCommand>();
            StubTestClassCommand classCommand = new StubTestClassCommand();
            StubTestCommand      testCommand  = new StubTestCommand();

            testCommand.ShouldCreateInstance__Result = false;
            testCommands.Add(testCommand);
            classCommand.EnumerateTestCommands__Result = testCommands;

            List <ITestCommand> result = new List <ITestCommand>(TestCommandFactory.Make(classCommand, Reflector.Wrap(method)));

            Assert.Same(method, classCommand.EnumerateTestCommands_TestMethod.MethodInfo);
            Assert.Equal(testCommands.Count, result.Count);
            var timedCommand       = Assert.IsType <TimedCommand>(result[0]);
            var captureCommand     = Assert.IsType <ExceptionAndOutputCaptureCommand>(timedCommand.InnerCommand);
            var beforeAfterCommand = Assert.IsType <BeforeAfterCommand>(captureCommand.InnerCommand);

            Assert.Same(testCommands[0], beforeAfterCommand.InnerCommand);
        }
    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()));
    }