Skip to content

Commit c51ff74

Browse files
authored
Merge pull request #5 from d1820/private-methods-hint
Fixed private member analyzer alert
2 parents 16e5ec4 + 41fdeeb commit c51ff74

55 files changed

Lines changed: 1344 additions & 569 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CodeDocumentor.Test/ClassUnitTests.cs

Lines changed: 0 additions & 126 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ConsoleApp4
6+
{
7+
partial class ClassTester
8+
{
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ConsoleApp4
6+
{
7+
/// <summary>
8+
/// The class tester.
9+
/// </summary>
10+
partial class ClassTester
11+
{
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ConsoleApp4
6+
{
7+
/// <inheritdoc/>
8+
public class ClassTesterInherit
9+
{
10+
}
11+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.IO;
3+
using CodeDocumentor.Vsix2022;
4+
using Microsoft.CodeAnalysis;
5+
using Microsoft.CodeAnalysis.CodeFixes;
6+
using Microsoft.CodeAnalysis.Diagnostics;
7+
8+
using Xunit;
9+
10+
namespace CodeDocumentor.Test
11+
{
12+
/// <summary>
13+
/// The class unit test.
14+
/// </summary>
15+
16+
public partial class ClassUnitTest : CodeFixVerifier, IClassFixture<TestFixure>
17+
{
18+
private readonly TestFixure _fixture;
19+
20+
public ClassUnitTest(TestFixure fixture)
21+
{
22+
_fixture = fixture;
23+
TestFixture.BuildOptionsPageGrid();
24+
CodeDocumentorPackage.Options.DefaultDiagnosticSeverity = DiagnosticSeverity.Warning;
25+
}
26+
27+
/// <summary>
28+
/// Nos diagnostics show.
29+
/// </summary>
30+
/// <param name="testCode">The test code.</param>
31+
[Theory]
32+
[InlineData("")]
33+
[InlineData("ClassTesterInheritDoc.cs")]
34+
public void NoDiagnosticsShow(string testCode)
35+
{
36+
var file = string.IsNullOrEmpty(testCode)? testCode : _fixture.LoadTestFile($@"./Classes/{testCode}");
37+
this.VerifyCSharpDiagnostic(file);
38+
}
39+
40+
/// <summary>
41+
/// Shows diagnostic and fix.
42+
/// </summary>
43+
/// <param name="testCode">The test code.</param>
44+
/// <param name="fixCode">The fix code.</param>
45+
/// <param name="line">The line.</param>
46+
/// <param name="column">The column.</param>
47+
[Theory]
48+
[InlineData("ClassTester.cs", "ClassTesterFix.cs", 7, 19, TestFixure.DIAG_TYPE_PRIVATE)]
49+
[InlineData("PublicClassTester.cs", "PublicClassTesterFix.cs", 7, 26, TestFixure.DIAG_TYPE_PUBLIC)]
50+
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType)
51+
{
52+
var fix = _fixture.LoadTestFile($@"./Classes/{fixCode}");
53+
var test = _fixture.LoadTestFile($@"./Classes/{testCode}");
54+
55+
var expected = new DiagnosticResult
56+
{
57+
Id = ClassAnalyzerSettings.DiagnosticId,
58+
Message = ClassAnalyzerSettings.MessageFormat,
59+
Severity = DiagnosticSeverity.Warning,
60+
Locations =
61+
new[] {
62+
new DiagnosticResultLocation("Test0.cs", line, column)
63+
}
64+
};
65+
66+
this.VerifyCSharpDiagnostic(test, diagType, expected);
67+
68+
this.VerifyCSharpFix(test, fix, diagType);
69+
}
70+
71+
/// <summary>
72+
/// Gets c sharp code fix provider.
73+
/// </summary>
74+
/// <returns>A CodeFixProvider.</returns>
75+
protected override CodeFixProvider GetCSharpCodeFixProvider()
76+
{
77+
return new ClassCodeFixProvider();
78+
}
79+
80+
/// <summary>
81+
/// Gets c sharp diagnostic analyzer.
82+
/// </summary>
83+
/// <returns>A DiagnosticAnalyzer.</returns>
84+
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagType)
85+
{
86+
if (diagType == TestFixure.DIAG_TYPE_PRIVATE)
87+
{
88+
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
89+
return new NonPublicClassAnalyzer();
90+
}
91+
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
92+
return new ClassAnalyzer();
93+
}
94+
}
95+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ConsoleApp4
6+
{
7+
public partial class PublicClassTester
8+
{
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ConsoleApp4
6+
{
7+
/// <summary>
8+
/// The public class tester.
9+
/// </summary>
10+
public partial class PublicClassTester
11+
{
12+
}
13+
}

CodeDocumentor.Test/CodeDocumentor.Test.csproj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44
<TargetFramework>net472</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<Compile Remove="Classes\ClassTester.cs" />
9+
<Compile Remove="Classes\ClassTesterFix.cs" />
10+
<Compile Remove="Classes\ClassTesterInheritDoc.cs" />
11+
<Compile Remove="Classes\PublicClassTester.cs" />
12+
<Compile Remove="Classes\PublicClassTesterFix.cs" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Include="Classes\ClassTester.cs">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Include="Classes\ClassTesterFix.cs">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Include="Classes\ClassTesterInheritDoc.cs">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
<None Include="Classes\PublicClassTester.cs">
26+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
27+
</None>
28+
<None Include="Classes\PublicClassTesterFix.cs">
29+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
30+
</None>
31+
</ItemGroup>
32+
733
<ItemGroup>
834
<PackageReference Include="FluentAssertions" Version="6.3.0" />
935
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">

0 commit comments

Comments
 (0)