Пример #1
0
 protected MethodResult(IMethodInfo method, string displayName)
     : this(method.Name,
            method.TypeName,
            displayName,
            MethodUtility.GetTraits(method))
 {
 }
Пример #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>
 /// Retrieves a list of the test methods from the test class.
 /// </summary>
 /// <param name="type">The type to be inspected</param>
 /// <returns>The test methods</returns>
 public static IEnumerable <IMethodInfo> GetTestMethods(ITypeInfo type)
 {
     foreach (IMethodInfo method in type.GetMethods())
     {
         if (MethodUtility.IsTest(method))
         {
             yield return(method);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Enumerates the test commands for a given test method in this test class.
        /// </summary>
        /// <param name="testMethod">The method under test</param>
        /// <returns>The test commands for the given test method</returns>
        public IEnumerable <ITestCommand> EnumerateTestCommands(IMethodInfo testMethod)
        {
            string skipReason = MethodUtility.GetSkipReason(testMethod);

            if (skipReason != null)
            {
                yield return(new SkipCommand(testMethod, MethodUtility.GetDisplayName(testMethod), skipReason));
            }
            else
            {
                foreach (ITestCommand command in MethodUtility.GetTestCommands(testMethod))
                {
                    yield return(new FixtureCommand(command, fixtures));
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FactCommand"/> class.
 /// </summary>
 /// <param name="method">The test method.</param>
 public FactCommand(IMethodInfo method)
     : base(method, MethodUtility.GetDisplayName(method), MethodUtility.GetTimeoutParameter(method))
 {
 }
Пример #6
0
 /// <summary>
 /// Determines if a given <see cref="IMethodInfo"/> refers to a test method.
 /// </summary>
 /// <param name="testMethod">The test method to validate</param>
 /// <returns>True if the method is a test method; false, otherwise</returns>
 public bool IsTestMethod(IMethodInfo testMethod)
 {
     return(MethodUtility.IsTest(testMethod));
 }
Пример #7
0
            public EnumerateTests(Executor executor, object _handler)
            {
                ExecutorCallback handler = ExecutorCallback.Wrap(_handler);

                XmlDocument doc = new XmlDocument();

                doc.LoadXml("<dummy/>");

                XmlNode assemblyNode = XmlUtility.AddElement(doc.ChildNodes[0], "assembly");

                XmlUtility.AddAttribute(assemblyNode, "name", executor.assemblyFilename);

                foreach (Type type in executor.assembly.GetExportedTypes())
                {
                    ITestClassCommand testClassCommand = TestClassCommandFactory.Make(type);

                    if (testClassCommand != null)
                    {
                        string typeName = type.FullName;

                        XmlNode classNode = XmlUtility.AddElement(assemblyNode, "class");
                        XmlUtility.AddAttribute(classNode, "name", typeName);

                        foreach (IMethodInfo method in testClassCommand.EnumerateTestMethods())
                        {
                            string methodName  = method.Name;
                            string displayName = null;

                            foreach (IAttributeInfo attr in method.GetCustomAttributes(typeof(FactAttribute)))
                            {
                                displayName = attr.GetPropertyValue <string>("Name");
                            }

                            XmlNode methodNode = XmlUtility.AddElement(classNode, "method");
                            XmlUtility.AddAttribute(methodNode, "name", displayName ?? typeName + "." + methodName);
                            XmlUtility.AddAttribute(methodNode, "type", typeName);
                            XmlUtility.AddAttribute(methodNode, "method", methodName);

                            string skipReason = MethodUtility.GetSkipReason(method);
                            if (skipReason != null)
                            {
                                XmlUtility.AddAttribute(methodNode, "skip", skipReason);
                            }

                            var traits = MethodUtility.GetTraits(method);
                            if (traits.Count > 0)
                            {
                                XmlNode traitsNode = XmlUtility.AddElement(methodNode, "traits");

                                traits.ForEach((name, value) =>
                                {
                                    XmlNode traitNode = XmlUtility.AddElement(traitsNode, "trait");
                                    XmlUtility.AddAttribute(traitNode, "name", name);
                                    XmlUtility.AddAttribute(traitNode, "value", value);
                                });
                            }
                        }
                    }
                }

                handler.Notify(assemblyNode.OuterXml);
            }