public Task <Result <QualityProfileChangeLogResponse> > GetQualityProfileChangeLogAsync(
     QualityProfileChangeLogRequest request, CancellationToken token)
 {
     // Since 5.2
     return(InvokeSonarQubeApi("api/qualityprofiles/changelog", request, token,
                               stringResponse => ProcessJsonResponse <QualityProfileChangeLogResponse>(stringResponse, token)));
 }
        public void GetQualityProfileChangeLogAsync_WhenExceptionThrown_PropagateIt()
        {
            var request = new QualityProfileChangeLogRequest {
                QualityProfileKey = "qp", PageSize = 25
            };

            Method_WhenExceptionThrown_PropagateIt((c, t) => c.GetQualityProfileChangeLogAsync(request, t));
        }
        public void GetQualityProfileChangeLogAsync_WhenCancellationRequested_ThrowsException()
        {
            var request = new QualityProfileChangeLogRequest {
                QualityProfileKey = "qp", PageSize = 25
            };

            Method_WhenCancellationRequested_ThrowsException((c, t) => c.GetQualityProfileChangeLogAsync(request, t));
        }
        public async Task GetQualityProfileChangeLogAsync_WhenRequestIsNotSuccess_ReturnsDefaultAndErrorCode()
        {
            var request = new QualityProfileChangeLogRequest {
                QualityProfileKey = "qp", PageSize = 25
            };

            await Method_WhenRequestIsNotSuccess_ReturnsDefaultAndErrorCode(
                (c, t) => c.GetQualityProfileChangeLogAsync(request, t), HttpStatusCode.InternalServerError);
        }
        public async Task GetQualityProfileChangeLogAsync_CallsTheExpectedUri()
        {
            var request = new QualityProfileChangeLogRequest {
                QualityProfileKey = "qp", PageSize = 25
            };

            await Method_CallsTheExpectedUri(new Uri("api/qualityprofiles/changelog?profileKey=qp&ps=25", UriKind.RelativeOrAbsolute),
                                             "", (c, t) => c.GetQualityProfileChangeLogAsync(request, t));
        }
        public async Task GetQualityProfileChangeLogAsync_WhenRequestIsSuccesful_ReturnsIsSuccessAndNotNullData()
        {
            var request = new QualityProfileChangeLogRequest {
                QualityProfileKey = "qp", PageSize = 25
            };

            await Method_WhenRequestIsSuccesful_ReturnsIsSuccessAndNotNullData(
                (c, t) => c.GetQualityProfileChangeLogAsync(request, t),
                @"{""events"":[{""date"":""2015-02-23T17:58:39+0100"",""action"":""ACTIVATED"",""authorLogin"":""anakin.skywalker"",""authorName"":""Anakin Skywalker"",""ruleKey"":""squid:S2438"",""ruleName"":""\""Threads\"" should not be used where \""Runnables\"" are expected"",""params"":{""severity"":""CRITICAL""}}]}",
                result => result.Events.Length.Should().Be(1));
        }
        public async Task <SonarQubeQualityProfile> GetQualityProfileAsync(string projectKey, string organizationKey,
                                                                           SonarQubeLanguage language, CancellationToken token)
        {
            EnsureIsConnected();

            var qualityProfileRequest = new QualityProfileRequest {
                ProjectKey = projectKey, OrganizationKey = organizationKey
            };
            var qualityProfilesResult = await this.sonarqubeClient.GetQualityProfilesAsync(qualityProfileRequest, token);

            // Special handling for the case when a project was not analyzed yet, in which case a 404 is returned
            if (qualityProfilesResult.StatusCode == HttpStatusCode.NotFound)
            {
                qualityProfileRequest = new QualityProfileRequest {
                    ProjectKey = null, OrganizationKey = organizationKey
                };
                qualityProfilesResult = await this.sonarqubeClient.GetQualityProfilesAsync(qualityProfileRequest, token);
            }

            qualityProfilesResult.EnsureSuccess();

            var profilesWithGivenLanguage = qualityProfilesResult.Value.Where(x => x.Language == language.Key).ToList();

            var qualityProfile = profilesWithGivenLanguage.Count > 1
                ? profilesWithGivenLanguage.Single(x => x.IsDefault)
                : profilesWithGivenLanguage.Single();

            var qualityProfileChangeLogRequest = new QualityProfileChangeLogRequest
            {
                PageSize          = 1,
                QualityProfileKey = qualityProfile.Key
            };
            var changeLog = await this.sonarqubeClient.GetQualityProfileChangeLogAsync(qualityProfileChangeLogRequest, token);

            changeLog.EnsureSuccess();

            return(SonarQubeQualityProfile.FromResponse(qualityProfile, changeLog.Value.Events.Single().Date));
        }