Example #1
0
 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);
 }
Example #2
0
        public static void ParseInfo()
        {
            var file     = SolutionFile.Find("Gu.Roslyn.Asserts.sln");
            var sln      = SolutionFile.ParseInfo(file);
            var expected = new[]
            {
                "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",
                "AstView",
                "WpfApp1",
                "ClassLibrary2",
                "ClassLibrary1",
            };

            CollectionAssert.AreEquivalent(expected, sln.Projects.Select(x => x.Name));
            var assertsProject = sln.Projects.Single(x => x.Name == "Gu.Roslyn.Asserts");

            var analyzersProject = sln.Projects.Single(x => x.Name == "Gu.Roslyn.Asserts.Analyzers");

            CollectionAssert.IsEmpty(analyzersProject.ProjectReferences);
            var testProject = sln.Projects.Single(x => x.Name == "Gu.Roslyn.Asserts.Tests");

            CollectionAssert.AreEqual(new[] { assertsProject.Id }, testProject.ProjectReferences.Select(x => x.ProjectId).ToArray());
        }
        public void SolutionNoErrorAnalyzer()
        {
            var sln      = SolutionFile.Find("Gu.Roslyn.Asserts.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);
        }
Example #4
0
        public static async Task Solution()
        {
            var analyzer  = new FieldNameMustNotBeginWithUnderscore();
            var sln       = CodeFactory.CreateSolution(SolutionFile.Find("Gu.Roslyn.Asserts.sln"));
            var benchmark = await Benchmark.CreateAsync(sln, analyzer).ConfigureAwait(false);

            CollectionAssert.IsNotEmpty(benchmark.SyntaxNodeActions);
            CollectionAssert.AllItemsAreInstancesOfType(benchmark.SyntaxNodeActions.Select(x => x.Context.Node), typeof(FieldDeclarationSyntax));
            CollectionAssert.AllItemsAreInstancesOfType(benchmark.SyntaxNodeActions.Select(x => x.Context.ContainingSymbol), typeof(IFieldSymbol));
            Assert.AreSame(analyzer, benchmark.Analyzer);
            benchmark.Run();
            benchmark.Run();
        }
            public void CreateSolutionFromSolutionFileAddsDependencies()
            {
                var sln = CodeFactory.CreateSolution(
                    SolutionFile.Find("Gu.Roslyn.Asserts.sln"),
                    new[] { new FieldNameMustNotBeginWithUnderscore() },
                    CreateMetadataReferences(typeof(object)));
                var assertsProject = sln.Projects.Single(x => x.Name == "Gu.Roslyn.Asserts");

                CollectionAssert.IsEmpty(assertsProject.AllProjectReferences);

                var testProject = sln.Projects.Single(x => x.Name == "Gu.Roslyn.Asserts.Tests");

                CollectionAssert.AreEqual(new[] { assertsProject.Id }, testProject.AllProjectReferences.Select(x => x.ProjectId).ToArray());
            }
Example #6
0
        public static async Task GetDiagnosticsAsyncSolutionFile()
        {
            var solutionFile = SolutionFile.Find("Gu.Roslyn.Asserts.sln");
            var diagnostics  = await Analyze.GetDiagnosticsAsync(new FieldNameMustNotBeginWithUnderscore(), solutionFile, MetadataReferences)
                               .ConfigureAwait(false);

            var expected = new[]
            {
                "ClassLibrary1Class1.cs(6,21): warning SA1309: Field '_value' must not begin with an underscore",
                "ClassLibrary2Class1.cs(6,21): warning SA1309: Field '_value' must not begin with an underscore",
            };

            CollectionAssert.AreEquivalent(expected, diagnostics.SelectMany(x => x).Select(SkipDirectory));
        }
        public void SolutionFileNoErrorAnalyzer()
        {
            var sln      = SolutionFile.Find("Gu.Roslyn.Asserts.sln");
            var analyzer = new NoErrorAnalyzer();

            AnalyzerAssert.Valid <NoErrorAnalyzer>(sln);
            AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), sln);
            AnalyzerAssert.Valid(analyzer, sln);

            var descriptor = NoErrorAnalyzer.Descriptor;

            AnalyzerAssert.Valid <NoErrorAnalyzer>(descriptor, sln);
            AnalyzerAssert.Valid(typeof(NoErrorAnalyzer), descriptor, sln);
            AnalyzerAssert.Valid(analyzer, descriptor, sln);
        }
Example #8
0
        public static void Find()
        {
            var sln = SolutionFile.Find("Gu.Roslyn.Asserts.sln");

            Assert.AreEqual("Gu.Roslyn.Asserts.sln", sln.Name);
        }