Example #1
0
        public void ExceptionsThrownWhenSettingFixturesProperlyReported()
        {
            var testClassCommand = new TestClassCommand(Reflector.Wrap(typeof(SetFixtureFailureSpy)));

            testClassCommand.ClassStart();

            var method       = testClassCommand.TypeUnderTest.GetMethod("Method");
            var testCommands = TestCommandFactory.Make(testClassCommand, method);

            var methodResult = testCommands.Single().Execute(null);

            // If you get a test failure here, then there's another missing instance of "throw;" where there
            // is a call to RethrowWithNoStackTraceLoss. Specifically, for this test, it's in FixtureCommand.Execute
            // Again, it should look like:
            //
            // catch (TargetInvocationException ex)
            // {
            //     ExceptionUtility.RethrowWithNoStackTraceLoss(ex.InnerException);
            //     throw;  // <---- New line
            // }
            if (!(methodResult is FailedResult))
            {
                throw new ExceptionNotBeingRethrownException("FixtureCommand.Execute");
            }

            Assert.Equal("System.Reflection.TargetInvocationException", ((FailedResult)methodResult).ExceptionType);
        }
Example #2
0
        public void IncludesTimeoutCommandWhenTestCommandSaysTheresATimeout()
        {
            MethodInfo           method       = typeof(TestCommandFactoryTests).GetMethod("PublicTestMethod");
            List <ITestCommand>  testCommands = new List <ITestCommand>();
            StubTestClassCommand classCommand = new StubTestClassCommand();

            testCommands.Add(new StubTestCommand {
                Timeout__Result = 153
            });
            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);
            Assert.IsType <TimeoutCommand>(result[0]);
        }
Example #3
0
        public void CallsTestClassCommandToGetTestCommandsAndWrapsTheminTimedCommands()
        {
            MethodInfo           method       = typeof(TestCommandFactoryTests).GetMethod("PublicTestMethod");
            List <ITestCommand>  testCommands = new List <ITestCommand>();
            StubTestClassCommand classCommand = new StubTestClassCommand();

            testCommands.Add(new StubTestCommand());
            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 lifetimeCommand    = Assert.IsType <LifetimeCommand>(captureCommand.InnerCommand);
            var beforeAfterCommand = Assert.IsType <BeforeAfterCommand>(lifetimeCommand.InnerCommand);

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