Exemplo n.º 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);
        }
Exemplo n.º 2
0
        protected IEnumerable <MethodResult> RunClass(Type typeUnderTest)
        {
            ITestClassCommand testClassCommand = new TestClassCommand(typeUnderTest);

            ClassResult classResult = TestClassCommandRunner.Execute(testClassCommand, testClassCommand.EnumerateTestMethods().ToList(),
                                                                     startCallback: null, resultCallback: null);

            return(classResult.Results.OfType <MethodResult>());
        }
Exemplo n.º 3
0
            public void CannotUseTestClassAsItsOwnFixture()
            {
                TestClassCommand command = new TestClassCommand(typeof(InvalidTestClassWithSelfFixture));

                ClassResult result = TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal(typeof(InvalidOperationException).FullName, result.ExceptionType);
                Assert.Equal(0, result.Results.Count);
            }
Exemplo n.º 4
0
            public void ClassResultContainsOneResultForEachTestMethod()
            {
                TestClassCommand command = new TestClassCommand();

                command.TypeUnderTest = Reflector.Wrap(typeof(Spy));

                ClassResult result = TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal(3, result.Results.Count);
            }
Exemplo n.º 5
0
            public void FixtureDataDisposeFailure_InvocationException()
            {
                TestClassCommand command = new TestClassCommand(typeof(DataDisposeFailureSpy));

                DataDisposeThrow.Exception = new TargetInvocationException(new Exception());

                ClassResult result = TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal("System.Reflection.TargetInvocationException", result.ExceptionType);
            }
Exemplo n.º 6
0
            public void TestsCanBePrivateMethods()
            {
                TestClassCommand command = new TestClassCommand();

                command.TypeUnderTest = Reflector.Wrap(typeof(PrivateSpy));
                PrivateSpy.Reset();

                TestClassCommandRunner.Execute(command, null, null, null);

                Assert.True(PrivateSpy.WasRun);
            }
Exemplo n.º 7
0
            public void FixtureDataConstructorFailure_InvocationException()
            {
                TestClassCommand command = new TestClassCommand();

                command.TypeUnderTest   = Reflector.Wrap(typeof(DataCtorFailureSpy));
                DataCtorThrow.Exception = new TargetInvocationException(new Exception());

                ClassResult result = TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal("System.Reflection.TargetInvocationException", result.ExceptionType);
            }
Exemplo n.º 8
0
            public void RandomizerUsedToDetermineTestOrder()
            {
                RandomSpy        randomizer = new RandomSpy();
                TestClassCommand command    = new TestClassCommand(typeof(OrderingSpy));

                command.Randomizer = randomizer;

                TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal(OrderingSpy.TestMethodCount, randomizer.Next__Count);
            }
Exemplo n.º 9
0
            public void SettingSkipReasonGeneratesSkipCommand()
            {
                MethodInfo       method       = typeof(ClassWithSkippedTest).GetMethod("SkippedTest");
                TestClassCommand classCommand = new TestClassCommand(typeof(ClassWithSkippedTest));

                var commands = new List <ITestCommand>(classCommand.EnumerateTestCommands(Reflector.Wrap(method)));

                ITestCommand command     = Assert.Single(commands);
                SkipCommand  skipCommand = Assert.IsType <SkipCommand>(command);

                Assert.Equal("My Skip Reason", skipCommand.Reason);
            }
Exemplo n.º 10
0
        public static IEnumerable <MethodResult> Run(Type featureDefinition)
        {
            var feature = new TestClassCommand(featureDefinition);

            MethodResult[] results = null;
            var            thread  = new Thread(() => results =
                                                    TestClassCommandRunner.Execute(feature, feature.EnumerateTestMethods().ToList(), startCallback: null, resultCallback: null).Results
                                                    .OfType <MethodResult>().ToArray());

            thread.Start();
            thread.Join();
            return(results);
        }
Exemplo n.º 11
0
            public void CtorFailure()
            {
                TestClassCommand command = new TestClassCommand();

                command.TypeUnderTest = Reflector.Wrap(typeof(CtorFailureSpy));
                CtorFailureSpy.Reset();
                CtorFailureSpy.dummyTestCalled = 0;

                TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal(1, CtorFailureSpy.dataCtorCalled);
                Assert.Equal(1, CtorFailureSpy.ctorCalled);
                Assert.Equal(0, CtorFailureSpy.dummyTestCalled);
                Assert.Equal(0, CtorFailureSpy.disposeCalled);
                Assert.Equal(1, CtorFailureSpy.dataDisposeCalled);
            }
