Esempio n. 1
0
        public void WorkItemTracking_Queries_GetQueryByPath_Success()
        {
            // arrange
            Queries request = new Queries(_configuration);

            // act
            GetQueriesByIdResponse.Queries response = request.GetQueryByPath(_configuration.Project, _configuration.Query);

            // assert
            if (response.HttpStatusCode == HttpStatusCode.NotFound)
            {
                Assert.Inconclusive("query '" + _configuration.Query + "' not found");
            }
            else
            {
                Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode);
            }

            request = null;
        }
        // / <summary>
        // / get queries for a specific query path
        // / </summary>
        // / <param name="project">project name or id</param>
        // / <param name="path">full query path</param>
        // / <returns>ListofQueriesByFolderPath.Queries</returns>
        public GetQueriesByIdResponse.Queries GetQueryByPath(string project, string path)
        {
            GetQueriesByIdResponse.Queries viewModel = new GetQueriesByIdResponse.Queries();

            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/queries/" + path + "?api-version=2.2").Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <GetQueriesByIdResponse.Queries>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }