예제 #1
0
        public List <string> FindTestAssembliesIn(string solutionFilePath)
        {
            var projectFiles   = GetProjectFilePaths(solutionFilePath);
            var testAssemblies = new List <Tuple <int, string> >();

            foreach (var file in projectFiles)
            {
                using (var stream = GetFileSystem().OpenFile(file, FileMode.Open,
                                                             FileAccess.Read, FileShare.ReadWrite))
                {
                    var project            = MsBuildProject.Load(stream);
                    var isTestProjectScore = GetIsTestProjectScore(project);
                    if (isTestProjectScore > 0)
                    {
                        var assemblyFilePath = project.GetAssemblyFilePath(file);
                        testAssemblies.Add(new Tuple <int, string>(
                                               isTestProjectScore, assemblyFilePath));
                    }
                }
            }

            // return assemblies with highest score first
            return((from tuple in testAssemblies
                    orderby tuple.Item1 descending,
                    tuple.Item2 ascending         // keep things deterministic for testing
                    select tuple.Item2).ToList());
        }
예제 #2
0
        private int GetIsTestProjectScore(MsBuildProject project)
        {
            // TODO: may want to group this information with other info about supported test frameworks
            var numberOfReferencedTestAssemblies =
                SupportedAssemblies.Where(item => IsTestFrameworkReferenced(project, item))
                .Count();
            var score = numberOfReferencedTestAssemblies * 10;

            // no supported test framework, abort
            if (score == 0)
            {
                return(0);
            }

            var assemblyName = project.GetAssemblyName();

            if (assemblyName.Contains("UnitTest"))
            {
                score += 5;
            }
            else if (assemblyName.Contains("Test"))
            {
                score += 3;
            }

            if (assemblyName.Contains("Spec"))
            {
                score += 2; // more likely to have non-test project with Spec in it?
            }
            return(score);
        }
예제 #3
0
        private int GetIsTestProjectScore(MsBuildProject project)
        {
            // TODO: may want to group this information with other info about supported test frameworks
            var numberOfReferencedTestAssemblies =
                    SupportedAssemblies.Where(item => IsTestFrameworkReferenced(project, item))
                            .Count();
            var score = numberOfReferencedTestAssemblies * 10;

            // no supported test framework, abort
            if (score == 0)
                return 0;

            var assemblyName = project.GetAssemblyName();
            if (assemblyName.Contains("UnitTest"))
                score += 5;
            else if (assemblyName.Contains("Test"))
                score += 3;

            if (assemblyName.Contains("Spec"))
                score += 2; // more likely to have non-test project with Spec in it?

            return score;
        }
예제 #4
0
 private static bool IsTestFrameworkReferenced(MsBuildProject project, string frameworkAssemblyFilename)
 {
     return project.GetLocalAssemblyRefs().Any(info =>
         info.EndsWith(frameworkAssemblyFilename, StringComparison.OrdinalIgnoreCase));
 }
예제 #5
0
 private static bool IsTestFrameworkReferenced(MsBuildProject project, string frameworkAssemblyFilename)
 {
     return(project.GetLocalAssemblyRefs().Any(info =>
                                               info.EndsWith(frameworkAssemblyFilename, StringComparison.OrdinalIgnoreCase)));
 }