Skip to content

Commit

Permalink
Merge pull request #18 from d1820/record-support
Browse files Browse the repository at this point in the history
Record support
  • Loading branch information
d1820 authored Feb 19, 2023
2 parents 6161824 + fc6ef18 commit e8c167f
Show file tree
Hide file tree
Showing 91 changed files with 1,748 additions and 854 deletions.
61 changes: 37 additions & 24 deletions CodeDocumentor.Test/Classes/ClassUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
using CodeDocumentor.Vsix2022;
using CodeDocumentor.Services;
using CodeDocumentor.Test.TestHelpers;
using CodeDocumentor.Vsix2022;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;

using Xunit;

namespace CodeDocumentor.Test
namespace CodeDocumentor.Test.Classes
{
/// <summary>
/// The class unit test.
/// </summary>

public partial class ClassUnitTest : CodeFixVerifier, IClassFixture<TestFixure>
public class ClassUnitTest : CodeFixVerifier, IClassFixture<TestFixture>
{
private readonly TestFixure _fixture;
private readonly TestFixture _fixture;

public ClassUnitTest(TestFixure fixture)
public ClassUnitTest(TestFixture fixture)
{
_fixture = fixture;
TestFixture.BuildOptionsPageGrid();
CodeDocumentorPackage.Options.DefaultDiagnosticSeverity = DiagnosticSeverity.Warning;
}

/// <summary>
/// Nos diagnostics show.
/// No diagnostics show.
/// </summary>
/// <param name="testCode">The test code.</param>
[Theory]
Expand All @@ -33,11 +32,11 @@ public void NoDiagnosticsShow(string testCode)
{
if (testCode == string.Empty)
{
this.VerifyCSharpDiagnostic(testCode, "public");
VerifyCSharpDiagnostic(testCode, TestFixture.DIAG_TYPE_PUBLIC);
}
else
{
var file = _fixture.LoadTestFile($@"./Classes/{testCode}");
var file = _fixture.LoadTestFile($@"./Classes/TestFiles/{testCode}");

var expected = new DiagnosticResult
{
Expand All @@ -50,7 +49,7 @@ public void NoDiagnosticsShow(string testCode)
}
};

this.VerifyCSharpDiagnostic(file, "public", expected);
VerifyCSharpDiagnostic(file, TestFixture.DIAG_TYPE_PUBLIC, expected);
}
}

Expand All @@ -62,13 +61,17 @@ public void NoDiagnosticsShow(string testCode)
/// <param name="line">The line.</param>
/// <param name="column">The column.</param>
[Theory]
[InlineData("ClassTester.cs", "ClassTesterFix.cs", 7, 19, TestFixure.DIAG_TYPE_PRIVATE)]
[InlineData("PublicClassTester.cs", "PublicClassTesterFix.cs", 7, 26, TestFixure.DIAG_TYPE_PUBLIC_ONLY)]
[InlineData("ClassTester.cs", "ClassTesterFix.cs", 7, 19, TestFixture.DIAG_TYPE_PRIVATE)]
[InlineData("PublicClassTester.cs", "PublicClassTesterFix.cs", 7, 26, TestFixture.DIAG_TYPE_PUBLIC_ONLY)]
public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int column, string diagType)
{
var fix = _fixture.LoadTestFile($@"./Classes/{fixCode}");
var test = _fixture.LoadTestFile($@"./Classes/{testCode}");
var fix = _fixture.LoadTestFile($@"./Classes/TestFiles/{fixCode}");
var test = _fixture.LoadTestFile($@"./Classes/TestFiles/{testCode}");

_fixture.OptionsPropertyCallback = (o) =>
{
_fixture.SetPublicProcessingOption(o, diagType);
};
var expected = new DiagnosticResult
{
Id = ClassAnalyzerSettings.DiagnosticId,
Expand All @@ -80,9 +83,24 @@ public void ShowDiagnosticAndFix(string testCode, string fixCode, int line, int
}
};

this.VerifyCSharpDiagnostic(test, diagType, expected);
VerifyCSharpDiagnostic(test, diagType, expected);

VerifyCSharpFix(test, fix, diagType);
}

[Fact]
public void SkipsDiagnosticAndFixWhenPublicOnlyTrue()
{
var fix = _fixture.LoadTestFile($@"./Classes/TestFiles/ClassTester.cs");
var test = _fixture.LoadTestFile($@"./Classes/TestFiles/ClassTester.cs");
_fixture.OptionsPropertyCallback = (o) =>
{
o.IsEnabledForPublicMembersOnly = true;
};

VerifyCSharpDiagnostic(test, TestFixture.DIAG_TYPE_PRIVATE);

this.VerifyCSharpFix(test, fix, diagType);
VerifyCSharpFix(test, fix, TestFixture.DIAG_TYPE_PRIVATE);
}

