-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLVS-1596 Add GetEffectiveIssueDetailsAsync (#5814)
- Loading branch information
1 parent
ff36cfa
commit 9f15429
Showing
6 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsParamsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 Newtonsoft.Json; | ||
using SonarLint.VisualStudio.SLCore.Service.Issue; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Issue; | ||
|
||
[TestClass] | ||
public class GetEffectiveIssueDetailsParamsTests | ||
{ | ||
[TestMethod] | ||
public void Serialized_AsExpected() | ||
{ | ||
var guid = Guid.NewGuid(); | ||
var expected = $$""" | ||
{ | ||
"configurationScopeId": "CONFIG_SCOPE_ID", | ||
"issueId": "{{guid.ToString()}}" | ||
} | ||
"""; | ||
|
||
var getEffectiveIssueDetailsParams = new GetEffectiveIssueDetailsParams("CONFIG_SCOPE_ID", guid); | ||
|
||
JsonConvert.SerializeObject(getEffectiveIssueDetailsParams, Formatting.Indented).Should().Be(expected); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsResponseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Newtonsoft.Json; | ||
using SonarLint.VisualStudio.SLCore.Common.Models; | ||
using SonarLint.VisualStudio.SLCore.Service.Issue; | ||
using SonarLint.VisualStudio.SLCore.Service.Issue.Models; | ||
using SonarLint.VisualStudio.SLCore.Service.Rules.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Issue; | ||
|
||
[TestClass] | ||
public class GetEffectiveIssueDetailsResponseTests | ||
{ | ||
[TestMethod] | ||
public void Deserialized_AsExpected() | ||
{ | ||
var expected = new GetEffectiveIssueDetailsResponse( | ||
details: new EffectiveIssueDetailsDto( | ||
ruleKey: "S3776", | ||
name: "Cognitive Complexity of methods should not be too high", | ||
language: Language.CS, | ||
vulnerabilityProbability: VulnerabilityProbability.HIGH, | ||
description: new RuleMonolithicDescriptionDto("<p>Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code.</p>"), | ||
parameters: [new EffectiveRuleParamDto("max", "Maximum cognitive complexity", "15", "15")], | ||
severityDetails: new StandardModeDetails(IssueSeverity.CRITICAL, RuleType.CODE_SMELL), | ||
ruleDescriptionContextKey: "key")); | ||
|
||
const string serialized = """ | ||
{ | ||
details: { | ||
"ruleKey": "S3776", | ||
"name": "Cognitive Complexity of methods should not be too high", | ||
"language": "cs", | ||
"vulnerabilityProbability": "HIGH", | ||
"description": { | ||
"htmlContent": "<p>Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code.</p>" | ||
}, | ||
"params": [ | ||
{ | ||
"name": "max", | ||
"description": "Maximum cognitive complexity", | ||
"value": "15", | ||
"defaultValue": "15" | ||
} | ||
], | ||
"severityDetails": { | ||
"severity": "CRITICAL", | ||
"type": "CODE_SMELL" | ||
}, | ||
"ruleDescriptionContextKey": "key" | ||
} | ||
} | ||
"""; | ||
|
||
var actual = JsonConvert.DeserializeObject<GetEffectiveIssueDetailsResponse>(serialized); | ||
|
||
actual | ||
.Should() | ||
.BeEquivalentTo(expected, | ||
options => | ||
options | ||
.ComparingByMembers<GetEffectiveIssueDetailsResponse>() | ||
.ComparingByMembers<EffectiveIssueDetailsDto>() | ||
.ComparingByMembers<RuleMonolithicDescriptionDto>() | ||
.ComparingByMembers<EffectiveRuleParamDto>() | ||
.ComparingByMembers<StandardModeDetails>()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/SLCore/Service/Issue/GetEffectiveIssueDetailsParams.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Service.Issue; | ||
|
||
public record GetEffectiveIssueDetailsParams(string configurationScopeId, Guid issueId); |
25 changes: 25 additions & 0 deletions
25
src/SLCore/Service/Issue/GetEffectiveIssueDetailsResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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 SonarLint.VisualStudio.SLCore.Service.Issue.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Service.Issue; | ||
|
||
public record GetEffectiveIssueDetailsResponse(EffectiveIssueDetailsDto details); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 SonarLint.VisualStudio.SLCore.Core; | ||
using SonarLint.VisualStudio.SLCore.Protocol; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Service.Issue; | ||
|
||
[JsonRpcClass("issue")] | ||
public interface IIssueSLCoreService : ISLCoreService | ||
{ | ||
Task<GetEffectiveIssueDetailsResponse> GetEffectiveIssueDetailsAsync(GetEffectiveIssueDetailsParams parameters); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/SLCore/Service/Issue/Models/EffectiveIssueDetailsDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 Newtonsoft.Json; | ||
using SonarLint.VisualStudio.SLCore.Common.Models; | ||
using SonarLint.VisualStudio.SLCore.Protocol; | ||
using SonarLint.VisualStudio.SLCore.Service.Rules.Models; | ||
|
||
namespace SonarLint.VisualStudio.SLCore.Service.Issue.Models; | ||
|
||
public record EffectiveIssueDetailsDto( | ||
string ruleKey, | ||
string name, | ||
Language language, | ||
VulnerabilityProbability? vulnerabilityProbability, | ||
[JsonConverter(typeof(EitherJsonConverter<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto>))] Either<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto> description, | ||
[JsonProperty("params")] List<EffectiveRuleParamDto> parameters, | ||
[JsonConverter(typeof(EitherJsonConverter<StandardModeDetails, MQRModeDetails>))] Either<StandardModeDetails, MQRModeDetails> severityDetails, | ||
string ruleDescriptionContextKey); |