Exemplo n.º 1
0
        private Test TryGetTypeTest(ITypeInfo type, Test assemblyTest)
        {
            Test typeTest;

            if (!typeTests.TryGetValue(type, out typeTest))
            {
                try
                {
                    XunitTypeInfoAdapter xunitTypeInfo = new XunitTypeInfoAdapter(type);
                    ITestClassCommand    command       = TestClassCommandFactory.Make(xunitTypeInfo);
                    if (command != null)
                    {
                        typeTest = CreateTypeTest(xunitTypeInfo, command);
                    }
                }
                catch (Exception ex)
                {
                    TestModel.AddAnnotation(new Annotation(AnnotationType.Error, type, "An exception was thrown while exploring an xUnit.net test type.", ex));
                }

                if (typeTest != null)
                {
                    assemblyTest.AddChild(typeTest);
                    typeTests.Add(type, typeTest);
                }
            }

            return(typeTest);
        }
        public void RunWithClassReturnsTypeToRunWith()
        {
            ITestClassCommand command = TestClassCommandFactory.Make(typeof(MyRunWithTestClass));

            Assert.IsType <MyRunWith>(command);
            Assert.Equal(typeof(MyRunWithTestClass), command.TypeUnderTest.Type);
        }
        public void NoTestMethodsShouldReturnNull()
        {
            Type type = typeof(StubClass);
            ITestClassCommand command = TestClassCommandFactory.Make(type);

            Assert.Null(command);
        }
        private IUnitTestElement ProcessTestMethod(IMethod method, IList<IUnitTestElement> subElements)
        {
            var type = method.GetContainingType();
            var @class = type as IClass;
            if (type == null || @class == null)
                return null;

            var typeInfo = @class.AsTypeInfo();
            if (@class.IsAbstract && TypeUtility.ContainsTestMethods(typeInfo))
                return ProcessTestMethodInAbstractClass(method, subElements);

            if (!IsValidTestClass(@class))
                return null;

            var command = TestClassCommandFactory.Make(typeInfo);
            if (command == null)
                return null;

            var testClassElement = classes[type];
            if (testClassElement == null)
                return null;

            var methodInfo = method.AsMethodInfo(typeInfo);
            if (command.IsTestMethod(methodInfo))
            {
                var clrTypeName = type.GetClrName();
                return unitTestElementFactory.GetOrCreateTestMethod(project, testClassElement, clrTypeName, method.ShortName, 
                    MethodUtility.GetSkipReason(methodInfo), methodInfo.GetTraits(), false);
            }

            return null;
        }
        public void StubTestClassMakesTestClassCommand()
        {
            Type testClassType        = typeof(StubTestClass);
            ITestClassCommand command = TestClassCommandFactory.Make(testClassType);

            Assert.IsType <TestClassCommand>(command);
            Assert.Equal(typeof(StubTestClass), command.TypeUnderTest.Type);
        }
Exemplo n.º 6
0
        public XmlNode RunTests(string type, List <string> methods, Predicate <XmlNode> callback)
        {
            var testClass   = testRun.Classes.Single(c => c.Typename == type);
            var methodInfos = (from m in methods
                               select testClass.GetMethod(m)).ToList();
            Predicate <XmlNode> nonNullCallback = node => node == null || callback(node);

            var testClassCommand = TestClassCommandFactory.Make(testClass);

            SetRandomizer(testClassCommand);

            var classResult = TestClassCommandRunner.Execute(testClassCommand,
                                                             methodInfos,
                                                             command => nonNullCallback(command.ToStartXml()),
                                                             result => nonNullCallback(ToXml(resultInspector(result))));

            return(ToXml(classResult));
        }
        public void AllStagesOfTestLifetimeExistOnSameThread()
        {
            Type testClassType        = typeof(ThreadLifetimeSpy);
            ITestClassCommand command = TestClassCommandFactory.Make(testClassType);

            ThreadFixtureSpy.Reset();
            ThreadLifetimeSpy.Reset();

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

            // The fixture data may take place on a different thread from the test, but that's
            // an acceptable limitation, as the fixture should have no knowledge of the test
            // class that it's attached to. This means that fixtures cannot use thread local
            // storage, but there's no reason for them to need that anyway, as their own data
            // remains the same throughout all the tests for a given class.

            Assert.NotEqual(-1, ThreadFixtureSpy.CtorThreadId);
            Assert.Equal(ThreadFixtureSpy.CtorThreadId, ThreadFixtureSpy.DisposeThreadId);

            Assert.NotEqual(-1, ThreadLifetimeSpy.CtorThreadId);
            Assert.Equal(ThreadLifetimeSpy.CtorThreadId, ThreadLifetimeSpy.DisposeThreadId);
            Assert.Equal(ThreadLifetimeSpy.CtorThreadId, ThreadLifetimeSpy.TestThreadId);
        }
Exemplo n.º 8
0
        public void TimeoutCommandMustUseReplacementBeginInvoke()
        {
            Type testClassType        = typeof(TestClassCommandFactoryTests.ThreadLifetimeSpy);
            ITestClassCommand command = TestClassCommandFactory.Make(testClassType);

            TestClassCommandFactoryTests.ThreadFixtureSpy.Reset();
            TestClassCommandFactoryTests.ThreadLifetimeSpy.Reset();

            try
            {
                TestClassCommandRunner.Execute(command, null, null, null);
            }
            catch (NotSupportedException e)
            {
                // If this test fails, you need to modify TimeoutCommand.Execute to use
                // working versions of delegate's BeginInvoke/EndInvoke. You should replace
                // with WorkingBeginInvoke and WorkingEndInvoke. WorkingEndInvoke's return
                // value will require casting to MethodResult.
                // The asynchronous methods on Invoke are compiler generated, and supposed
                // to be implemented by the runtime. Silverlight doesn't implement them.
                // I don't really know why.
                throw new AsyncDelegateMethodsNotSupportedException("TimeoutCommand.Execute", e);
            }
        }
 public TestClassCommandTypeAdapter()
 {
     testClassCommand = TestClassCommandFactory.Make(typeof(TClassUnderTest));
 }
Exemplo n.º 10
0
        public void RunWithForInvalidTestClassCommandReturnsNull()
        {
            ITestClassCommand command = TestClassCommandFactory.Make(typeof(MyInvalidRunWithTestClass));

            Assert.Null(command);
        }
Exemplo n.º 11
0
        public void AbstractTestClassReturnsNull()
        {
            ITestClassCommand command = TestClassCommandFactory.Make(typeof(AbstractTestClass));

            Assert.Null(command);
        }