Esempio n. 1
0
        public IEnumerable <MethodInfo> EnumerateTestMethods(Assembly assembly, ITestMessageSink messageSink)
        {
            if (!_assemblyFilterConvention.IsValidTestAssembly(assembly))
            {
                yield break;
            }

            var visited = new HashSet <Type>();
            var types   = assembly.GetTypes();

            foreach (var type in types.OrderByDescending(t => t.IsAbstract))
            {
                if (visited.Contains(type))
                {
                    continue;
                }

                visited.Add(type);

                if (!_testClassFilterConvention.IsValidTestClass(type))
                {
                    continue;
                }

                var methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
                foreach (var method in methods)
                {
                    if (method.DeclaringType == typeof(object))
                    {
                        continue;
                    }
                    if (!_testMethodFilterConvention.IsValidTestMethod(type, method))
                    {
                        continue;
                    }
                    messageSink?.LogInfo($"Found test: {type.FullName}.{method.Name}");
                    yield return(method);
                }
            }
        }
Esempio n. 2
0
        public static IEnumerable <MethodInfo> EnumerateTestMethods(this string source, IEnumerable <ITestFeature> features, ITestMessageSink messageSink)
        {
            var methods = new HashSet <MethodInfo>();

            if (ShouldIgnoreAssembly(source))
            {
                return(methods);
            }

            try
            {
                var assembly = Assembly.LoadFile(source);

                if (assembly == typeof(TestKitchenTestDiscoverer).Assembly)
                {
                    return(methods);
                }

                if (assembly.IsDynamic)
                {
                    return(methods);
                }

                messageSink.LogInfo($"Probing source: {source}");

                foreach (var feature in features)
                {
                    foreach (var method in feature.EnumerateTestMethods(assembly, messageSink))
                    {
                        methods.Add(method);
                    }
                }
            }
            catch (Exception e)
            {
                messageSink.LogError(e.ToString());
                throw;
            }

            return(methods);
        }
Esempio n. 3
0
 public TestContext(TestFixture fixture, ITestMessageSink messageSink)
 {
     _fixture     = fixture;
     _messageSink = messageSink;
     _random      = new Random();
 }