private static int Run(Arguments args) { TestAssemblyScanner scanner = new TestAssemblyScanner(); NUnitTestProjectProcessor processor = new NUnitTestProjectProcessor(scanner); string assembliesPath = args.AssembliesPath.FullName; Console.WriteLine("Loading assemblies from '{0}'", assembliesPath); var sw = new DebugStopwatch("1.Load NunitProject"); string inputProjectPath = File.Exists(args.InputNUnitProject) ? args.InputNUnitProject : Path.Combine(assembliesPath, args.InputNUnitProject); if (!File.Exists(inputProjectPath)) { Console.Error.WriteLine($"File Not Found: {args.InputNUnitProject}"); return(-102); } NUnitTestProject inputProject = NUnitTestProject.LoadFromFile(inputProjectPath); sw.Dispose(); int processedAssemblies = processor.Process( inputProject, args.SplitRules, assembliesPath, Path.GetDirectoryName(inputProjectPath) ); Console.WriteLine("NUnitTestProjectSplitter finished. Processed {0} assemblies", processedAssemblies); return(0); }
public TestAssembly Scan(Assembly assembly) { var sw = new DebugStopwatch("2.GetAssemblyCategories"); List <string> assemblyCategories = assembly .GetCustomAttributes <CategoryAttribute>() .Select(attr => attr.Name) .ToList(); sw.Dispose(); sw = new DebugStopwatch("3.LoadTestFixturs"); List <TestFixture> fixtures = assembly.GetTypes() .Select(LoadTestFixtureOrNull) .Where(f => f != null) .ToList(); sw.Dispose(); TestAssembly testAssembly = new TestAssembly( assembly, assemblyCategories, fixtures ); foreach (var validator in m_validators) { using (new DebugStopwatch($"4.{validator.GetType().Name}")) { validator.Validate(testAssembly); } } return(testAssembly); }
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); }
public IEnumerable <SplitRule> Scan(Assembly assembly, IList <SplitRule> splitRules) { ISet <SplitRule> appliedRules = new HashSet <SplitRule>(); var sw = new DebugStopwatch("3.GetAssemblyCategories"); List <string> assemblyCategories = assembly .GetCustomAttributes(typeof(CategoryAttribute)) .OfType <CategoryAttribute>() .Select(attr => attr.Name) .ToList(); sw.Dispose(); sw = new DebugStopwatch("4.LoadTestFixturs"); List <TestFixture> fixtures = assembly.GetTypes() .Select(LoadTestFixtureOrNull) .Where(f => f != null) .ToList(); sw.Dispose(); using (new DebugStopwatch("5.SplitRules.Check")) { foreach (var fixture in fixtures) { foreach (var method in fixture.TestMethods) { ISet <string> testCategories = method .GetCustomAttributes <CategoryAttribute>(true) .Select(attr => attr.Name) .ToHashSet(StringComparer.OrdinalIgnoreCase); testCategories.UnionWith(assemblyCategories); testCategories.UnionWith(fixture.TestFixtureCategories); foreach (var splitRule in splitRules) { if (!appliedRules.Contains(splitRule) && splitRule.RequiredCategories.All(c => testCategories.Contains(c)) && splitRule.ProhibitedCategories.All(c => !testCategories.Contains(c))) { appliedRules.Add(splitRule); } } } } } return(appliedRules); }
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); }