示例#1
0
        private static Dictionary <Type, SortedDictionary <Type, Delegate> > FindAllGenerators()
        {
            var result     = new Dictionary <Type, SortedDictionary <Type, Delegate> >();
            var generators = TypeDiscoverer.GetAllTypes()
                             .SelectMany(t => t.GetMethods())
                             .Where(IsGeneratorMethod)
                             .Select(GetGenerators);
            var typeComparer = new CustomComparer <Type>
                               (
                (left, right) => string.Compare(left.Name, right.Name, StringComparison.Ordinal)
                               );

            foreach (var(returnType, generatorType, @delegate) in generators)
            {
                if (@delegate == null)
                {
                    continue;
                }

                if (result.TryGetValue(returnType, out var dictionary))
                {
                    dictionary.TryAdd(generatorType, @delegate);
                }
                else
                {
                    dictionary = new SortedDictionary <Type, Delegate>(typeComparer)
                    {
                        { generatorType, @delegate }
                    };
                    result.Add(returnType, dictionary);
                }
            }

            return(result);
        }
示例#2
0
 private static IEnumerable <Test> GetAllTests(string[] ignoredCategories)
 {
     return(TypeDiscoverer.GetAllTypes().Where(type => type.HasAttribute <TestFixtureAttribute>()).Select(type => new TestFixture(type)).Where(testFixture => testFixture.TestFixtureAttribute != null && !testFixture.Categories.Overlaps(ignoredCategories)).SelectMany(testFixture => testFixture.Type.GetMethods()).Select(method => new TestMethod(method)).Where(testMethod => testMethod.TestAttribute != null && !testMethod.Categories.Overlaps(ignoredCategories)).Select(testMethod => new Test(testMethod)));
 }