Skip to content

Commit

Permalink
CaYC: cleanup code applied in touched files
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriela-trutan-sonarsource committed Dec 23, 2024
1 parent 15efd71 commit f45e20b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void BoundSonarQubeProject_CreateConnectionInformation_NoOrganizationNoAu
conn.Credentials.Should().BeAssignableTo<INoCredentials>();
conn.Organization.Should().BeNull();
}

[TestMethod]
public void BoundServerProject_CreateConnectionInformation_ArgCheck()
{
Expand All @@ -109,7 +109,6 @@ public void BoundServerProject_CreateConnectionInformation_NoCredentials()
conn.Credentials.Should().BeAssignableTo<INoCredentials>();
conn.Organization.Key.Should().Be("org_key");
}


[TestMethod]
public void BoundServerProject_CreateConnectionInformation_BasicAuthCredentials()
Expand Down
9 changes: 7 additions & 2 deletions src/ConnectedMode/Binding/IUnintrusiveBindingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ namespace SonarLint.VisualStudio.ConnectedMode.Binding
public interface IBindingController
{
Task BindAsync(BoundServerProject project, CancellationToken cancellationToken);

bool Unbind(string localBindingKey);
}

internal interface IUnintrusiveBindingController
{
Task BindAsync(BoundServerProject project, IProgress<FixedStepsProgress> progress, CancellationToken token);
Expand All @@ -48,7 +49,11 @@ internal class UnintrusiveBindingController : IUnintrusiveBindingController, IBi
private readonly ISolutionBindingRepository solutionBindingRepository;

[ImportingConstructor]
public UnintrusiveBindingController(IBindingProcessFactory bindingProcessFactory, ISonarQubeService sonarQubeService, IActiveSolutionChangedHandler activeSolutionChangedHandler, ISolutionBindingRepository solutionBindingRepository)
public UnintrusiveBindingController(
IBindingProcessFactory bindingProcessFactory,
ISonarQubeService sonarQubeService,
IActiveSolutionChangedHandler activeSolutionChangedHandler,
ISolutionBindingRepository solutionBindingRepository)
{
this.bindingProcessFactory = bindingProcessFactory;
this.sonarQubeService = sonarQubeService;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Binding/BoundSonarQubeProjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static ConnectionInformation CreateConnectionInformation(this BoundSonarQ
connection.Organization = binding.Organization;
return connection;
}

public static ConnectionInformation CreateConnectionInformation(this BoundServerProject binding)
{
if (binding == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public void Create_BasicAuth_CredentialsProvided_ReturnsBasicScheme()
AssertAreEqualUserNameAndPassword(Username, Password, authenticationHeaderValue.Parameter);
}

private void AssertAreEqualUserNameAndPassword(string expectedUser, string expectedPassword,
private void AssertAreEqualUserNameAndPassword(
string expectedUser,
string expectedPassword,
string userAndPasswordBase64String)

{
Expand Down
16 changes: 8 additions & 8 deletions src/SonarQube.Client.Tests/Models/ConnectionInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,23 @@ public void Ctor_SonarCloudUrl_IsProcessedCorrectly(string inputUrl)
[DataRow("http://localhost", "user1", "secret", null)]
[DataRow("http://sonarcloud.io", null, null, "myorg")]
[DataRow("http://sonarcloud.io", "a token", null, "myorg")]
public void Clone_PropertiesAreCopiedCorrectly(string serverUrl, string userName, string password, string orgKey)
public void Clone_PropertiesAreCopiedCorrectly(
string serverUrl,
string userName,
string password,
string orgKey)
{
var securePwd = InitializeSecureString(password);
var org = InitializeOrganization(orgKey);
var credentials = MockBasicAuthCredentials(userName, securePwd);

var testSubject = new ConnectionInformation(new Uri(serverUrl), credentials)
{
Organization = org
};
var testSubject = new ConnectionInformation(new Uri(serverUrl), credentials) { Organization = org };

var cloneObj = ((ICloneable)testSubject).Clone();
cloneObj.Should().BeOfType<ConnectionInformation>();

CheckPropertiesMatch(testSubject, (ConnectionInformation)cloneObj);
_= credentials.Received().Clone();
_ = credentials.Received().Clone();
}

[TestMethod]
Expand All @@ -108,8 +109,7 @@ private static SecureString InitializeSecureString(string password) =>
// The "ToSecureString" doesn't expect nulls, which we want to use in the tests
password?.ToSecureString();

private static SonarQubeOrganization InitializeOrganization(string orgKey) =>
orgKey == null ? null : new SonarQubeOrganization(orgKey, Guid.NewGuid().ToString());
private static SonarQubeOrganization InitializeOrganization(string orgKey) => orgKey == null ? null : new SonarQubeOrganization(orgKey, Guid.NewGuid().ToString());

private static void CheckPropertiesMatch(ConnectionInformation item1, ConnectionInformation item2)
{
Expand Down
6 changes: 5 additions & 1 deletion src/SonarQube.Client.Tests/SonarQubeService_TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ public void TestInitialize()
ResetService();
}

protected void SetupRequest(string relativePath, string response, HttpStatusCode statusCode = HttpStatusCode.OK, string serverUrl = DefaultBasePath) =>
protected void SetupRequest(
string relativePath,
string response,
HttpStatusCode statusCode = HttpStatusCode.OK,
string serverUrl = DefaultBasePath) =>
MocksHelper.SetupHttpRequest(messageHandler, relativePath, response, statusCode, serverUrl);

protected void SetupRequest(string relativePath, HttpResponseMessage response, params MediaTypeHeaderValue[] expectedHeaderValues) =>
Expand Down
85 changes: 54 additions & 31 deletions src/SonarQube.Client/SonarQubeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public SonarQubeService(HttpMessageHandler messageHandler, string userAgent, ILo
{
}

internal /* for testing */ SonarQubeService(HttpMessageHandler messageHandler, string userAgent, ILogger logger,
internal /* for testing */ SonarQubeService(
HttpMessageHandler messageHandler,
string userAgent,
ILogger logger,
IRequestFactorySelector requestFactorySelector,
ISecondaryIssueHashUpdater secondaryIssueHashUpdater,
ISSEStreamReaderFactory sseStreamReaderFactory)
Expand Down Expand Up @@ -110,7 +113,8 @@ private Task<TResponse> InvokeCheckedRequestAsync<TRequest, TResponse>(Cancellat
/// <param name="configure">Action that configures a type instance that implements TRequest.</param>
/// <param name="token">Cancellation token.</param>
/// <returns>Returns the result of the request invocation.</returns>
private Task<TResponse> InvokeCheckedRequestAsync<TRequest, TResponse>(Action<TRequest> configure,
private Task<TResponse> InvokeCheckedRequestAsync<TRequest, TResponse>(
Action<TRequest> configure,
CancellationToken token)
where TRequest : IRequest<TResponse>
{
Expand Down Expand Up @@ -141,11 +145,7 @@ public async Task ConnectAsync(ConnectionInformation connection, CancellationTok

httpClient = new HttpClient(messageHandler)
{
BaseAddress = connection.ServerUri,
DefaultRequestHeaders =
{
Authorization = AuthenticationHeaderFactory.Create(connection.Credentials),
},
BaseAddress = connection.ServerUri, DefaultRequestHeaders = { Authorization = AuthenticationHeaderFactory.Create(connection.Credentials), },
};

httpClient.DefaultRequestHeaders.Add("User-Agent", userAgent);
Expand Down Expand Up @@ -214,8 +214,7 @@ await InvokeCheckedRequestAsync<IGetOrganizationsRequest, SonarQubeOrganization[
},
token);

public async Task<IList<SonarQubeLanguage>> GetAllLanguagesAsync(CancellationToken token) =>
await InvokeCheckedRequestAsync<IGetLanguagesRequest, SonarQubeLanguage[]>(token);
public async Task<IList<SonarQubeLanguage>> GetAllLanguagesAsync(CancellationToken token) => await InvokeCheckedRequestAsync<IGetLanguagesRequest, SonarQubeLanguage[]>(token);

public async Task<Stream> DownloadStaticFileAsync(string pluginKey, string fileName, CancellationToken token) =>
await InvokeCheckedRequestAsync<IDownloadStaticFile, Stream>(
Expand All @@ -226,8 +225,7 @@ await InvokeCheckedRequestAsync<IDownloadStaticFile, Stream>(
},
token);

public async Task<IList<SonarQubePlugin>> GetAllPluginsAsync(CancellationToken token) =>
await InvokeCheckedRequestAsync<IGetPluginsRequest, SonarQubePlugin[]>(token);
public async Task<IList<SonarQubePlugin>> GetAllPluginsAsync(CancellationToken token) => await InvokeCheckedRequestAsync<IGetPluginsRequest, SonarQubePlugin[]>(token);

public async Task<IList<SonarQubeProject>> GetAllProjectsAsync(string organizationKey, CancellationToken token) =>
await InvokeCheckedRequestAsync<IGetProjectsRequest, SonarQubeProject[]>(
Expand Down Expand Up @@ -268,7 +266,11 @@ public async Task<IList<SonarQubeQualityProfile>> GetAllQualityProfilesAsync(str
token);
}

public async Task<SonarQubeQualityProfile> GetQualityProfileAsync(string projectKey, string organizationKey, SonarQubeLanguage language, CancellationToken token)
public async Task<SonarQubeQualityProfile> GetQualityProfileAsync(
string projectKey,
string organizationKey,
SonarQubeLanguage language,
CancellationToken token)
{
var qualityProfiles = await InvokeCheckedRequestAsync<IGetQualityProfilesRequest, SonarQubeQualityProfile[]>(
request =>
Expand Down Expand Up @@ -309,8 +311,11 @@ public async Task<SonarQubeQualityProfile> GetQualityProfileAsync(string project
qualityProfile.IsDefault, updatedDate);
}

public async Task<RoslynExportProfileResponse> GetRoslynExportProfileAsync(string qualityProfileName,
string organizationKey, SonarQubeLanguage language, CancellationToken token) =>
public async Task<RoslynExportProfileResponse> GetRoslynExportProfileAsync(
string qualityProfileName,
string organizationKey,
SonarQubeLanguage language,
CancellationToken token) =>
await InvokeCheckedRequestAsync<IGetRoslynExportProfileRequest, RoslynExportProfileResponse>(
request =>
{
Expand All @@ -320,8 +325,11 @@ await InvokeCheckedRequestAsync<IGetRoslynExportProfileRequest, RoslynExportProf
},
token);

public async Task<IList<SonarQubeIssue>> GetSuppressedIssuesAsync(string projectKey, string branch,
string[] issueKeys, CancellationToken token) =>
public async Task<IList<SonarQubeIssue>> GetSuppressedIssuesAsync(
string projectKey,
string branch,
string[] issueKeys,
CancellationToken token) =>
await InvokeCheckedRequestAsync<IGetIssuesRequest, SonarQubeIssue[]>(
request =>
{
Expand All @@ -332,7 +340,11 @@ await InvokeCheckedRequestAsync<IGetIssuesRequest, SonarQubeIssue[]>(
},
token);

public async Task<IList<SonarQubeIssue>> GetIssuesForComponentAsync(string projectKey, string branch, string componentKey, string ruleId,
public async Task<IList<SonarQubeIssue>> GetIssuesForComponentAsync(
string projectKey,
string branch,
string componentKey,
string ruleId,
CancellationToken token)
{
return await InvokeCheckedRequestAsync<IGetIssuesRequest, SonarQubeIssue[]>(
Expand All @@ -346,7 +358,9 @@ public async Task<IList<SonarQubeIssue>> GetIssuesForComponentAsync(string proje
token);
}

public async Task<IList<SonarQubeNotification>> GetNotificationEventsAsync(string projectKey, DateTimeOffset eventsSince,
public async Task<IList<SonarQubeNotification>> GetNotificationEventsAsync(
string projectKey,
DateTimeOffset eventsSince,
CancellationToken token) =>
await InvokeCheckedRequestAsync<IGetNotificationsRequest, SonarQubeNotification[]>(
request =>
Expand All @@ -365,17 +379,21 @@ await InvokeCheckedRequestAsync<IGetModulesRequest, SonarQubeModule[]>(
},
token);

public async Task<IList<string>> SearchFilesByNameAsync(string projectKey, string branch, string fileName, CancellationToken token)
public async Task<IList<string>> SearchFilesByNameAsync(
string projectKey,
string branch,
string fileName,
CancellationToken token)
{
return await InvokeCheckedRequestAsync<ISearchFilesByNameRequest, string[]>(
request =>
{
request.ProjectKey = projectKey;
request.BranchName = branch;
request.FileName = fileName;
},
token
);
request =>
{
request.ProjectKey = projectKey;
request.BranchName = branch;
request.FileName = fileName;
},
token
);
}

public async Task<IList<SonarQubeRule>> GetRulesAsync(bool isActive, string qualityProfileKey, CancellationToken token) =>
Expand All @@ -385,7 +403,7 @@ await InvokeCheckedRequestAsync<IGetRulesRequest, SonarQubeRule[]>(
request.IsActive = isActive;
request.QualityProfileKey = qualityProfileKey;
},
token);
token);

public async Task<SonarQubeRule> GetRuleByKeyAsync(string ruleKey, string qualityProfileKey, CancellationToken token)
{
Expand All @@ -395,7 +413,7 @@ public async Task<SonarQubeRule> GetRuleByKeyAsync(string ruleKey, string qualit
request.RuleKey = ruleKey;
request.QualityProfileKey = qualityProfileKey;
},
token);
token);
Debug.Assert(rules.Length <= 1);

return rules.FirstOrDefault();
Expand All @@ -409,15 +427,20 @@ await InvokeCheckedRequestAsync<IGetHotspotRequest, SonarQubeHotspot>(
},
token);

public async Task<IList<SonarQubeHotspotSearch>> SearchHotspotsAsync(string projectKey, string branch, CancellationToken token) => await InvokeCheckedRequestAsync<ISearchHotspotRequest, SonarQubeHotspotSearch[]>(
public async Task<IList<SonarQubeHotspotSearch>> SearchHotspotsAsync(string projectKey, string branch, CancellationToken token) =>
await InvokeCheckedRequestAsync<ISearchHotspotRequest, SonarQubeHotspotSearch[]>(
request =>
{
request.BranchKey = branch;
request.ProjectKey = projectKey;
},
token);

public async Task<SonarQubeIssueTransitionResult> TransitionIssueAsync(string issueKey, SonarQubeIssueTransition transition, string optionalComment, CancellationToken token)
public async Task<SonarQubeIssueTransitionResult> TransitionIssueAsync(
string issueKey,
SonarQubeIssueTransition transition,
string optionalComment,
CancellationToken token)
{
var transitionResult = await InvokeCheckedRequestAsync<ITransitionIssueRequest, SonarQubeIssueTransitionResult>(
request =>
Expand Down

0 comments on commit f45e20b

Please sign in to comment.