public Task <Result <ComponentResponse[]> > GetComponentsSearchProjectsAsync(ComponentRequest request,
                                                                              CancellationToken token)
 {
     // Since 6.2; internal
     return(InvokeSonarQubeApi("api/components/search_projects", request, token,
                               stringResponse => JObject.Parse(stringResponse)["components"].ToObject <ComponentResponse[]>()));
 }
        public async Task <IList <SonarQubeProject> > GetAllProjectsAsync(string organizationKey, CancellationToken token)
        {
            EnsureIsConnected();

            if (organizationKey == null) // Orgs are not supported or not enabled
            {
                var projectsResult = await this.sonarqubeClient.GetProjectsAsync(token);

                projectsResult.EnsureSuccess();

                return(projectsResult.Value.Select(SonarQubeProject.FromResponse).ToList());
            }

            int currentPage = 1;
            var allProjects = new List <ComponentResponse>();
            Result <ComponentResponse[]> componentsResult;

            do
            {
                var request = new ComponentRequest
                {
                    Page            = currentPage,
                    PageSize        = MaximumPageSize,
                    OrganizationKey = organizationKey,
                };
                componentsResult = await this.sonarqubeClient.GetComponentsSearchProjectsAsync(request, token);

                componentsResult.EnsureSuccess();

                allProjects.AddRange(componentsResult.Value);
                currentPage++;
            }while (componentsResult.Value.Length > 0);

            return(allProjects.Select(SonarQubeProject.FromResponse).ToList());
        }
        public void GetComponentsSearchProjectsAsync_WhenExceptionThrown_PropagateIt()
        {
            var request = new ComponentRequest {
                OrganizationKey = "org", Page = 42, PageSize = 25
            };

            Method_WhenExceptionThrown_PropagateIt((c, t) => c.GetComponentsSearchProjectsAsync(request, t));
        }
        public void GetComponentsSearchProjectsAsync_WhenCancellationRequested_ThrowsException()
        {
            var request = new ComponentRequest {
                OrganizationKey = "org", Page = 42, PageSize = 25
            };

            Method_WhenCancellationRequested_ThrowsException((c, t) => c.GetComponentsSearchProjectsAsync(request, t));
        }
        public async Task GetComponentsSearchProjectsAsync_WhenRequestIsNotSuccess_ReturnsDefaultAndErrorCode()
        {
            var request = new ComponentRequest {
                OrganizationKey = "org", Page = 42, PageSize = 25
            };

            await Method_WhenRequestIsNotSuccess_ReturnsDefaultAndErrorCode(
                (c, t) => c.GetComponentsSearchProjectsAsync(request, t), HttpStatusCode.InternalServerError);
        }
        public async Task GetComponentsSearchProjectsAsync_CallsTheExpectedUri()
        {
            var request = new ComponentRequest {
                OrganizationKey = "org", Page = 42, PageSize = 25
            };

            await Method_CallsTheExpectedUri(
                new Uri("api/components/search_projects?p=42&ps=25&organization=org&asc=true", UriKind.RelativeOrAbsolute),
                @"{""components"":[]}", (c, t) => c.GetComponentsSearchProjectsAsync(request, t));
        }
        public async Task GetComponentsSearchProjectsAsync_WhenRequestIsSuccesful_ReturnsIsSuccessAndNotNullData()
        {
            var request = new ComponentRequest {
                OrganizationKey = "org", Page = 42, PageSize = 25
            };

            await Method_WhenRequestIsSuccesful_ReturnsIsSuccessAndNotNullData(
                (c, t) => c.GetComponentsSearchProjectsAsync(request, t),
                @"{""components"":[{""organization"":""my - org - key - 1"",""id"":""AU - Tpxb--iU5OvuD2FLy"",""key"":""my_project"",""name"":""My Project 1"",""isFavorite"":true,""tags"":[""finance"",""java""],""visibility"":""public""},{""organization"":""my-org-key-1"",""id"":""AU-TpxcA-iU5OvuD2FLz"",""key"":""another_project"",""name"":""My Project 2"",""isFavorite"":false,""tags"":[],""visibility"":""public""}]}",
                result => result.Length.Should().Be(2));
        }
Example #8
0
        /*************************************/
        /**** Private Methods             ****/
        /*************************************/

        private static void M_SearchMenu_ItemSelected(object sender, ComponentRequest request)
        {
            ItemSelected?.Invoke(sender, request);
        }