// / <summary> // / get all of the work item links by paging through list // / </summary> // / <returns>BatchOfWorkItemLinksResponse.WorkItemLinks</returns> public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinksAll() { BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); BatchOfWorkItemLinksResponse.WorkItemLinks tempViewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); List <BatchOfWorkItemLinksResponse.Value> list = new List <BatchOfWorkItemLinksResponse.Value>(); HttpResponseMessage response; using (var client = new HttpClient()) { client.BaseAddress = new Uri(_configuration.UriString); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); response = client.GetAsync("_apis/wit/reporting/workitemlinks?api-version=2.0").Result; if (!response.IsSuccessStatusCode) { viewModel.HttpStatusCode = response.StatusCode; return(viewModel); } else { // read from response tempViewModel = response.Content.ReadAsAsync <BatchOfWorkItemLinksResponse.WorkItemLinks>().Result; // and add values to list object list.AddRange(tempViewModel.values); // keep looping through the list untill done // loop thru until isLastBatch = true while (!tempViewModel.isLastBatch) { // using watermarked nextLink value, get next page from list response = client.GetAsync(tempViewModel.nextLink).Result; if (!response.IsSuccessStatusCode) { viewModel.HttpStatusCode = response.StatusCode; return(viewModel); } else { // read and add to your list tempViewModel = response.Content.ReadAsAsync <BatchOfWorkItemLinksResponse.WorkItemLinks>().Result; list.AddRange(tempViewModel.values); } } // loaded all pages, now set value in viewModel with list object so we can send the entire list back viewModel.values = list.ToArray <BatchOfWorkItemLinksResponse.Value>(); viewModel.HttpStatusCode = response.StatusCode; return(viewModel); } } }
public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksForAll_Success() { // arrange Reporting request = new Reporting(_configuration); // act BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinksAll(); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); }
public void WorkItemTracking_Reporting_GetBatchOfWorkItemLinksByProjectAndDate_Success() { // arrange Reporting request = new Reporting(_configuration); // act BatchOfWorkItemLinksResponse.WorkItemLinks response = request.GetBatchOfWorkItemLinks(_configuration.Project, new DateTime(2016, 3, 15)); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); request = null; }
// / <summary> // / get a batch of work item links starting at a specific start date and scoped to a project // / </summary> // / <param name="project">project name or id</param> // / <param name="startDateTime"></param> // / <returns>BatchOfWorkItemLinksResponse.WorkItemLinks</returns> public BatchOfWorkItemLinksResponse.WorkItemLinks GetBatchOfWorkItemLinks(string project, DateTime startDateTime) { BatchOfWorkItemLinksResponse.WorkItemLinks viewModel = new BatchOfWorkItemLinksResponse.WorkItemLinks(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(_configuration.UriString); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials); HttpResponseMessage response = client.GetAsync(project + "/_apis/wit/reporting/workitemlinks?startDateTime=" + startDateTime.ToShortDateString() + "&api-version=2.0").Result; if (response.IsSuccessStatusCode) { viewModel = response.Content.ReadAsAsync <BatchOfWorkItemLinksResponse.WorkItemLinks>().Result; } viewModel.HttpStatusCode = response.StatusCode; return(viewModel); } }