/// <summary>
Expand All @@ -100,15 +118,10 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()
/// <returns>A DiagnosticAnalyzer.</returns>
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer(string diagType)
{
if (diagType == TestFixure.DIAG_TYPE_PRIVATE)
if (diagType == TestFixture.DIAG_TYPE_PRIVATE)
{
CodeDocumentorPackage.Options.IsEnabledForPublicMembersOnly = false;
return new NonPublicClassAnalyzer();
}
if (diagType == TestFixure.DIAG_TYPE_PUBLIC_ONLY)
{
CodeDocumentorPackage.Options.IsEnabledForPublicMembersOnly = true;
}
return new ClassAnalyzer();
}
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp4
namespace CodeDocumentor.Test.Classes.TestFiles
{
/// <inheritdoc/>
public class ClassTesterInherit
Expand Down
100 changes: 95 additions & 5 deletions CodeDocumentor.Test/CodeDocumentor.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,112 @@
<Compile Remove="Classes\ClassTesterInheritDoc.cs" />
<Compile Remove="Classes\PublicClassTester.cs" />
<Compile Remove="Classes\PublicClassTesterFix.cs" />
<Compile Remove="Constructors\TestFiles\InheritDocTestCode.cs" />
<Compile Remove="Constructors\TestFiles\PrivateConstructorTestCode.cs" />
<Compile Remove="Constructors\TestFiles\PrivateContructorTestFixCode.cs" />
<Compile Remove="Constructors\TestFiles\PublicConstructorTestCode.cs" />
<Compile Remove="Constructors\TestFiles\PublicConstructorWithBooleanParameterTestCode.cs" />
<Compile Remove="Constructors\TestFiles\PublicContructorTestFixCode.cs" />
<Compile Remove="Constructors\TestFiles\PublicContructorWithBooleanParameterTestFixCode.cs" />
<Compile Remove="Enums\TestFiles\TestCode.cs" />
<Compile Remove="Enums\TestFiles\TestFixCode.cs" />
<Compile Remove="Fields\TestFiles\ConstFieldTestCode.cs" />
<Compile Remove="Fields\TestFiles\ConstFieldTestFixCode.cs" />
<Compile Remove="Fields\TestFiles\InheritDocTestCode.cs" />
<Compile Remove="Interfaces\TestFiles\TestCode.cs" />
<Compile Remove="Interfaces\TestFiles\TestFixCode.cs" />
<Compile Remove="Methods\TestFiles\InheritDocTestCode.cs" />
<Compile Remove="Properties\TestFiles\InheritDocTestCode.cs" />
<Compile Remove="Records\TestFiles\PublicRecordTester.cs" />
<Compile Remove="Records\TestFiles\PublicRecordTesterFix.cs" />
<Compile Remove="Records\TestFiles\RecordTester.cs" />
<Compile Remove="Records\TestFiles\RecordTesterFix.cs" />
<Compile Remove="Records\TestFiles\RecordTesterInheritDoc.cs" />
</ItemGroup>

<ItemGroup>
<None Include="Classes\ClassTester.cs">
<None Include="Methods\TestFiles\InheritDocTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Classes\ClassTesterFix.cs">
</ItemGroup>

<ItemGroup>
<None Include="Constructors\TestFiles\InheritDocTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Constructors\TestFiles\PrivateConstructorTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Constructors\TestFiles\PrivateContructorTestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Constructors\TestFiles\PublicConstructorTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Constructors\TestFiles\PublicConstructorWithBooleanParameterTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Constructors\TestFiles\PublicContructorTestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Constructors\TestFiles\PublicContructorWithBooleanParameterTestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Enums\TestFiles\TestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Enums\TestFiles\TestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Fields\TestFiles\ConstFieldTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Fields\TestFiles\ConstFieldTestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Fields\TestFiles\InheritDocTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Interfaces\TestFiles\TestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Interfaces\TestFiles\TestFixCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Properties\TestFiles\InheritDocTestCode.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Include="Records\TestFiles\RecordTester.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Records\TestFiles\RecordTesterFix.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Records\TestFiles\RecordTesterInheritDoc.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Records\TestFiles\PublicRecordTester.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Records\TestFiles\PublicRecordTesterFix.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Classes\TestFiles\ClassTester.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Classes\TestFiles\ClassTesterFix.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Classes\ClassTesterInheritDoc.cs">
<None Include="Classes\TestFiles\ClassTesterInheritDoc.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Classes\PublicClassTester.cs">
<None Include="Classes\TestFiles\PublicClassTester.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Classes\PublicClassTesterFix.cs">
<None Include="Classes\TestFiles\PublicClassTesterFix.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Loading

0 comments on commit e8c167f

Please sign in to comment.