public static void TryFind() { Assert.AreEqual(true, SolutionFile.TryFind("Gu.Roslyn.Asserts.sln", out var sln)); Assert.AreEqual("Gu.Roslyn.Asserts.sln", sln !.Name); sln = SolutionFile.Find("Gu.Roslyn.Asserts.sln"); Assert.AreEqual("Gu.Roslyn.Asserts.sln", sln.Name); }
public static void CreateSolutionFromSolutionFile() { Assert.AreEqual(true, SolutionFile.TryFind("Gu.Roslyn.Asserts.sln", out var solutionFile)); var solution = CodeFactory.CreateSolution( solutionFile !, new[] { new FieldNameMustNotBeginWithUnderscore(), }, CreateMetadataReferences(typeof(object))); var expectedProjects = new[] { "AstView", "WpfApp1", "ClassLibrary1", "ClassLibrary2", "Gu.Roslyn.Asserts", "Gu.Roslyn.Asserts.Analyzers", "Gu.Roslyn.Asserts.Analyzers.Tests", "Gu.Roslyn.Asserts.Analyzers.Vsix", "Gu.Roslyn.Asserts.Tests", "Gu.Roslyn.Asserts.Tests.Net472WithAttributes", "Gu.Roslyn.Asserts.Tests.NetCoreWithAttributes", }; CollectionAssert.AreEquivalent(expectedProjects, solution.Projects.Select(p => p.Name)); var expected = solutionFile !.Directory .EnumerateFiles("*.cs", SearchOption.AllDirectories) .Where(f => !f.DirectoryName.Contains(".vs")) .Where(f => !f.DirectoryName.Contains(".git")) .Where(f => !f.DirectoryName.Contains("bin")) .Where(f => !f.DirectoryName.Contains("obj")) .Select(f => f.Name) .Distinct() .OrderBy(x => x) .ToArray(); var actual = solution.Projects .SelectMany(p => p.Documents) .Select(d => d.Name) .Distinct() .OrderBy(x => x) .ToArray(); //// ReSharper disable UnusedVariable for debug. var expectedString = string.Join(Environment.NewLine, expected); var actualString = string.Join(Environment.NewLine, actual); //// ReSharper restore UnusedVariable CollectionAssert.AreEqual(expected, actual); }