Bari.Plugins.VsCore.VisualStudio.SolutionName.ReadableSlnNameGenerator.GetName C# (CSharp) Method

GetName() public method

Generates a file name for a VS solution file which will contain the given set of projects.
public GetName ( IEnumerable projects ) : string
projects IEnumerable Set of projects to be included in the SLN file
return string
        public string GetName(IEnumerable<Project> projects)
        {
            var prjs = projects.ToList();

            var matches = analyzer.GetCoveredModules(prjs).ToList();
            if (matches.Count > 0 && matches.All(m => !m.Partial))
            {
                bool? allTests = AllHasTests(matches);

                if (allTests.HasValue)
                {
                    var productName = analyzer.GetProductName(matches.Select(m => m.Module));
                    if (productName != null)
                    {
                        // this covers a product
                        return GetNameBasedOnProduct(productName, allTests.Value);
                    }
                    else if (matches.Count <= MaxModuleCount)
                    {
                        return GetNameBasedOnMultipleModules(matches.Select(m => m.Module), allTests.Value);
                    }
                    // otherwise: many modules -> fallback
                }
                // otherwise: contains modules both with tests included and without included -> fallback
            }
            // otherwise: there are partial matches -> fallback

            if (prjs.Count == 1)
            {
                // Single project
                return GetNameForSingleProject(prjs[0]);
            }
            else
            {
                return fallbackGenerator.GetName(prjs);
            }
        }

Usage Example

        public void Issue90_SingleProjectProduct()
        {
            var s = new Suite(new TestFileSystemDirectory("z"));
            var m = s.GetModule("m");
            var p = m.GetProject("p");
            var prod = s.GetProduct("prod");
            prod.AddModule(m);

            var sc = new DefaultSuiteContentsAnalyzer(s);
            var g = new ReadableSlnNameGenerator(fallback.Object, sc);
            var name = g.GetName(new[] { p });
            name.Should().Be("prod");
        }