Skip to content

Commit

Permalink
Add RichRuleDescriptionProvider implementation (#5227)
Browse files Browse the repository at this point in the history
Fixes #5217
  • Loading branch information
1 parent cd830f9 commit 8b55924
Show file tree
Hide file tree
Showing 24 changed files with 408 additions and 268 deletions.
3 changes: 2 additions & 1 deletion src/CFamily.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,8 @@
"DiffPlex": "[1.7.1, )",
"Microsoft.VisualStudio.Sdk": "[17.0.31902.203, )",
"SonarLint.VisualStudio.Core": "[1.0.0, )",
"SonarLint.VisualStudio.Infrastructure.VS": "[1.0.0, )"
"SonarLint.VisualStudio.Infrastructure.VS": "[1.0.0, )",
"SonarLint.VisualStudio.SLCore": "[1.0.0, )"
}
},
"SonarLint.VisualStudio.Infrastructure.VS": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public class ContextualRuleDescriptionTabTests
private const string ContextTabContent2 = "htmlcontent2";
private const string ContextTabXamlContent2 = "xamlcontent2";

[TestMethod]
public void Ctor_ContextContentTab_EnsuresHtmlIsXml()
{
var testSubject = new ContextualRuleDescriptionTab.ContextContentTab("title", "context", "<col>");

testSubject.HtmlContent.Should().BeEquivalentTo("<col/>");
}

[TestMethod]
public void Title_ReturnsCorrectTitle()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ namespace SonarLint.VisualStudio.Education.UnitTests.Layout.Logical;
[TestClass]
public class NonContextualRuleDescriptionTabTests
{
[TestMethod]
public void Ctor_EnsuresHtmlIsXml()
{
var testSubject = new NonContextualRuleDescriptionTab("title", "<col>");

testSubject.htmlContent.Should().BeEquivalentTo("<col/>");
}

[TestMethod]
public void ProduceVisualNode_ReturnsSingleContentSection()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Collections.Generic;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SonarLint.VisualStudio.Education.Layout.Logical;
using SonarLint.VisualStudio.Education.Rule;
using SonarLint.VisualStudio.SLCore.Protocol;
using SonarLint.VisualStudio.SLCore.Service.Rules.Models;
using SonarLint.VisualStudio.TestInfrastructure;

namespace SonarLint.VisualStudio.Education.UnitTests.Layout.Logical;

[TestClass]
public class RichRuleDescriptionProviderTest
{
[TestMethod]
public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<RichRuleDescriptionProvider, IRichRuleDescriptionProvider>();
}

[TestMethod]
public void MefCtor_CheckIsSingleton()
{
MefTestHelpers.CheckIsSingletonMefComponent<RichRuleDescriptionProvider>();
}

[TestMethod]
public void Get_ReturnsCorrectStructure()
{
var richRuleDescriptionProvider = new RichRuleDescriptionProvider();
var ruleInfoMock = new Mock<IRuleInfo>();
ruleInfoMock.SetupGet(x => x.RichRuleDescriptionDto).Returns(
new RuleSplitDescriptionDto("intro",
new List<RuleDescriptionTabDto>
{
new("tab 1",
Either<RuleNonContextualSectionDto, RuleContextualSectionWithDefaultContextKeyDto>.CreateLeft(
new RuleNonContextualSectionDto("content"))),
new("tab 2",
Either<RuleNonContextualSectionDto, RuleContextualSectionWithDefaultContextKeyDto>.CreateRight(
new RuleContextualSectionWithDefaultContextKeyDto("context2",
new List<RuleContextualSectionDto>
{
new("context1content", "context1", "Context 1"),
new("context2content", "context2", "Context 2")
}))),
new("tab 3",
Either<RuleNonContextualSectionDto, RuleContextualSectionWithDefaultContextKeyDto>.CreateLeft(
new RuleNonContextualSectionDto("content"))),
}));


richRuleDescriptionProvider.GetRichRuleDescriptionModel(ruleInfoMock.Object).Should().BeEquivalentTo(
new RichRuleDescription("intro", new List<IRuleDescriptionTab>
{
new NonContextualRuleDescriptionTab("tab 1", "content"),
new ContextualRuleDescriptionTab("tab 2", "context2", new List<ContextualRuleDescriptionTab.ContextContentTab>
{
new("Context 1", "context1", "context1content"),
new("Context 2", "context2", "context2content")
}),
new NonContextualRuleDescriptionTab("tab 3", "content"),
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ namespace SonarLint.VisualStudio.Education.UnitTests.Layout.Logical;
[TestClass]
public class RichRuleDescriptionTests
{
[TestMethod]
public void Ctor_EnsuresHtmlIsXml()
{
var testSubject = new RichRuleDescription( "<col>", new List<IRuleDescriptionTab>());

testSubject.introductionHtml.Should().BeEquivalentTo("<col/>");
}

[TestMethod]
public void ProduceVisualNode_ProducesMultiBlockSectionWithIntroAndTabs()
{
Expand Down
74 changes: 0 additions & 74 deletions src/Education.UnitTests/Rule/RuleHelpTests.cs

This file was deleted.

Loading

0 comments on commit 8b55924

Please sign in to comment.