Skip to content

Commit b7a6dbc

Browse files
authored
Merge pull request #9 from d1820/bug-fixes
bug fixes
2 parents c51ff74 + 122af24 commit b7a6dbc

19 files changed

Lines changed: 231 additions & 40 deletions

CodeDocumentor.Test/Classes/ClassUnitTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void NoDiagnosticsShow(string testCode)
4646
/// <param name="column">The column.</param>
4747
[Theory]
4848
[InlineData("ClassTester.cs", "ClassTesterFix.cs", 7, 19, TestFixure.DIAG_TYPE_PRIVATE)]
49-
[InlineData("PublicClassTester.cs", "PublicClassTesterFix.cs", 7, 26, TestFixure.DIAG_TYPE_PUBLIC)]
49+
[InlineData("PublicClassTester.cs", "PublicClassTesterFix.cs", 7, 26, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
5050
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType)
5151
{
5252
var fix = _fixture.LoadTestFile($@"./Classes/{fixCode}");
@@ -88,7 +88,10 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagTyp
8888
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
8989
return new NonPublicClassAnalyzer();
9090
}
91-
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
91+
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
92+
{
93+
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
94+
}
9295
return new ClassAnalyzer();
9396
}
9497
}

CodeDocumentor.Test/ConstructorUnitTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ public void NoDiagnosticsShow(string testCode)
186186
/// <param name="line">The line.</param>
187187
/// <param name="column">The column.</param>
188188
[Theory]
189-
[InlineData(PublicConstructorTestCode, PublicContructorTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PUBLIC)]
189+
[InlineData(PublicConstructorTestCode, PublicContructorTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
190190
[InlineData(PrivateConstructorTestCode, PrivateContructorTestFixCode, 10, 11, TestFixure.DIAG_TYPE_PRIVATE)]
191-
[InlineData(PublicConstructorWithBooleanParameterTestCode, PublicContructorWithBooleanParameterTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PUBLIC)]
191+
[InlineData(PublicConstructorWithBooleanParameterTestCode, PublicContructorWithBooleanParameterTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
192192
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType)
193193
{
194194
var expected = new DiagnosticResult
@@ -227,7 +227,10 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagTyp
227227
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
228228
return new NonPublicConstructorAnalyzer();
229229
}
230-
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
230+
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
231+
{
232+
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
233+
}
231234
return new ConstructorAnalyzer();
232235
}
233236
}

CodeDocumentor.Test/EnumUnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
9393
}
9494
};
9595

96-
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
96+
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY, expected);
9797

98-
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
98+
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY);
9999
}
100100

101101
/// <summary>

CodeDocumentor.Test/FieldUnitTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
126126
}
127127
};
128128

129-
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
129+
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY, expected);
130130

131-
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
131+
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY);
132132
}
133133

134134
/// <summary>
@@ -151,7 +151,10 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagTyp
151151
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
152152
return new NonPublicFieldAnalyzer();
153153
}
154-
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
154+
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
155+
{
156+
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
157+
}
155158
return new FieldAnalyzer();
156159
}
157160
}

CodeDocumentor.Test/InterfaceUnitTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
9393
}
9494
};
9595

96-
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
96+
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY, expected);
9797

98-
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
98+
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY);
9999
}
100100

101101
/// <summary>

CodeDocumentor.Test/MethodUnitTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
606606
}
607607
};
608608

609-
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
609+
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY, expected);
610610

611-
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
611+
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC_ONLY);
612612
}
613613

614614
/// <summary>
@@ -631,7 +631,10 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagTyp
631631
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
632632
return new NonPublicMethodAnalyzer();
633633
}
634-
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
634+
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
635+
{
636+
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
637+
}
635638
return new MethodAnalyzer();
636639
}
637640

CodeDocumentor.Test/PropertyUnitTests.cs

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,80 @@ public class PropertyTester
309309
}";
310310

311311

