示例#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
            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);
            }