public void Combine_EmptyWithEmpty()
        {
            var configBuilder1 = new AnalyzerConfigBuilder();
            var configBuilder2 = new AnalyzerConfigBuilder();

            configBuilder1.Combine(configBuilder2);

            configBuilder1.IsEnabled.Should().BeNull();
            configBuilder1.IssueKind.Should().BeNull();
            configBuilder1.InfoImportance.Should().BeNull();
            configBuilder1.ChildCanDependOnParentImplicitly.Should().BeNull();
            configBuilder1.AllowRules.Should().HaveCount(0);
            configBuilder1.DisallowRules.Should().HaveCount(0);
            configBuilder1.VisibleTypesByNamespace.Should().HaveCount(0);
            configBuilder1.MaxIssueCount.Should().BeNull();
        }
        public void SetMethods_WithNonNullValues_OverwriteProperties()
        {
            var configBuilder = new AnalyzerConfigBuilder()
                                .SetInheritanceDepth(9)
                                .SetIsEnabled(true)
                                .SetIssueKind(IssueKind.Error)
                                .SetInfoImportance(Importance.High)
                                .SetChildCanDependOnParentImplicitly(true)
                                .SetMaxIssueCount(42);

            configBuilder.InheritanceDepth.Should().Be(9);
            configBuilder.IsEnabled.Should().Be(true);
            configBuilder.IssueKind.Should().Be(IssueKind.Error);
            configBuilder.InfoImportance.Should().Be(Importance.High);
            configBuilder.ChildCanDependOnParentImplicitly.Should().Be(true);
            configBuilder.MaxIssueCount.Should().Be(42);
        }
        public void AddDisallowRule_Works()
        {
            var configBuilder = new AnalyzerConfigBuilder()
                                .AddDisallowRule(new NamespaceDependencyRule("N1", "N2"))
                                .AddDisallowRule(new NamespaceDependencyRule("N3", "N4"));

            configBuilder
            .AddDisallowRule(new NamespaceDependencyRule("N3", "N4"))
            .AddDisallowRule(new NamespaceDependencyRule("N5", "N6"));

            configBuilder.DisallowRules.ShouldBeEquivalentTo(
                new HashSet <NamespaceDependencyRule>
            {
                new NamespaceDependencyRule("N1", "N2"),
                new NamespaceDependencyRule("N3", "N4"),
                new NamespaceDependencyRule("N5", "N6"),
            });
        }
        public void Combine_NonEmptyWithNonEmpty()
        {
            var configBuilder1 = new AnalyzerConfigBuilder()
                                 .SetIsEnabled(false)
                                 .SetIssueKind(IssueKind.Info)
                                 .SetInfoImportance(Importance.Low)
                                 .SetChildCanDependOnParentImplicitly(false)
                                 .AddAllowRule(new NamespaceDependencyRule("N1", "N2"), new TypeNameSet {
                "T1"
            })
                                 .AddDisallowRule(new NamespaceDependencyRule("N3", "N4"))
                                 .AddVisibleTypesByNamespace(new Namespace("N5"), new TypeNameSet {
                "T2"
            })
                                 .SetMaxIssueCount(43);

            var configBuilder2 = new AnalyzerConfigBuilder()
                                 .SetIsEnabled(true)
                                 .SetIssueKind(IssueKind.Error)
                                 .SetInfoImportance(Importance.High)
                                 .SetChildCanDependOnParentImplicitly(true)
                                 .AddAllowRule(new NamespaceDependencyRule("N6", "N7"), new TypeNameSet {
                "T3"
            })
                                 .AddDisallowRule(new NamespaceDependencyRule("N8", "N9"))
                                 .AddVisibleTypesByNamespace(new Namespace("N10"), new TypeNameSet {
                "T4"
            })
                                 .SetMaxIssueCount(42);

            configBuilder1.Combine(configBuilder2);

            configBuilder1.IsEnabled.Should().Be(true);
            configBuilder1.IssueKind.Should().Be(IssueKind.Error);
            configBuilder1.InfoImportance.Should().Be(Importance.High);
            configBuilder1.ChildCanDependOnParentImplicitly.Should().Be(true);
            configBuilder1.AllowRules.Should().HaveCount(2);
            configBuilder1.DisallowRules.Should().HaveCount(2);
            configBuilder1.VisibleTypesByNamespace.Should().HaveCount(2);
            configBuilder1.MaxIssueCount.Should().Be(42);
        }
Exemple #5
0
        public void ToAnalyzerConfig_ConvertsPathsToRooted()
        {
            var configBuilder = new AnalyzerConfigBuilder()
                                .AddSourcePathExclusionPatterns(new[]
            {
                @"*.cs",
                @"**\*.cs",
                @"D:\*.cs",
                @"\\a folder\b.cs",
                @"\*.cs"
            })
                                .MakePathsRooted(@"C:\folder with space");

            var config = configBuilder.ToAnalyzerConfig();

            config.SourcePathExclusionPatterns.Should().BeEquivalentTo(
                @"C:\folder with space\*.cs",
                @"C:\folder with space\**\*.cs",
                @"D:\*.cs",
                @"\\a folder\b.cs",
                @"\*.cs"
                );
        }