312+
313+
/// <summary>
314+
/// The public property test code.
315+
/// </summary>
316+
private const string PublicPropertyInterfaceTestCode = @"
317+
using System;
318+
using System.Collections.Generic;
319+
using System.Text;
320+
321+
namespace ConsoleApp4
322+
{
323+
public interface PropertyTester
324+
{
325+
public string PersonName => ""Person Name"";
326+
}
327+
}";
328+
329+
/// <summary>
330+
/// The public property test fix code.
331+
/// </summary>
332+
private const string PublicPropertyInterfaceTestFixCode = @"
333+
using System;
334+
using System.Collections.Generic;
335+
using System.Text;
336+
337+
namespace ConsoleApp4
338+
{
339+
public interface PropertyTester
340+
{
341+
/// <summary>
342+
/// Gets the person name.
343+
/// </summary>
344+
public string PersonName => ""Person Name"";
345+
}
346+
}";
347+
348+
349+
350+
351+
/// <summary>
352+
/// The public property test code.
353+
/// </summary>
354+
private const string PrivatePropertyInterfaceTestCode = @"
355+
using System;
356+
using System.Collections.Generic;
357+
using System.Text;
358+
359+
namespace ConsoleApp4
360+
{
361+
public interface PropertyTester
362+
{
363+
string PersonName => ""Person Name"";
364+
}
365+
}";
366+
367+
/// <summary>
368+
/// The public property test fix code.
369+
/// </summary>
370+
private const string PrivatePropertyInterfaceTestFixCode = @"
371+
using System;
372+
using System.Collections.Generic;
373+
using System.Text;
374+
375+
namespace ConsoleApp4
376+
{
377+
public interface PropertyTester
378+
{
379+
/// <summary>
380+
/// Gets the person name.
381+
/// </summary>
382+
string PersonName => ""Person Name"";
383+
}
384+
}";
385+
312386
}
313387
/// <summary>
314388
/// The property unit test.
@@ -344,15 +418,17 @@ public void NoDiagnosticsShow(string testCode)
344418
/// <param name="line">The line.</param>
345419
/// <param name="column">The column.</param>
346420
[Theory]
347-
[InlineData(PropertyWithGetterSetterTestCode, PropertyWithGetterSetterTestFixCode, 10, 17)]
348-
[InlineData(PropertyOnlyGetterTestCode, PropertyOnlyGetterTestFixCode, 10, 17)]
349-
[InlineData(PropertyPrivateGetterTestCode, PropertyPrivateGetterTestFixCode, 10, 23)]
350-
[InlineData(PropertyInternalGetterTestCode, PropertyInternalGetterTestFixCode, 10, 23)]
351-
[InlineData(BooleanPropertyTestCode, BooleanPropertyTestFixCode, 10, 15)]
352-
[InlineData(NullableBooleanPropertyTestCode, NullableBooleanPropertyTestFixCode, 10, 16)]
353-
[InlineData(ExpressionBodyPropertyTestCode, ExpressionBodyPropertyTestFixCode, 10, 17)]
354-
[InlineData(NullableDateTimePropertyTestCode, NullableDateTimePropertyTestFixCode, 10, 20)]
355-
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column)
421+
[InlineData(PropertyWithGetterSetterTestCode, PropertyWithGetterSetterTestFixCode, 10, 17, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
422+
[InlineData(PropertyOnlyGetterTestCode, PropertyOnlyGetterTestFixCode, 10, 17, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
423+
[InlineData(PropertyPrivateGetterTestCode, PropertyPrivateGetterTestFixCode, 10, 23, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
424+
[InlineData(PropertyInternalGetterTestCode, PropertyInternalGetterTestFixCode, 10, 23, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
425+
[InlineData(BooleanPropertyTestCode, BooleanPropertyTestFixCode, 10, 15, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
426+
[InlineData(NullableBooleanPropertyTestCode, NullableBooleanPropertyTestFixCode, 10, 16, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
427+
[InlineData(ExpressionBodyPropertyTestCode, ExpressionBodyPropertyTestFixCode, 10, 17, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
428+
[InlineData(NullableDateTimePropertyTestCode, NullableDateTimePropertyTestFixCode, 10, 20, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
429+
[InlineData(PublicPropertyInterfaceTestCode, PublicPropertyInterfaceTestFixCode, 10, 17, TestFixure.DIAG_TYPE_PUBLIC)]
430+
[InlineData(PrivatePropertyInterfaceTestCode, PrivatePropertyInterfaceTestFixCode, 10, 10, TestFixure.DIAG_TYPE_PRIVATE)]
431+
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType)
356432
{
357433
var expected = new DiagnosticResult
358434
{
@@ -365,9 +441,9 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
365441
}
366442
};
367443

368-
this.VerifyCSharpDiagnostic(testCode, TestFixure.DIAG_TYPE_PUBLIC, expected);
444+
this.VerifyCSharpDiagnostic(testCode, diagType, expected);
369445

370-
this.VerifyCSharpFix(testCode, fixCode, TestFixure.DIAG_TYPE_PUBLIC);
446+
this.VerifyCSharpFix(testCode, fixCode, diagType);
371447
}
372448

373449
/// <summary>
@@ -385,12 +461,15 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()
385461
/// <returns>A DiagnosticAnalyzer.</returns>
386462
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagType)
387463
{
388-
if (diagType == "private")
464+
if (diagType == TestFixure.DIAG_TYPE_PRIVATE)
389465
{
390466
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = false;
391467
return new NonPublicPropertyAnalyzer();
392468
}
393-
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
469+
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
470+
{
471+
CodeDocumentorPackage.Options.IsEnabledForPublishMembersOnly = true;
472+
}
394473
return new PropertyAnalyzer();
395474
}
396475
}

CodeDocumentor.Test/TestFixure.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace CodeDocumentor.Test
99
public class TestFixure
1010
{
1111
public const string DIAG_TYPE_PUBLIC = "public";
12+
public const string DIAG_TYPE_PUBLIC_ONLY = "publicOnly";
1213
public const string DIAG_TYPE_PRIVATE = "private";
1314

1415
public TestFixure()

CodeDocumentor/Analyzers/Classes/ClassCodeFixProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt
9393

9494
//append to any existing leading trivia [attributes, decorators, etc)
9595
SyntaxTriviaList leadingTrivia = declarationSyntax.GetLeadingTrivia();
96-
SyntaxTriviaList newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));
96+
97+
var newLeadingTrivia = DocumentationHeaderHelper.BuildLeadingTrivia(leadingTrivia, commentTrivia);
9798
ClassDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(newLeadingTrivia);
9899
SyntaxNode newRoot = root.ReplaceNode(declarationSyntax, newDeclaration);
99100

CodeDocumentor/Analyzers/Constructors/ConstructorCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt
7777
SyntaxTriviaList leadingTrivia = declarationSyntax.GetLeadingTrivia();
7878
DocumentationCommentTriviaSyntax commentTrivia = await Task.Run(() => CreateDocumentationCommentTriviaSyntax(declarationSyntax), cancellationToken);
7979

80-
SyntaxTriviaList newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));
80+
var newLeadingTrivia = DocumentationHeaderHelper.BuildLeadingTrivia(leadingTrivia, commentTrivia);
8181
ConstructorDeclarationSyntax newDeclaration = declarationSyntax.WithLeadingTrivia(newLeadingTrivia);
8282

8383
SyntaxNode newRoot = root.ReplaceNode(declarationSyntax, newDeclaration);

0 commit comments

Comments
 (0)