Пример #1
0
        private static void BuildTest(IAssemblyInfo assembly, Test parentTest, NUnit.Core.ITest nunitTest)
        {
            string           kind;
            ICodeElementInfo codeElement;

            switch (nunitTest.TestType)
            {
#if NUNIT248
            case @"Test Case":
#elif NUNIT253
            case @"NUnitTestMethod":
#elif NUNIT254TO10 || NUNITLATEST
            case @"TestMethod":
#else
#error "Unrecognized NUnit framework version."
#endif
                kind        = TestKinds.Test;
                codeElement = ParseTestCaseName(assembly, nunitTest.TestName.FullName);
                break;

#if NUNIT248
            case @"Test Fixture":
#elif NUNIT253
            case @"NUnitTestFixture":
#elif NUNIT254TO10 || NUNITLATEST
            case @"TestFixture":
#else
#error "Unrecognized NUnit framework version."
#endif
                kind        = TestKinds.Fixture;
                codeElement = ParseTestFixtureName(assembly, nunitTest.TestName.FullName);
                break;

#if NUNIT254TO10 || NUNITLATEST
            case @"ParameterizedTest":
                kind        = TestKinds.Suite;
                codeElement = ParseTestCaseName(assembly, nunitTest.TestName.FullName);
                break;

            case @"Namespace":
                kind        = TestKinds.Namespace;
                codeElement = parentTest.CodeElement;
                break;
#endif

            default:
                kind        = nunitTest.IsSuite ? TestKinds.Suite : TestKinds.Test;
                codeElement = parentTest.CodeElement;
                break;
            }

            // Build the test.
            NUnitTest test = new NUnitTest(nunitTest.TestName.Name, codeElement, nunitTest);
            test.Kind       = kind;
            test.IsTestCase = !nunitTest.IsSuite;

            PopulateMetadata(test);

            parentTest.AddChild(test);
            BuildTestChildren(assembly, test, nunitTest);
        }
Пример #2
0
        protected static void PopulateMetadata(NUnitTest test)
        {
            NUnit.Core.ITest nunitTest = test.Test;

            if (!String.IsNullOrEmpty(nunitTest.Description))
            {
                test.Metadata.Add(MetadataKeys.Description, nunitTest.Description);
            }

            if (!String.IsNullOrEmpty(nunitTest.IgnoreReason))
            {
                test.Metadata.Add(MetadataKeys.IgnoreReason, nunitTest.IgnoreReason);
            }

            if (nunitTest.Categories != null)
            {
                foreach (string category in nunitTest.Categories)
                {
                    if (!string.IsNullOrEmpty(category))
                    {
                        test.Metadata.Add(MetadataKeys.Category, category);
                    }
                }
            }

            if (nunitTest.Properties != null)
            {
                foreach (DictionaryEntry entry in nunitTest.Properties)
                {
                    if (entry.Key != null && entry.Value != null)
                    {
                        string keyString = entry.Key.ToString();
                        if (!keyString.StartsWith("_") && keyString.Length != 0)
                        {
                            ICollection values = entry.Value as ICollection;
                            if (values != null)
                            {
                                foreach (object value in values)
                                {
                                    if (value != null)
                                    {
                                        test.Metadata.Add(keyString, value.ToString());
                                    }
                                }
                            }
                            else
                            {
                                test.Metadata.Add(keyString, entry.Value.ToString());
                            }
                        }
                    }
                }
            }

            ICodeElementInfo codeElement = test.CodeElement;

            if (codeElement != null)
            {
                // Add documentation.
                string xmlDocumentation = codeElement.GetXmlDocumentation();
                if (xmlDocumentation != null)
                {
                    test.Metadata.Add(MetadataKeys.XmlDocumentation, xmlDocumentation);
                }
            }
        }
Пример #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="test">The NUnit test, or null if none.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is null.</exception>
 public NUnitTest(string name, ICodeElementInfo codeElement, NUnit.Core.ITest test)
     : base(name, codeElement)
 {
     this.test = test;
 }
Пример #4
0
 protected static void BuildTestChildren(IAssemblyInfo assembly, NUnitTest parentTest, NUnit.Core.ITest parentNUnitTest)
 {
     if (parentNUnitTest.Tests != null)
     {
         foreach (NUnit.Core.ITest childNUnitTest in parentNUnitTest.Tests)
         {
             BuildTest(assembly, parentTest, childNUnitTest);
         }
     }
 }
Пример #5
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="test">The NUnit test, or null if none.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is null.</exception>
 public NUnitTest(string name, ICodeElementInfo codeElement, NUnit.Core.ITest test)
     : base(name, codeElement)
 {
     this.test = test;
 }