public int Process(
            NUnitTestProject inputProject,
            IList <SplitRule> rules,
            string assembliesPath,
            string outputPath
            )
        {
            AssemblyResolver.Setup(assembliesPath);
            int processedAssemblies = 0;

            IDictionary <string, NUnitTestProject> outputProjects = new SortedDictionary <string, NUnitTestProject>(
                rules.ToDictionary(rule => rule.TestProjectName, rule => new NUnitTestProject(inputProject.ActiveConfig))
                );

            foreach (var assemblyItem in inputProject.Assemblies)
            {
                string assemblyName = assemblyItem.Key;

                var      sw           = new DebugStopwatch("2.Load Assembly");
                string   assemblyPath = Path.Combine(assembliesPath, assemblyName);
                Assembly assembly     = AssemblyResolver.GetAssemblyOrNull(assemblyPath);
                sw.Dispose();

                if (assembly != null)
                {
                    IEnumerable <SplitRule> appliedRules = m_testAssemblyScanner.Scan(assembly, rules);

                    foreach (var rule in appliedRules)
                    {
                        outputProjects[rule.TestProjectName].Add(assemblyName, assemblyItem.Value);
                    }
                    processedAssemblies++;
                }
            }

            using (new DebugStopwatch("6.Save NunitProjects")) {
                foreach (var outputProject in outputProjects.Where(proj => proj.Value.Assemblies.Any()))
                {
                    string outputProjectPath = Path.Combine(outputPath, outputProject.Key);
                    outputProject.Value.Save(outputProjectPath);
                }
            }

            using (IndentedTextWriter writer = new IndentedTextWriter(Console.Error, "\t")) {
                DebugStopwatch.Report(writer);
            }

            return(processedAssemblies);
        }
コード例 #2
0
        private static int Run(Arguments args)
        {
            string path = args.AssembliesPath.FullName;

            SetupAssemblyResolver(path);

            Console.WriteLine("Loading assemblies from '{0}'", path);

            var sw = new DebugStopwatch("1.LoadAssemblies");
            IEnumerable <Assembly> assemblies = args.AssembliesPath
                                                .EnumerateFiles("*.dll", SearchOption.TopDirectoryOnly)
                                                .Where(file => !args.ExcludedAssemblies.Contains(file.Name))
                                                .Select(GetAssemblyOrNull)
                                                .Where(ass => ass != null)
                                                .Where(NUnitFrameworkReferenceChecker.ReferencesNUnitFramework);

            sw.Dispose();

            int violations = 0;

            TestAssemblyScanner scanner = new TestAssemblyScanner(
                new IAssemblyValidator[] {
                new ProhibitedAssemblyCategoryValidator(args.ProhibitedAssemblyCategories),
                new RequaredCategoryValidator(args.RequiredCategories)
            });

            using (IndentedTextWriter writer = new IndentedTextWriter(Console.Error, "\t")) {
                foreach (Assembly assembly in assemblies)
                {
                    TestAssembly testAssembly = scanner.Scan(assembly);
                    violations += Report(testAssembly, writer);
                }

                DebugStopwatch.Report(writer);
            }

            return(violations);
        }