Exemplo n.º 1
0
        private static List <IMetadataMethod> GetAllTestMethods(IMetadataTypeInfo typeInfo)
        {
            var list = new List <IMetadataMethod>();
            var map  = new OneToListMap <string, IMetadataMethod>();

            while (typeInfo != null)
            {
                foreach (IMetadataMethod method in typeInfo.GetMethods())
                {
                    if (!IsTestMethod(method))
                    {
                        continue;
                    }

                    if (map.ContainsKey(method.Name) && (method.IsVirtual))
                    {
                        bool hasOverride = false;
                        foreach (IMetadataMethod metadataMethod in map[method.Name])
                        {
                            if (metadataMethod.IsVirtual && !metadataMethod.IsNewSlot)
                            {
                                hasOverride = true;
                            }
                        }

                        if (hasOverride)
                        {
                            continue;
                        }
                    }

                    map.AddValue(method.Name, method);
                    list.Add(method);
                }

                IMetadataClassType baseType = typeInfo.Base;
                typeInfo = (baseType != null) ? baseType.Type : null;
            }

            return(list);
        }
Exemplo n.º 2
0
        private void ExploreType(IMetadataTypeInfo type, IMetadataAssembly assembly, CancellationToken cancellationToken)
        {
            InterruptableActivityCookie.CheckAndThrow();
            cancellationToken.ThrowIfCancellationRequested();

            if (type.IsAbstract && type.GetMethods().Any(method => !(method.IsAbstract || method.IsStatic)))
            {
                return;
            }

            var testMethods = GetAllTestMethods(type);

            foreach (var method in testMethods)
            {
                var typeName = myTypeNameCache.GetClrName(method.DeclaringType);
                var id       = string.Format("{0}.{1}", typeName, method.Name);

                var testElement = GetOrCreateTest(id, typeName, method.Name);
                myUnitTestCollector.OnUnitTestElement(testElement);
            }
        }
Exemplo n.º 3
0
 public IMetadataMethod[] GetMethods()
 {
     return(_metadataTypeInfo.GetMethods());
 }