From 93612104824f4bd6216fd0cf96df00b63db1f753 Mon Sep 17 00:00:00 2001 From: Peter Knobloch Date: Thu, 21 Mar 2024 22:31:58 +0100 Subject: [PATCH] Upgrade to DotNet 8. Upgraded all nuget packages to latest. (#22) * Upgrade to DotNet 8. Upgraded all nuget packages to latest. * Fixed class with file scoped namespace. Cleaned up SonarLint warnings and some general logic. * More cleanup. Renamed the test to NoIdent to properly explain the meaning. * Fix the build by updating the version and format check * Change centralised version definition * Fix linting * Remove TargetFramework tags * Correct version number for DotNet * Upgrade setup-dotnet action to latest * Fixing test build. Removed a missed TargetFramework tag. * Fixed test names. --------- Co-authored-by: Peter Knobloch --- .github/workflows/main.yml | 11 +-- .github/workflows/release.yml | 6 +- Directory.Build.props | 2 +- dotnet-document.sln | 11 +-- .../DotnetDocument.Tools.csproj | 24 +++--- .../Handlers/ApplyDocumentHandler.cs | 4 +- .../Workspace/FileWorkspace.cs | 3 +- .../Workspace/FolderWorkspace.cs | 3 +- .../Workspace/WorkspaceBase.cs | 9 -- src/DotnetDocument/DotnetDocument.csproj | 8 +- .../Format/HumanizeFormatter.cs | 10 +-- .../PropertyDocumentationStrategy.cs | 2 +- .../Syntax/DocumentationBuilder.cs | 11 ++- .../Syntax/DocumentationFactory.cs | 15 +++- src/DotnetDocument/Syntax/SyntaxUtils.cs | 62 ++++++++------ src/DotnetDocument/Utils/EnglishUtils.cs | 4 +- src/DotnetDocument/Utils/FormatUtils.cs | 2 +- .../DotnetDocument.Performance.csproj | 6 +- .../DocumentationBuilderTests.cs | 85 +++++++++++++++++-- .../DotnetDocument.Tests.csproj | 18 ++-- .../ClassDocumentationStrategyTests.cs | 1 + .../Strategies/TestCode.cs | 26 ++++++ .../StringExtensionsTests.cs | 18 +--- .../DotnetDocument.Tools.Tests.csproj | 20 ----- test/DotnetDocument.Tools.Tests/UnitTest1.cs | 18 ---- 25 files changed, 213 insertions(+), 166 deletions(-) delete mode 100644 src/DotnetDocument.Tools/Workspace/WorkspaceBase.cs delete mode 100644 test/DotnetDocument.Tools.Tests/DotnetDocument.Tools.Tests.csproj delete mode 100644 test/DotnetDocument.Tools.Tests/UnitTest1.cs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e7bc40c..7e42ba2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ name: Build on: [push, pull_request] env: - DOTNET_VERSION: 6.0.101 + DOTNET_VERSION: 8.0.203 PACKAGE_ID: dotnet-document NUPKG_PATH: ./src/DotnetDocument.Tools/nupkg/*.nupkg PROJECT_PATH: src/DotnetDocument.Tools/DotnetDocument.Tools.csproj @@ -18,11 +18,8 @@ jobs: - name: Checkout repo uses: actions/checkout@v2 - - name: Install dotnet-format - run: dotnet tool install -g dotnet-format - - name: Check format - run: dotnet format --check -v q + run: dotnet format --severity error --verify-no-changes -v q # The test job test-build-pack: @@ -36,7 +33,7 @@ jobs: # Setup .NET - name: Setup .NET ${{ env.DOTNET_VERSION }} - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} @@ -58,7 +55,7 @@ jobs: dotnet pack -v normal -c Release --no-restore \ --include-symbols --include-source \ -p:PackageID=${{ env.PACKAGE_ID }} \ - -p:PackageVersion=${GITHUB_RUN_ID} \ + -p:PackageVersion=0.0.1 \ ${{ env.PROJECT_PATH }} # Upload nupkg to build artifacts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ac35232..5fb9240 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: - '*' env: - DOTNET_VERSION: 6.0.101 + DOTNET_VERSION: 8.0.203 PACKAGE_ID: dotnet-document NUPKG_PATH: ./src/DotnetDocument.Tools/nupkg/*.nupkg PROJECT_PATH: src/DotnetDocument.Tools/DotnetDocument.Tools.csproj @@ -29,9 +29,9 @@ jobs: - name: Update build/Version.props with version from tag run: dotnet TagToVersion -t ${{ github.ref }} - # Setup .NET 5.0 + # Setup .NET - name: Setup .NET ${{ env.DOTNET_VERSION }} - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} source-url: https://api.nuget.org/v3/index.json diff --git a/Directory.Build.props b/Directory.Build.props index 75d5cf1..3eb67b4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,7 +7,7 @@ - net6.0 + net8.0 latest enable diff --git a/dotnet-document.sln b/dotnet-document.sln index 2b05713..fd459ec 100644 --- a/dotnet-document.sln +++ b/dotnet-document.sln @@ -6,8 +6,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3F70908C-71D EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{5C0CC22B-6A56-4BEE-BFCF-3EC1CF6DF1D4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotnetDocument.Tools.Tests", "test\DotnetDocument.Tools.Tests\DotnetDocument.Tools.Tests.csproj", "{E5201557-757B-4C6E-B88C-EF0E273F77FA}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotnetDocument", "src\DotnetDocument\DotnetDocument.csproj", "{120B347D-2DEB-4983-A0C3-AEC5201EB386}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotnetDocument.Tests", "test\DotnetDocument.Tests\DotnetDocument.Tests.csproj", "{53A03382-32D2-4B80-96B6-7FFDF3936368}" @@ -24,14 +22,10 @@ Global {29B9E303-643B-4DA8-A01C-B7D2F49322A1}.Debug|Any CPU.Build.0 = Debug|Any CPU {29B9E303-643B-4DA8-A01C-B7D2F49322A1}.Release|Any CPU.ActiveCfg = Release|Any CPU {29B9E303-643B-4DA8-A01C-B7D2F49322A1}.Release|Any CPU.Build.0 = Release|Any CPU - {E5201557-757B-4C6E-B88C-EF0E273F77FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E5201557-757B-4C6E-B88C-EF0E273F77FA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E5201557-757B-4C6E-B88C-EF0E273F77FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E5201557-757B-4C6E-B88C-EF0E273F77FA}.Release|Any CPU.Build.0 = Release|Any CPU - {120B347D-2DEB-4983-A0C3-AEC5201EB386}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {120B347D-2DEB-4983-A0C3-AEC5201EB386}.Debug|Any CPU.Build.0 = Debug|Any CPU {120B347D-2DEB-4983-A0C3-AEC5201EB386}.Release|Any CPU.ActiveCfg = Release|Any CPU {120B347D-2DEB-4983-A0C3-AEC5201EB386}.Release|Any CPU.Build.0 = Release|Any CPU + {120B347D-2DEB-4983-A0C3-AEC5201EB386}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {120B347D-2DEB-4983-A0C3-AEC5201EB386}.Debug|Any CPU.Build.0 = Release|Any CPU {53A03382-32D2-4B80-96B6-7FFDF3936368}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {53A03382-32D2-4B80-96B6-7FFDF3936368}.Debug|Any CPU.Build.0 = Debug|Any CPU {53A03382-32D2-4B80-96B6-7FFDF3936368}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -43,7 +37,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {29B9E303-643B-4DA8-A01C-B7D2F49322A1} = {3F70908C-71DC-48D1-A6A7-1D46A1481A97} - {E5201557-757B-4C6E-B88C-EF0E273F77FA} = {5C0CC22B-6A56-4BEE-BFCF-3EC1CF6DF1D4} {120B347D-2DEB-4983-A0C3-AEC5201EB386} = {3F70908C-71DC-48D1-A6A7-1D46A1481A97} {53A03382-32D2-4B80-96B6-7FFDF3936368} = {5C0CC22B-6A56-4BEE-BFCF-3EC1CF6DF1D4} {87C75476-E094-4BB6-9F90-2A0B099686E4} = {5C0CC22B-6A56-4BEE-BFCF-3EC1CF6DF1D4} diff --git a/src/DotnetDocument.Tools/DotnetDocument.Tools.csproj b/src/DotnetDocument.Tools/DotnetDocument.Tools.csproj index eda8543..11e2747 100644 --- a/src/DotnetDocument.Tools/DotnetDocument.Tools.csproj +++ b/src/DotnetDocument.Tools/DotnetDocument.Tools.csproj @@ -22,18 +22,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/DotnetDocument.Tools/Handlers/ApplyDocumentHandler.cs b/src/DotnetDocument.Tools/Handlers/ApplyDocumentHandler.cs index a4fd5b3..7078de2 100644 --- a/src/DotnetDocument.Tools/Handlers/ApplyDocumentHandler.cs +++ b/src/DotnetDocument.Tools/Handlers/ApplyDocumentHandler.cs @@ -73,7 +73,7 @@ public Result Apply(string? path, bool isDryRun) var memberDocStatusList = GetFilesDocumentationStatus(files); // Get the list of undocumented members - var undocumentedMembers = memberDocStatusList.Where(m => m.IsDocumented is not true).ToList(); + var undocumentedMembers = memberDocStatusList.Where(m => !m.IsDocumented).ToList(); foreach (var member in undocumentedMembers) _logger.LogInformation(" {File} (ln {Line}): {MemberType} '{MemberName}' has no document", @@ -87,7 +87,7 @@ public Result Apply(string? path, bool isDryRun) // Don't go ahead with saving. // If there are members without doc return `undocumented members` - return memberDocStatusList.Any(m => m.IsDocumented is not true) + return memberDocStatusList.Any(m => !m.IsDocumented) ? Result.UndocumentedMembers : Result.Success; } diff --git a/src/DotnetDocument.Tools/Workspace/FileWorkspace.cs b/src/DotnetDocument.Tools/Workspace/FileWorkspace.cs index 0f5d020..4b0462e 100644 --- a/src/DotnetDocument.Tools/Workspace/FileWorkspace.cs +++ b/src/DotnetDocument.Tools/Workspace/FileWorkspace.cs @@ -5,9 +5,8 @@ namespace DotnetDocument.Tools.Workspace /// /// The file workspace class /// - /// /// - public class FileWorkspace : WorkspaceBase, IWorkspace + public class FileWorkspace : IWorkspace { /// /// The exclude paths diff --git a/src/DotnetDocument.Tools/Workspace/FolderWorkspace.cs b/src/DotnetDocument.Tools/Workspace/FolderWorkspace.cs index 8a565d4..4c01e79 100644 --- a/src/DotnetDocument.Tools/Workspace/FolderWorkspace.cs +++ b/src/DotnetDocument.Tools/Workspace/FolderWorkspace.cs @@ -7,9 +7,8 @@ namespace DotnetDocument.Tools.Workspace /// /// The folder workspace class /// - /// /// - public class FolderWorkspace : WorkspaceBase, IWorkspace + public class FolderWorkspace : IWorkspace { /// /// The exclude paths diff --git a/src/DotnetDocument.Tools/Workspace/WorkspaceBase.cs b/src/DotnetDocument.Tools/Workspace/WorkspaceBase.cs deleted file mode 100644 index d2af82d..0000000 --- a/src/DotnetDocument.Tools/Workspace/WorkspaceBase.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace DotnetDocument.Tools.Workspace -{ - /// - /// The workspace base class - /// - public abstract class WorkspaceBase - { - } -} diff --git a/src/DotnetDocument/DotnetDocument.csproj b/src/DotnetDocument/DotnetDocument.csproj index 5f3a79f..03b8294 100644 --- a/src/DotnetDocument/DotnetDocument.csproj +++ b/src/DotnetDocument/DotnetDocument.csproj @@ -2,10 +2,10 @@ - - - - + + + + diff --git a/src/DotnetDocument/Format/HumanizeFormatter.cs b/src/DotnetDocument/Format/HumanizeFormatter.cs index c602830..f7a24ce 100644 --- a/src/DotnetDocument/Format/HumanizeFormatter.cs +++ b/src/DotnetDocument/Format/HumanizeFormatter.cs @@ -116,7 +116,7 @@ public string FormatMethod(string methodName, string returnType, IEnumerable options.TestAttributes.Contains(a)); @@ -127,8 +127,8 @@ public string FormatMethod(string methodName, string returnType, IEnumerable 0 }: return options.Method.Summary.ManyArgsOneWordMethod .Replace(TemplateKeys.Verb, verb) - .Replace(TemplateKeys.FirstParam, humanizedParameters.First()) + .Replace(TemplateKeys.FirstParam, humanizedParameters[0]) .FirstCharToUpper(); // Multiple words method with params @@ -172,7 +172,7 @@ public string FormatMethod(string methodName, string returnType, IEnumerable {...} + //TODO Check if constructor has an expression body => {...} if (node.ExpressionBody is not null) { } diff --git a/src/DotnetDocument/Syntax/DocumentationBuilder.cs b/src/DotnetDocument/Syntax/DocumentationBuilder.cs index 7f1c3bb..d665c02 100644 --- a/src/DotnetDocument/Syntax/DocumentationBuilder.cs +++ b/src/DotnetDocument/Syntax/DocumentationBuilder.cs @@ -236,8 +236,7 @@ public T Build() .GetIndentationTrivia(node); // Declare a new line element using the method indentation - var xmlNewLine = DocumentationFactory - .XmlNewLineToken(indentationTrivia); + var xmlNewLine = DocumentationFactory.XmlNewLineToken(indentationTrivia); // Declare a new line node var newLineXmlNode = SyntaxFactory @@ -285,10 +284,14 @@ public T Build() // TODO: Research this var endOfLineTrivia = SyntaxFactory.EndOfLine(Environment.NewLine); - var newLeadingTrivia = leadingTrivia + var newLeadingTrivia = indentationTrivia.HasValue + ? leadingTrivia .Add(documentationTrivia) .Add(endOfLineTrivia) - .Add(indentationTrivia); + .Add(indentationTrivia.Value) + : leadingTrivia + .Add(documentationTrivia) + .Add(endOfLineTrivia); var documentedNode = node .WithLeadingTrivia(newLeadingTrivia); diff --git a/src/DotnetDocument/Syntax/DocumentationFactory.cs b/src/DotnetDocument/Syntax/DocumentationFactory.cs index 586f723..7b1c894 100644 --- a/src/DotnetDocument/Syntax/DocumentationFactory.cs +++ b/src/DotnetDocument/Syntax/DocumentationFactory.cs @@ -18,10 +18,17 @@ public static class DocumentationFactory /// /// The indentation trivia /// The syntax token - public static SyntaxToken XmlNewLineToken(SyntaxTrivia indentationTrivia) => SyntaxFactory - .XmlTextNewLine(Environment.NewLine, false) - .WithTrailingTrivia(SyntaxFactory.TriviaList(indentationTrivia, SyntaxFactory - .DocumentationCommentExterior("/// "))); + public static SyntaxToken XmlNewLineToken(SyntaxTrivia? indentationTrivia) + { + List paramList = + indentationTrivia.HasValue + ? [indentationTrivia.Value, SyntaxFactory.DocumentationCommentExterior("/// ")] + : [SyntaxFactory.DocumentationCommentExterior("/// ")]; + + return SyntaxFactory + .XmlTextNewLine(Environment.NewLine, false) + .WithTrailingTrivia(SyntaxFactory.TriviaList(paramList)); + } /// /// Summaries the summary lines diff --git a/src/DotnetDocument/Syntax/SyntaxUtils.cs b/src/DotnetDocument/Syntax/SyntaxUtils.cs index f88da92..04c8cc5 100644 --- a/src/DotnetDocument/Syntax/SyntaxUtils.cs +++ b/src/DotnetDocument/Syntax/SyntaxUtils.cs @@ -17,24 +17,32 @@ public static class SyntaxUtils /// /// The node /// The syntax trivia - public static SyntaxTrivia GetIndentationTrivia(SyntaxNode node) + public static SyntaxTrivia? GetIndentationTrivia(SyntaxNode node) { - var leadingTrivia = node - .GetLeadingTrivia(); + var leadingTrivia = node.GetLeadingTrivia(); try { - var indentationTrivia = leadingTrivia - .Last(); + if (leadingTrivia.Count <= 0) return null; + + // Retrieve the last trivia item (usually indentation) + var lastTrivia = leadingTrivia.Last(); - return indentationTrivia; + // Check if the last trivia is an end-of-line trivia + if (lastTrivia.IsKind(SyntaxKind.EndOfLineTrivia)) + { + return null; + } + + // If it's not an end-of-line trivia, return it directly + return lastTrivia; } catch (Exception e) { Console.WriteLine(node.ToFullString() + Environment.NewLine + e); - // TODO: Investigate this. It should be an empty trivia - return SyntaxFactory.Space; + // It should be an empty trivia, but I can't figure it out so I just ignore it later + return null; } } @@ -96,6 +104,25 @@ public static string FindMemberIdentifier(SyntaxNode node) return descendantIdentifier; } + /// + /// Gets the type. + /// + /// The constructor declaration syntax. + /// + public static string ExtractClassName(ConstructorDeclarationSyntax constructorDeclarationSyntax) + { + if (constructorDeclarationSyntax.Parent is ClassDeclarationSyntax classDeclarationSyntax + && classDeclarationSyntax.TypeParameterList != null) + { + var typeParams = string.Join(",", + classDeclarationSyntax.TypeParameterList.Parameters.Select(x => x.Identifier.Text)); + + return $"{constructorDeclarationSyntax.Identifier.Text}{{{typeParams}}}"; + } + + return constructorDeclarationSyntax.Identifier.Text; + } + /// /// Extracts the base types using the specified class declaration syntax /// @@ -110,25 +137,6 @@ public static IEnumerable ExtractBaseTypes(ClassDeclarationSyntax classD return new List(); } - /// - /// Gets the type. - /// - /// The constructor declaration syntax. - /// - public static string ExtractClassName(ConstructorDeclarationSyntax constructorDeclarationSyntax) - { - if (constructorDeclarationSyntax.Parent is ClassDeclarationSyntax classDeclarationSyntax) - { - if (classDeclarationSyntax.TypeParameterList != null) - { - var typeParams = string.Join(",", classDeclarationSyntax.TypeParameterList.Parameters.Select(x => x.Identifier.Text)); - return $"{constructorDeclarationSyntax.Identifier.Text}{{{typeParams}}}"; - } - } - - return constructorDeclarationSyntax.Identifier.Text; - } - /// /// Extracts the base types using the specified interface declaration syntax /// diff --git a/src/DotnetDocument/Utils/EnglishUtils.cs b/src/DotnetDocument/Utils/EnglishUtils.cs index 7139c7a..17a83ad 100644 --- a/src/DotnetDocument/Utils/EnglishUtils.cs +++ b/src/DotnetDocument/Utils/EnglishUtils.cs @@ -16,8 +16,8 @@ public static class EnglishUtils public static string ConjugateToThirdPersonSingular(string verb) { // Check if verb ends with one of the following chars - if (verb.EndsWith("ch") || verb.EndsWith("s") || verb.EndsWith("sh") || - verb.EndsWith("x") || verb.EndsWith("z") || verb.EndsWith("o")) + if (verb.EndsWith("ch") || verb.EndsWith('s') || verb.EndsWith("sh") || + verb.EndsWith('x') || verb.EndsWith('z') || verb.EndsWith('o')) return $"{verb}es"; // Check if verb is at least 3 chars long, ends with a consonant then y diff --git a/src/DotnetDocument/Utils/FormatUtils.cs b/src/DotnetDocument/Utils/FormatUtils.cs index 15a4d86..3aacfff 100644 --- a/src/DotnetDocument/Utils/FormatUtils.cs +++ b/src/DotnetDocument/Utils/FormatUtils.cs @@ -36,7 +36,7 @@ public static string HumanizeReturnsType(string returnsType) returnsType = returnsType.Trim(); // If the return starts with task - if (returnsType.StartsWith("Task<") && returnsType.EndsWith(">")) + if (returnsType.StartsWith("Task<") && returnsType.EndsWith('>')) { // This is a task description = "a task containing "; diff --git a/test/DotnetDocument.Performance/DotnetDocument.Performance.csproj b/test/DotnetDocument.Performance/DotnetDocument.Performance.csproj index dd06b39..901ffad 100644 --- a/test/DotnetDocument.Performance/DotnetDocument.Performance.csproj +++ b/test/DotnetDocument.Performance/DotnetDocument.Performance.csproj @@ -1,8 +1,8 @@ - + - - + + diff --git a/test/DotnetDocument.Tests/DocumentationBuilderTests.cs b/test/DotnetDocument.Tests/DocumentationBuilderTests.cs index 44e23c0..f48fe06 100644 --- a/test/DotnetDocument.Tests/DocumentationBuilderTests.cs +++ b/test/DotnetDocument.Tests/DocumentationBuilderTests.cs @@ -32,10 +32,29 @@ static void Main(string[] args) } }"; + /// + /// The program text with file scoped namespace + /// + private const string ProgramTextFileScopedNamespace = @" +using System.Collections; +using System.Linq; +using System.Text; + +namespace HelloWorld; + +class Program +{ + static void Main(string[] args) + { + Console.WriteLine(""Hello, World!""); + } +} +"; + /// /// The expected documented method text /// - private const string ExpectedDocumentedMethodText = @" /// + private const string ExpectedDocumentedMethodTextBlockScope = @" /// /// Gets or sets the list of users /// Note that this method needs to be awaited /// @@ -51,11 +70,27 @@ static void Main(string[] args) } "; + private const string ExpectedDocumentedMethodTextFileScope = @" /// + /// Gets or sets the list of users + /// Note that this method needs to be awaited + /// + /// The type of the returned entity + /// The logger + /// The user repository + /// You should provide something + /// You should provide a valid arg + /// The list of users + static void Main(string[] args) + { + Console.WriteLine(""Hello, World!""); + } +"; + /// - /// Tests that test 2 + /// Tests blocked scope namespace /// - [Fact(DisplayName = "Yes")] - public void Test2() + [Fact] + public void TestBlockedScopeNamespace() { // Arrange @@ -88,7 +123,47 @@ public void Test2() .Build(); // Assert - documentedNode.ToFullString().ShouldBe(ExpectedDocumentedMethodText); + documentedNode.ToFullString().ShouldBe(ExpectedDocumentedMethodTextBlockScope); + } + + /// + /// Tests file scoped namespace + /// + [Fact] + public void TestFileScopeNamespace() + { + // Arrange + + // Declare a new CSharp syntax tree by parsing the program text + var tree = CSharpSyntaxTree.ParseText(ProgramTextFileScopedNamespace, + new CSharpParseOptions(documentationMode: DocumentationMode.Parse)); + + // Get the compilation unit root + var root = tree.GetCompilationUnitRoot(); + + // Find the first method declaration + var methodDeclaration = root.Members.First() + .DescendantNodes() + .OfType() + .First(); + + // Assert it's a method declaration + methodDeclaration.Kind().ShouldBe(SyntaxKind.MethodDeclaration); + + // Act + var documentedNode = new DocumentationBuilder() + .For(methodDeclaration) + .WithSummary("Gets or sets the list of users", "Note that this method needs to be awaited") + .WithTypeParam("TEntity", "The type of the returned entity") + .WithParam("logger", "The logger") + .WithParam("repository", "The user repository") + .WithException("System.Exception", "You should provide something") + .WithException("System.ArgumentException", "You should provide a valid arg") + .WithReturns("The list of users") + .Build(); + + // Assert + documentedNode.ToFullString().ShouldBe(ExpectedDocumentedMethodTextFileScope); } } } diff --git a/test/DotnetDocument.Tests/DotnetDocument.Tests.csproj b/test/DotnetDocument.Tests/DotnetDocument.Tests.csproj index 5ccad88..0b2c388 100644 --- a/test/DotnetDocument.Tests/DotnetDocument.Tests.csproj +++ b/test/DotnetDocument.Tests/DotnetDocument.Tests.csproj @@ -5,19 +5,19 @@ - - - - - - + + + + + + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/DotnetDocument.Tests/Strategies/ClassDocumentationStrategyTests.cs b/test/DotnetDocument.Tests/Strategies/ClassDocumentationStrategyTests.cs index 600d5af..f16cae6 100644 --- a/test/DotnetDocument.Tests/Strategies/ClassDocumentationStrategyTests.cs +++ b/test/DotnetDocument.Tests/Strategies/ClassDocumentationStrategyTests.cs @@ -23,6 +23,7 @@ public class ClassDocumentationStrategyTests : DocumentationStrategyTestsBase /// The expected commented code [Theory(DisplayName = "Should document")] [InlineData(TestCode.WithoutDoc.SimpleClass, TestCode.WithDoc.SimpleClass)] + [InlineData(TestCode.WithoutDoc.SimpleClassNoIdent, TestCode.WithDoc.SimpleClassNoIdent)] [InlineData(TestCode.WithoutDoc.ClassWithInheritance, TestCode.WithDoc.ClassWithInheritance)] public void ShouldDocument(string uncommentedCode, string expectedCommentedCode) { diff --git a/test/DotnetDocument.Tests/Strategies/TestCode.cs b/test/DotnetDocument.Tests/Strategies/TestCode.cs index 8a52eaf..5aa7a30 100644 --- a/test/DotnetDocument.Tests/Strategies/TestCode.cs +++ b/test/DotnetDocument.Tests/Strategies/TestCode.cs @@ -22,6 +22,18 @@ public User Get(string id) } }"; + /// + /// The simple + /// + public const string SimpleClassNoIdent = @" +public class UserRepository +{ + public User Get(string id) + { + return new User(); + } +}"; + /// /// The class with inheritance /// @@ -99,6 +111,20 @@ public User Get(string id) return new User(); } }"; + /// + /// The simple + /// + public const string SimpleClassNoIdent = @" +/// +/// The user repository class +/// +public class UserRepository +{ + public User Get(string id) + { + return new User(); + } +}"; /// /// The class with inheritance diff --git a/test/DotnetDocument.Tests/StringExtensionsTests.cs b/test/DotnetDocument.Tests/StringExtensionsTests.cs index e0e1eec..575f820 100644 --- a/test/DotnetDocument.Tests/StringExtensionsTests.cs +++ b/test/DotnetDocument.Tests/StringExtensionsTests.cs @@ -17,23 +17,8 @@ public class StringExtensionsTests [Theory] [InlineData("Initializes a new instance of the <> class.", "GenericRepository{T}")] [InlineData("Initializes a new instance of the <> class.", "UserRepository")] - public void ShouldSubstring(string text, string expected) - { - // Act - var substring = text.SubstringBetween("<<", ">>"); - - // Assert - substring.ShouldBe(expected); - } - - /// - /// Tests that should not substring - /// - /// The text - /// The expected - [Theory] [InlineData("Initializes a new instance of the UserRepository class.", "")] - public void ShouldNotSubstring(string text, string expected) + public void ShouldOnlySubstringDoubleTriangleBrackets(string text, string expected) { // Act var substring = text.SubstringBetween("<<", ">>"); @@ -41,5 +26,6 @@ public void ShouldNotSubstring(string text, string expected) // Assert substring.ShouldBe(expected); } + } } diff --git a/test/DotnetDocument.Tools.Tests/DotnetDocument.Tools.Tests.csproj b/test/DotnetDocument.Tools.Tests/DotnetDocument.Tools.Tests.csproj deleted file mode 100644 index 67d7019..0000000 --- a/test/DotnetDocument.Tools.Tests/DotnetDocument.Tools.Tests.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - false - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - diff --git a/test/DotnetDocument.Tools.Tests/UnitTest1.cs b/test/DotnetDocument.Tools.Tests/UnitTest1.cs deleted file mode 100644 index 8ca6ef9..0000000 --- a/test/DotnetDocument.Tools.Tests/UnitTest1.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Xunit; - -namespace DotnetDocument.Tools.Tests -{ - /// - /// The unit test class - /// - public class UnitTest1 - { - /// - /// Tests that test 1 - /// - [Fact] - public void Test1() - { - } - } -}