예제 #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);
        }
예제 #2
0
        private static XunitTest CreateMethodTest(XunitTypeInfoAdapter typeInfo, XunitMethodInfoAdapter methodInfo)
        {
            XunitTest methodTest = new XunitTest(methodInfo.Name, methodInfo.Target, typeInfo, methodInfo);

            methodTest.Kind       = TestKinds.Test;
            methodTest.IsTestCase = true;

            // Add skip reason.
            if (XunitMethodUtility.IsSkip(methodInfo))
            {
                string skipReason = XunitMethodUtility.GetSkipReason(methodInfo);
                if (skipReason != null)
                {
                    methodTest.Metadata.SetValue(MetadataKeys.IgnoreReason, skipReason);
                }
            }

            // Add traits.
            if (XunitMethodUtility.HasTraits(methodInfo))
            {
                XunitMethodUtility.GetTraits(methodInfo).ForEach((key, value) =>
                                                                 methodTest.Metadata.Add(key ?? @"", value ?? @""));
            }

            // Add XML documentation.
            string xmlDocumentation = methodInfo.Target.GetXmlDocumentation();

            if (xmlDocumentation != null)
            {
                methodTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }

            return(methodTest);
        }
예제 #3
0
        /// <summary>
        /// Initializes a test initially without a parent.
        /// </summary>
        /// <param name="name">The name of the component.</param>
        /// <param name="codeElement">The point of definition, or null if none.</param>
        /// <param name="typeInfo">The Xunit test type information.</param>
        /// <param name="methodInfo">The Xunit test method information, or null if none.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> or <paramref name="typeInfo"/> is null.</exception>
        public XunitTest(string name, ICodeElementInfo codeElement, XunitTypeInfoAdapter typeInfo, XunitMethodInfoAdapter methodInfo)
            : base(name, codeElement)
        {
            if (typeInfo == null)
                throw new ArgumentNullException(@"typeInfo");

            this.typeInfo = typeInfo;
            this.methodInfo = methodInfo;
        }
예제 #4
0
        /// <summary>
        /// Initializes a test initially without a parent.
        /// </summary>
        /// <param name="name">The name of the component.</param>
        /// <param name="codeElement">The point of definition, or null if none.</param>
        /// <param name="typeInfo">The Xunit test type information.</param>
        /// <param name="methodInfo">The Xunit test method information, or null if none.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> or <paramref name="typeInfo"/> is null.</exception>
        public XunitTest(string name, ICodeElementInfo codeElement, XunitTypeInfoAdapter typeInfo, XunitMethodInfoAdapter methodInfo)
            : base(name, codeElement)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException(@"typeInfo");
            }

            this.typeInfo   = typeInfo;
            this.methodInfo = methodInfo;
        }
예제 #5
0
        private static TestResult RunTestFixture(ITestCommand testCommand, XunitTypeInfoAdapter typeInfo,
                                                 TestStep parentTestStep)
        {
            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);

            XunitTestClassCommand testClassCommand;

            try
            {
                testClassCommand = XunitTestClassCommandFactory.Make(typeInfo);
            }
            catch (Exception ex)
            {
                // Xunit can throw exceptions when making commands if the test is malformed.
                testContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                return(testContext.FinishStep(TestOutcome.Failed, null));
            }

            return(RunTestClassCommandAndFinishStep(testCommand, testContext, testClassCommand));
        }
예제 #6
0
        private static XunitTest CreateTypeTest(XunitTypeInfoAdapter typeInfo, ITestClassCommand testClassCommand)
        {
            XunitTest typeTest = new XunitTest(typeInfo.Target.Name, typeInfo.Target, typeInfo, null);

            typeTest.Kind = TestKinds.Fixture;

            foreach (XunitMethodInfoAdapter methodInfo in testClassCommand.EnumerateTestMethods())
            {
                typeTest.AddChild(CreateMethodTest(typeInfo, methodInfo));
            }

            // Add XML documentation.
            string xmlDocumentation = typeInfo.Target.GetXmlDocumentation();

            if (xmlDocumentation != null)
            {
                typeTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);
            }

            return(typeTest);
        }
예제 #7
0
        private static XunitTest CreateMethodTest(XunitTypeInfoAdapter typeInfo, XunitMethodInfoAdapter methodInfo)
        {
            XunitTest methodTest = new XunitTest(methodInfo.Name, methodInfo.Target, typeInfo, methodInfo);
            methodTest.Kind = TestKinds.Test;
            methodTest.IsTestCase = true;

            // Add skip reason.
            if (XunitMethodUtility.IsSkip(methodInfo))
            {
                string skipReason = XunitMethodUtility.GetSkipReason(methodInfo);
                if (skipReason != null)
                    methodTest.Metadata.SetValue(MetadataKeys.IgnoreReason, skipReason);
            }

            // Add traits.
            if (XunitMethodUtility.HasTraits(methodInfo))
            {
                XunitMethodUtility.GetTraits(methodInfo).ForEach((key, value) =>
                    methodTest.Metadata.Add(key ?? @"", value ?? @""));
            }

            // Add XML documentation.
            string xmlDocumentation = methodInfo.Target.GetXmlDocumentation();
            if (xmlDocumentation != null)
                methodTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);

            return methodTest;
        }
예제 #8
0
        private static XunitTest CreateTypeTest(XunitTypeInfoAdapter typeInfo, ITestClassCommand testClassCommand)
        {
            XunitTest typeTest = new XunitTest(typeInfo.Target.Name, typeInfo.Target, typeInfo, null);
            typeTest.Kind = TestKinds.Fixture;

            foreach (XunitMethodInfoAdapter methodInfo in testClassCommand.EnumerateTestMethods())
                typeTest.AddChild(CreateMethodTest(typeInfo, methodInfo));

            // Add XML documentation.
            string xmlDocumentation = typeInfo.Target.GetXmlDocumentation();
            if (xmlDocumentation != null)
                typeTest.Metadata.SetValue(MetadataKeys.XmlDocumentation, xmlDocumentation);

            return typeTest;
        }
예제 #9
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;
        }
예제 #10
0
        private static TestResult RunTestFixture(ITestCommand testCommand, XunitTypeInfoAdapter typeInfo,
            TestStep parentTestStep)
        {
            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);

            XunitTestClassCommand testClassCommand;
            try
            {
                testClassCommand = XunitTestClassCommandFactory.Make(typeInfo);
            }
            catch (Exception ex)
            {
                // Xunit can throw exceptions when making commands if the test is malformed.
                testContext.LogWriter.Failures.WriteException(ex, "Internal Error");
                return testContext.FinishStep(TestOutcome.Failed, null);
            }

            return RunTestClassCommandAndFinishStep(testCommand, testContext, testClassCommand);
        }