From c6475aabff2d52d44255ae92105e2ca3872a1442 Mon Sep 17 00:00:00 2001 From: Praven Kuttappan <55455725+praveenkuttappan@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:16:34 -0400 Subject: [PATCH] Include RenderClasses in serialized JSON code file (#8877) --- .../APIView/APIView/Model/V2/ReviewToken.cs | 2 +- .../CSharpAPIParserTests/CodeFileTests.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/dotnet/APIView/APIView/Model/V2/ReviewToken.cs b/src/dotnet/APIView/APIView/Model/V2/ReviewToken.cs index fb45f0929eb..94e878f9b48 100644 --- a/src/dotnet/APIView/APIView/Model/V2/ReviewToken.cs +++ b/src/dotnet/APIView/APIView/Model/V2/ReviewToken.cs @@ -57,7 +57,7 @@ public ReviewToken(string value, TokenKind kind) /// /// Language specific style css class names /// - public List RenderClasses = []; + public List RenderClasses { get; set; } = []; public static ReviewToken CreateTextToken(string value, string navigateToId = null, bool hasSuffixSpace = true) { diff --git a/tools/apiview/parsers/csharp-api-parser/CSharpAPIParserTests/CodeFileTests.cs b/tools/apiview/parsers/csharp-api-parser/CSharpAPIParserTests/CodeFileTests.cs index 59aea555c7d..40fa294b3d9 100644 --- a/tools/apiview/parsers/csharp-api-parser/CSharpAPIParserTests/CodeFileTests.cs +++ b/tools/apiview/parsers/csharp-api-parser/CSharpAPIParserTests/CodeFileTests.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Schema; using Newtonsoft.Json.Linq; using System.Text.Json.Serialization; +using APIView.Model.V2; namespace CSharpAPIParserTests @@ -126,5 +127,25 @@ private bool validateSchema(CodeFile codeFile) } return isValid; } + + [Fact] + public void TestNavigatonNodeHasRenderingClass() + { + var jsonString = JsonSerializer.Serialize(codeFile); + var parsedCodeFile = JsonSerializer.Deserialize(jsonString); + Assert.Equal(8, CountNavigationNodes(parsedCodeFile.ReviewLines)); + } + + private int CountNavigationNodes(List lines) + { + int count = 0; + foreach (var line in lines) + { + var navTokens = line.Tokens.Where(x=> x.NavigationDisplayName != null); + count += navTokens.Count(x => x.RenderClasses.Any()); + count += CountNavigationNodes(line.Children); + } + return count; + } } }