<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

using ReSharperFixieTestProvider;

namespace RemoteTestFinder
{
    public class TestFinder : MarshalByRefObject, ITestFinder
    {
        public FixieConventionInfo FindTests(string testAssemblyPath)
        {
            var appDomain = AppDomain.CurrentDomain;

            var testAssembly = Assembly.LoadFrom(testAssemblyPath);
            var conventionAssembly = testAssembly;
            var conventionTypes = testAssembly.GetExportedTypes().Where(IsConvention).ToArray();
            if (!conventionTypes.Any())
            {
                var fixieAssemblyPath = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "Fixie.dll");
                conventionAssembly = Assembly.LoadFrom(fixieAssemblyPath);
                conventionTypes = conventionAssembly.GetExportedTypes().Where(t => t.FullName == "Fixie.Conventions.DefaultConvention").ToArray();
            }

            var testClasses = new List<FixieConventionTestClass>();
            foreach (var conventionType in conventionTypes)
            {
                var convention = (dynamic)Activator.CreateInstance(conventionType);

                var classes = convention.Classes;
                if (classes != null)
                {
                    IEnumerable<Type> types = classes.Filter(testAssembly.GetExportedTypes());
                    foreach (var type in types)
                    {
                        var classInfo = new FixieConventionTestClass(type);

                        var methods = convention.Methods;
                        if (methods != null)
                        {
                            var filteredMethods = methods.Filter(type);
                            foreach (MethodInfo method in filteredMethods)
                                classInfo.AddTestMethod(method);
                        }

                        if (classInfo.HasTestMethods())
                            testClasses.Add(classInfo);
                    }
                }
            }
            // remove duplicates
            return new FixieConventionInfo(testClasses.Distinct());
        }

        private static bool IsConvention(Type type)
        {
            if (type.FullName == "System.Object")
                return false;

            if (type.FullName == "Fixie.Conventions.Convention")
                return true;

            return IsConvention(type.BaseType);
        }
    }
}
<commit_msg>Some code cleanup<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

using ReSharperFixieTestProvider;

namespace RemoteTestFinder
{
    public class TestFinder : MarshalByRefObject, ITestFinder
    {
        public FixieConventionInfo FindTests(string testAssemblyPath)
        {
            var testAssembly = Assembly.LoadFrom(testAssemblyPath);
            var conventionTypes = testAssembly.GetExportedTypes().Where(IsConvention).ToArray();
            if (!conventionTypes.Any())
            {
                var fixieAssemblyPath = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "Fixie.dll");
                var fixieAssembly = Assembly.LoadFrom(fixieAssemblyPath);
                conventionTypes = fixieAssembly.GetExportedTypes().Where(t => t.FullName == "Fixie.Conventions.DefaultConvention").ToArray();
            }

            var testClasses = new List<FixieConventionTestClass>();
            foreach (var conventionType in conventionTypes)
            {
                var convention = (dynamic)Activator.CreateInstance(conventionType);

                var classes = convention.Classes;
                if (classes != null)
                {
                    IEnumerable<Type> types = classes.Filter(testAssembly.GetExportedTypes());
                    foreach (var type in types)
                    {
                        var classInfo = new FixieConventionTestClass(type);

                        var methods = convention.Methods;
                        if (methods != null)
                        {
                            var filteredMethods = methods.Filter(type);
                            foreach (MethodInfo method in filteredMethods)
                                classInfo.AddTestMethod(method);
                        }

                        if (classInfo.HasTestMethods())
                            testClasses.Add(classInfo);
                    }
                }
            }
            // remove duplicates
            return new FixieConventionInfo(testClasses.Distinct());
        }

        private static bool IsConvention(Type type)
        {
            if (type.FullName == "System.Object")
                return false;

            if (type.FullName == "Fixie.Conventions.Convention")
                return true;

            return IsConvention(type.BaseType);
        }
    }
}

{'fraction_non_alphanumeric': 0.07893151235187788, 'fraction_numerical': 0.0, 'mean_word_length': 1.64050901378579, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4768718', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1117, 'n_words': 231}