Example #1
0
        private void ReturnValueForPostAsync(bool alreadyExist)
        {
            string jsonVideo = SerializeCharge(alreadyExist);
            var    response  = CreateResponse(jsonVideo);

            client.PostAsync(Arg.Any <string>(), Arg.Any <HttpContent>()).Returns(response);
        }
Example #2
0
        public async Task <SearchIssuesResponse> GetIssuesAsync(SonarRequestGetIssues sonarSettingRequest)
        {
            if (sonarSettingRequest == null || _sonarSettings == null)
            {
                return(null);
            }
            if (sonarSettingRequest.NbIssuesPerRequest == default(int))
            {
                sonarSettingRequest.NbIssuesPerRequest = _sonarSettings.NbIssuesPerRequestDefault;
            }

            SearchIssuesResponse searchIssuesResponse = new SearchIssuesResponse();

            searchIssuesResponse.issues = new List <Issues>();
            bool needToRetrieveNextIssues = true;
            int  pageNumber = 1;

            while (needToRetrieveNextIssues)
            {
                List <KeyValuePair <string, string> > args = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("ps", sonarSettingRequest.NbIssuesPerRequest.ToString()),
                    new KeyValuePair <string, string>("assigned", "true"),
                    new KeyValuePair <string, string>("p", pageNumber.ToString()),
                    new KeyValuePair <string, string>("createdAfter", sonarSettingRequest.DateFrom.ToString("yyyy-MM-dd")),// "2017-10-01"));
                    new KeyValuePair <string, string>("createdBefore", sonarSettingRequest.DateTo.ToString("yyyy-MM-dd")),
                    new KeyValuePair <string, string>("statuses", "OPEN,REOPENED"),
                    new KeyValuePair <string, string>("severities", "CRITICAL, MAJOR"),
                    new KeyValuePair <string, string>("languages", "cs")
                };
                if (sonarSettingRequest.Users != null)
                {
                    args.Add(new KeyValuePair <string, string>("assignees", string.Join(",", sonarSettingRequest.Users)));
                }
                SearchIssuesResponse result = await _httpApiClient.PostAsync <SearchIssuesResponse>(args, _sonarSettings.Uri_GetIssues, _sonarSettings.Token);

                if (result?.issues == null)
                {
                    break;
                }
                searchIssuesResponse.issues.AddRange(result.issues);
                needToRetrieveNextIssues = sonarSettingRequest.NbIssuesPerRequest == result.issues.Count;
                pageNumber++;
            }

            return(searchIssuesResponse);
        }
        public virtual async Task <bool> NotifyNewCharge(ActivityDto identifier)
        {
            string requestUri = string.Format("{0}/api/ChargeActivity/add", server);
            var    content    = GivenAHttpContent(identifier, requestUri);
            var    result     = await httpApiClient.PostAsync(requestUri, content);

            if (result.StatusCode == HttpStatusCode.OK)
            {
                return(true);
            }
            return(false);
        }
Example #4
0
        public virtual async Task <ChargeResponse> AddCharge(Charge newCharge)
        {
            string requestUri = string.Format("{0}/api/charges/add", server);
            var    content    = GivenAHttpContent(newCharge, requestUri);
            var    result     = await client.PostAsync(requestUri, content);

            ChargeResponse response = JsonConvert.DeserializeObject <ChargeResponse>(result.Content.ReadAsStringAsync().GetAwaiter().GetResult());

            if (result.StatusCode == HttpStatusCode.OK && response.alreadyExist)
            {
                return(new ChargeAlreadyExist());
            }
            if (result.StatusCode == HttpStatusCode.OK && !response.alreadyExist)
            {
                return(new ChargeResponseOK());
            }
            throw new Exception("TODO");
        }
 private static void valuesReturnForPost(IHttpApiClient client)
 {
     client.PostAsync(Arg.Any <string>(), Arg.Any <HttpContent>()).Returns(new HttpResponseMessage(HttpStatusCode.OK));
 }