public void FindSolutionFile() { Assert.AreEqual(true, CodeFactory.TryFindSolutionFile("Gu.Roslyn.Asserts.sln", out var sln)); Assert.AreEqual("Gu.Roslyn.Asserts.sln", sln.Name); sln = CodeFactory.FindSolutionFile("Gu.Roslyn.Asserts.sln"); Assert.AreEqual("Gu.Roslyn.Asserts.sln", sln.Name); }
public void SolutionFileNoErrorAnalyzer() { Assert.AreEqual(true, CodeFactory.TryFindSolutionFile("Gu.Roslyn.Asserts.sln", out var sln)); AnalyzerAssert.Valid <NoErrorAnalyzer>(sln); AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), sln); AnalyzerAssert.Valid(new NoErrorAnalyzer(), sln); }
public void SolutionNoErrorAnalyzer() { Assert.AreEqual(true, CodeFactory.TryFindSolutionFile("Gu.Roslyn.Asserts.sln", out var sln)); var solution = CodeFactory.CreateSolution(sln, new[] { new NoErrorAnalyzer() }, AnalyzerAssert.MetadataReferences); AnalyzerAssert.Valid <NoErrorAnalyzer>(solution); AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), solution); AnalyzerAssert.Valid(new NoErrorAnalyzer(), solution); }
public async Task AnalyzeSolutionFile() { Assert.AreEqual(true, CodeFactory.TryFindSolutionFile("Gu.Roslyn.Asserts.sln", out FileInfo solutionFile)); var diagnostics = await Analyze.GetDiagnosticsAsync(new FieldNameMustNotBeginWithUnderscore(), solutionFile, MetadataReferences) .ConfigureAwait(false); var expected = new[] { "ClassLibrary1Class1.cs(8,21): warning SA1309: Field '_value' must not begin with an underscore", "ClassLibrary2Class1.cs(8,21): warning SA1309: Field '_value' must not begin with an underscore", }; CollectionAssert.AreEquivalent(expected, diagnostics.SelectMany(x => x).Select(x => x.ToString())); }
public void CreateSolutionFromSolutionFile() { Assert.AreEqual(true, CodeFactory.TryFindSolutionFile("Gu.Roslyn.Asserts.sln", out var solutionFile)); var solution = CodeFactory.CreateSolution( solutionFile, new[] { new FieldNameMustNotBeginWithUnderscore(), }, CreateMetadataReferences(typeof(object))); var expectedProjects = new[] { "WpfApp1", "ClassLibrary1", "ClassLibrary2", "Gu.Roslyn.Asserts", "Gu.Roslyn.Asserts.Tests", "Gu.Roslyn.Asserts.Tests.WithMetadataReferencesAttribute", "Gu.Roslyn.Asserts.XUnit" }; 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); }