Skip to content

Commit

Permalink
Projects cannot be retrieved from sonarcloud.io and SonarQube 6.4+ wi…
Browse files Browse the repository at this point in the history
…th organizations enabled.
  • Loading branch information
Valeri Hristov authored and valhristov committed Jun 21, 2017
1 parent bed8859 commit c9cfd87
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/Integration.UnitTests/Service/SonarQubeServiceWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,48 @@ public void SonarQubeServiceWrapper_TryGetProjects()
}
}

[TestMethod]
public void SonarQubeServiceWrapper_TryGetProjects_Organization()
{
var p1 = new ComponentResult
{
Name = "Project 1",
Key = "1"
};
var p2 = new ComponentResult
{
Name = "Project 2",
Key = "2"
};

using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider))
{
testSubject.RegisterQueryValidator("api/components/search_projects", request =>
{
request.QueryString.HasValue.Should().BeTrue();
request.QueryString.Value.Should().Be("asc=true&organization=myorg&ps=500&p=1");
});

// Arrange
testSubject.AllowAnonymous = true;
testSubject.RegisterRequestHandler("api/components/search_projects?asc=true&organization=myorg&ps=500&p=1",
new RequestHandler { ResponseText = Serialize(new { paging = new { total = 0 }, components = new[] { p1 } }) });
var connectionInfo1 = new ConnectionInformation(new Uri("http://server"))
{
Organization = new OrganizationInformation { Key = "myorg", Name = "My org" }
};

// Act
ProjectInformation[] projects = null;
testSubject.TryGetProjects(connectionInfo1, CancellationToken.None, out projects)
.Should().BeTrue("Expected to get the projects");

// Assert
projects.Should().Equal(new[] { p1 }, (x, y) => x.Key == y.Key && x.Name == y.Name);
this.outputWindowPane.AssertOutputStrings(0);
}
}

[TestMethod]
public void SonarQubeServiceWrapper_TryGetProjects_InvalidStatusCode()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Integration/Service/SonarQubeServiceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private async Task<ProjectInformation[]> DownloadProjects(HttpClient configuredC

do
{
var query = string.Format("{0}?asc&organization={1}&ps={2}&p={3}", SearchProjectsAPI, organizationKey,
var query = string.Format("{0}?asc=true&organization={1}&ps={2}&p={3}", SearchProjectsAPI, organizationKey,
MaxAllowedPageSize, currentPage);
var httpResponse = await InvokeGetRequest(configuredClient, query, token);
var stringResponse = await ReadResponse(httpResponse, token);
Expand Down

0 comments on commit c9cfd87

Please sign in to comment.