Exemplo n.º 12
0
            public void DisposeFailure()
            {
                TestClassCommand command = new TestClassCommand();

                command.TypeUnderTest = Reflector.Wrap(typeof(DisposeFailureSpy));
                DisposeFailureSpy.Reset();
                DisposeFailureSpy.dummyTestCalled = 0;

                TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal(1, DisposeFailureSpy.dataCtorCalled);
                Assert.Equal(1, DisposeFailureSpy.ctorCalled);
                Assert.Equal(1, DisposeFailureSpy.dummyTestCalled);
                Assert.Equal(1, DisposeFailureSpy.disposeCalled);
                Assert.Equal(1, DisposeFailureSpy.dataDisposeCalled);
                Assert.Equal("ctorData ctor setFixture dispose disposeData ", DisposeFailureSpy.callOrder);
            }
Exemplo n.º 13
0
        public IMessageSinkMessage[] Run(Type feature)
        {
            var command = new TestClassCommand(feature);

            IMessageSinkMessage[] results = null;
            var thread = new Thread(() => results = TestClassCommandRunner
                                                    .Execute(command, command.EnumerateTestMethods().ToList(), null, null)
                                                    .Results
                                                    .Select(Map)
                                                    .Where(message => message != null)
                                                    .ToArray());

            thread.Start();
            thread.Join();

            return(results);
        }
Exemplo n.º 14
0
            public void FixtureDataDisposeFailure()
            {
                TestClassCommand command = new TestClassCommand(typeof(DataDisposeFailureSpy));

                DataDisposeFailureSpy.Reset();
                DataDisposeFailureSpy.dummyTestCalled = 0;
                DataDisposeThrow.Exception            = new Exception();

                ClassResult result = TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal(1, DataDisposeFailureSpy.dataCtorCalled);
                Assert.Equal(1, DataDisposeFailureSpy.ctorCalled);
                Assert.Equal(1, DataDisposeFailureSpy.dummyTestCalled);
                Assert.Equal(1, DataDisposeFailureSpy.disposeCalled);
                Assert.Equal(1, DataDisposeFailureSpy.dataDisposeCalled);
                Assert.Equal("ctorData ctor setFixture dispose disposeData ", DataDisposeFailureSpy.callOrder);
                Assert.NotNull(result.Message);
                Assert.Equal("System.Exception", result.ExceptionType);
            }
Exemplo n.º 15
0
            public void TestMethodCounters()
            {
                TestClassCommand command = new TestClassCommand();

                command.TypeUnderTest = Reflector.Wrap(typeof(InstrumentedTestClass));
                InstrumentedTestClass.Reset();
                InstrumentedTestClass.passedTestCalled = 0;
                InstrumentedTestClass.failedTestCalled = 0;
                InstrumentedTestClass.skipTestCalled   = 0;
                InstrumentedTestClass.nonTestCalled    = 0;

                TestClassCommandRunner.Execute(command, null, null, null);

                Assert.Equal(1, InstrumentedTestClass.dataCtorCalled);
                Assert.Equal(2, InstrumentedTestClass.ctorCalled);                  // Two non-skipped tests, the skipped test does not create an instance
                Assert.Equal(1, InstrumentedTestClass.passedTestCalled);
                Assert.Equal(1, InstrumentedTestClass.failedTestCalled);
                Assert.Equal(0, InstrumentedTestClass.skipTestCalled);
                Assert.Equal(0, InstrumentedTestClass.nonTestCalled);
                Assert.Equal(2, InstrumentedTestClass.disposeCalled);
                Assert.Equal(1, InstrumentedTestClass.dataDisposeCalled);
                Assert.Equal("ctorData ctor setFixture dispose ctor setFixture dispose disposeData ", InstrumentedTestClass.callOrder);
            }
        public void Initialize()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            foreach (Type type in assembly.GetTypes())
            {
                TestFixtureAttribute fixtureAttribute = type.GetCustomAttribute <TestFixtureAttribute>();
                if (fixtureAttribute == null)
                {
                    continue;
                }

                object           fixtureInstance = Activator.CreateInstance(type);
                TestClassCommand classCommand    = new TestClassCommand(fixtureInstance);

                foreach (MethodInfo method in type.GetMethods())
                {
                    TestAttribute testAttribute = method.GetCustomAttribute <TestAttribute>();
                    if (testAttribute == null)
                    {
                        continue;
                    }

                    TestMethodCommand methodCommand = new TestMethodCommand(method)
                    {
                        Iterations     = testAttribute.Iterations,
                        PartitionCount = testAttribute.PartitionCount
                    };

                    string methodName = method.Name.Replace("Tests", string.Empty).Replace("Test", string.Empty).ToLower();
                    classCommand.AddTestMethodCommand(methodName, methodCommand);
                }

                testClassCommands.Add(type.Name.ToLower(), classCommand);
            }
        }
Exemplo n.º 17
0
 public StubTestClassCommand(Type typeUnderTest)
 {
     this.typeUnderTest = Reflector.Wrap(typeUnderTest);
     testClassCommand   = new TestClassCommand(typeUnderTest);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Creates an instace of the <see cref="IocTestClassCommand"/>.
 /// </summary>
 public IocTestClassCommand()
 {
     _testClassCommand = new TestClassCommand();
 }