Exemplo n.º 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()));
    }
Exemplo n.º 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);
    }
Exemplo n.º 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()));
        }
Exemplo n.º 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);
    }
Exemplo n.º 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);
        }
Exemplo n.º 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()));
        }
Exemplo n.º 7
0
    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);
    }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
    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);
    }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 12
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);
    }
Exemplo n.º 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);
        }
Exemplo n.º 14
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()));
    }