-
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.
Fix muting of incorrect issues when bound to SonarCloud
- Loading branch information
1 parent
30aa1d7
commit 8c02b5a
Showing
17 changed files
with
353 additions
and
60 deletions.
There are no files selected for viewing
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
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
92 changes: 92 additions & 0 deletions
92
src/SonarQube.Client.Tests/Requests/Api/V7_20/GetIssuesSonarCloudRequestTests.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,92 @@ | ||
/* | ||
* 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; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using SonarQube.Client.Api.V7_20; | ||
using SonarQube.Client.Tests.Infra; | ||
using static SonarQube.Client.Tests.Infra.MocksHelper; | ||
|
||
namespace SonarQube.Client.Tests.Requests.Api.V7_20; | ||
|
||
[TestClass] | ||
public class GetIssuesSonarCloudRequestTests | ||
{ | ||
[TestMethod] | ||
public async Task InvokeAsync_ComponentKeyNotSpecified_ComponentsAreNotIncludedInQueryString() | ||
{ | ||
var testSubject = CreateTestSubject("any", "any", componentKey: null); | ||
|
||
var handlerMock = new Mock<HttpMessageHandler>(); | ||
var httpClient = new HttpClient(handlerMock.Object) | ||
{ | ||
BaseAddress = new Uri(ValidBaseAddress) | ||
}; | ||
|
||
SetupHttpRequest(handlerMock, EmptyGetIssuesResponse); | ||
_ = await testSubject.InvokeAsync(httpClient, CancellationToken.None); | ||
|
||
var actualQueryString = GetSingleActualQueryString(handlerMock); | ||
actualQueryString.Contains("components").Should().BeFalse(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task InvokeAsync_ComponentKeySpecified_ComponentsAreIncludedInQueryString() | ||
{ | ||
var testSubject = CreateTestSubject("any", "any", componentKey: "project1"); | ||
|
||
var handlerMock = new Mock<HttpMessageHandler>(); | ||
var httpClient = new HttpClient(handlerMock.Object) | ||
{ | ||
BaseAddress = new Uri(ValidBaseAddress) | ||
}; | ||
|
||
SetupHttpRequest(handlerMock, EmptyGetIssuesResponse); | ||
_ = await testSubject.InvokeAsync(httpClient, CancellationToken.None); | ||
|
||
var actualQueryString = GetSingleActualQueryString(handlerMock); | ||
actualQueryString.Contains("componentKeys=project1").Should().BeTrue(); | ||
} | ||
|
||
private static GetIssuesWithComponentSonarCloudRequest CreateTestSubject(string projectKey, string statusesToRequest, string componentKey = null) | ||
{ | ||
var testSubject = new GetIssuesWithComponentSonarCloudRequest | ||
{ | ||
Logger = new TestLogger(), | ||
ProjectKey = projectKey, | ||
Statuses = statusesToRequest, | ||
ComponentKey = componentKey | ||
}; | ||
|
||
return testSubject; | ||
} | ||
|
||
private static string GetSingleActualQueryString(Mock<HttpMessageHandler> handlerMock) | ||
{ | ||
handlerMock.Invocations.Count.Should().Be(1); | ||
var requestMessage = (HttpRequestMessage)handlerMock.Invocations[0].Arguments[0]; | ||
return requestMessage.RequestUri.Query; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
src/SonarQube.Client.Tests/Requests/Api/V7_20/GetIssuesSonarQubeRequestTests.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,92 @@ | ||
/* | ||
* 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; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using SonarQube.Client.Api.V7_20; | ||
using SonarQube.Client.Tests.Infra; | ||
using static SonarQube.Client.Tests.Infra.MocksHelper; | ||
|
||
namespace SonarQube.Client.Tests.Requests.Api.V7_20; | ||
|
||
[TestClass] | ||
public class GetIssuesSonarQubeRequestTests | ||
{ | ||
[TestMethod] | ||
public async Task InvokeAsync_ComponentKeyNotSpecified_ComponentsAreNotIncludedInQueryString() | ||
{ | ||
var testSubject = CreateTestSubject("any", "any", componentKey: null); | ||
|
||
var handlerMock = new Mock<HttpMessageHandler>(); | ||
var httpClient = new HttpClient(handlerMock.Object) | ||
{ | ||
BaseAddress = new Uri(ValidBaseAddress) | ||
}; | ||
|
||
SetupHttpRequest(handlerMock, EmptyGetIssuesResponse); | ||
_ = await testSubject.InvokeAsync(httpClient, CancellationToken.None); | ||
|
||
var actualQueryString = GetSingleActualQueryString(handlerMock); | ||
actualQueryString.Contains("components").Should().BeFalse(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task InvokeAsync_ComponentKeySpecified_ComponentsAreIncludedInQueryString() | ||
{ | ||
var testSubject = CreateTestSubject("any", "any", componentKey: "project1"); | ||
|
||
var handlerMock = new Mock<HttpMessageHandler>(); | ||
var httpClient = new HttpClient(handlerMock.Object) | ||
{ | ||
BaseAddress = new Uri(ValidBaseAddress) | ||
}; | ||
|
||
SetupHttpRequest(handlerMock, EmptyGetIssuesResponse); | ||
_ = await testSubject.InvokeAsync(httpClient, CancellationToken.None); | ||
|
||
var actualQueryString = GetSingleActualQueryString(handlerMock); | ||
actualQueryString.Contains("components=project1").Should().BeTrue(); | ||
} | ||
|
||
private static GetIssuesWithComponentSonarQubeRequest CreateTestSubject(string projectKey, string statusesToRequest, string componentKey = null) | ||
{ | ||
var testSubject = new GetIssuesWithComponentSonarQubeRequest | ||
{ | ||
Logger = new TestLogger(), | ||
ProjectKey = projectKey, | ||
Statuses = statusesToRequest, | ||
ComponentKey = componentKey | ||
}; | ||
|
||
return testSubject; | ||
} | ||
|
||
private static string GetSingleActualQueryString(Mock<HttpMessageHandler> handlerMock) | ||
{ | ||
handlerMock.Invocations.Count.Should().Be(1); | ||
var requestMessage = (HttpRequestMessage)handlerMock.Invocations[0].Arguments[0]; | ||
return requestMessage.RequestUri.Query; | ||
} | ||
} |
Oops, something went wrong.