Ejemplo n.º 1
0
        public static async Task <List <TestCase> > GetTestCaseFailedWithMinorDefect(string testCasePath)
        {
            HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
            HttpClient          newClient = client.CreateHttpClient();

            newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var requestUri = string.Format("api/TestCase/FailedWithMinorDefects?testCasePath={0}", testCasePath);

            var method  = new HttpMethod("GET");
            var request = new HttpRequestMessage(method, requestUri)
            {
            };
            var response = await newClient.SendAsync(request);

            string workItem = await response.Content.ReadAsStringAsync();

            List <TestCase> res = new List <TestCase>();

            if (response.IsSuccessStatusCode)
            {
                JObject jObject = JObject.Parse(workItem);
                JArray  ja      = jObject["values"].ToObject <JArray>();

                foreach (JObject jo in ja)
                {
                    res.Add(jo.ToObject <TestCase>());
                }
            }

            return(res);
        }
Ejemplo n.º 2
0
        public static async Task <TestCase> GetTestCaseById(int id)
        {
            HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
            HttpClient          newClient = client.CreateHttpClient();

            newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var requestUri = "/api/TestCase/" + id;
            var method     = new HttpMethod("GET");
            var request    = new HttpRequestMessage(method, requestUri)
            {
            };
            var response = await newClient.SendAsync(request);

            string workItem = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                JObject jObject = JObject.Parse(workItem);

                return(jObject.ToObject <TestCase>());
            }
            else
            {
                throw new Exception();
            }
        }
Ejemplo n.º 3
0
        public static async Task <List <TestCase> > GetTestCaseByPlan(int planId)
        {
            List <TestCase> res = new List <TestCase>();

            HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
            HttpClient          newClient = client.CreateHttpClient();

            newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var requestUri = "/api/TestCase/Plan/" + planId;
            var method     = new HttpMethod("GET");
            var request    = new HttpRequestMessage(method, requestUri)
            {
            };
            var response = await newClient.SendAsync(request);

            string workItem = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                JObject jObject = JObject.Parse(workItem);
                JArray  ja      = jObject["values"].ToObject <JArray>();

                Console.WriteLine("Parsed item");

                foreach (JObject jo in ja)
                {
                    res.Add(jo.ToObject <TestCase>());
                }
            }

            return(res);
        }
Ejemplo n.º 4
0
        public GetDefectWithTestCaseCount(Properties props)
        {
            _project      = props.Project;
            _fileLocation = props.SaveLocation;
            _testPlanId   = props.TestPlanId;
            _testSuite    = props.TestSuiteId;

            _logger = props.Logger;
            HttpClientInitiator clientInitator = new HttpClientInitiator(props.Uri, props.PersonalAccessToken);

            _client = clientInitator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            _testCaseIdToResults = new Dictionary <int, List <TestCaseResult> >();

            _tfsCommonFunctions = new TFSCommonFunctions(props);

            if (props.UseWebApi == 1)
            {
                _allTestCaseId = GetTestCasesWebApi.GetAllTestCaseIds().Result;
            }
            else
            {
                GetTestCasesInSuite getTestCaseInSuite = new GetTestCasesInSuite(props);
                List <TestCase>     allTestCases       = getTestCaseInSuite.GatherTestCases();
                _allTestCaseId = new List <int>();
                foreach (TestCase currTestCase in allTestCases)
                {
                    _allTestCaseId.Add(currTestCase.TestCaseId);
                }
            }
        }
        private async void InsertSingleTestScenario(TestScenario testScenario)
        {
            HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
            HttpClient          newClient = client.CreateHttpClient();

            newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var patchValue = new StringContent(JsonConvert.SerializeObject(testScenario,
                                                                           Formatting.None,
                                                                           new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }), Encoding.UTF8, "application/json");

            var requestUri = "/api/TestScenario";
            var method     = new HttpMethod("PATCH");
            var request    = new HttpRequestMessage(method, requestUri)
            {
                Content = patchValue
            };
            var response = await newClient.SendAsync(request);

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException();
            }
        }
Ejemplo n.º 6
0
        //public async Task<List<TestCase>> GetTestCaseExecutedCumulativeAndPath(DateTime dateTime, string path)
        //{
        //    HttpClientInitiator client = new HttpClientInitiator("https://localhost:44369/");
        //    HttpClient newClient = client.CreateHttpClient();
        //    newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

        //    var requestUri = string.Format("api/TestCase/ByResultDateAndPath?dateTime={0}&");
        //    var method = new HttpMethod("GET");
        //    var request = new HttpRequestMessage(method, requestUri) { };
        //    var response = await newClient.SendAsync(request);

        //    return null;
        //}

        public static async Task <List <TestCase> > GetTestCaseExecutedCumulativeAndPathAndStatuses(DateTime dateTime, string[] statuses, string path)
        {
            HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
            HttpClient          newClient = client.CreateHttpClient();

            newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var requestUri = string.Format("api/TestCase/ByResultDateAndPath?dateTime={0}&statuses={1}&path={2}&cumulative=1",
                                           dateTime.ToString("yyyy-MM-dd"),
                                           String.Join(",", statuses),
                                           path);
            var method  = new HttpMethod("GET");
            var request = new HttpRequestMessage(method, requestUri)
            {
            };
            var response = await newClient.SendAsync(request);

            string workItem = await response.Content.ReadAsStringAsync();

            List <TestCase> res = new List <TestCase>();

            if (response.IsSuccessStatusCode)
            {
                JObject jObject = JObject.Parse(workItem);
                JArray  ja      = jObject["values"].ToObject <JArray>();

                foreach (JObject jo in ja)
                {
                    res.Add(jo.ToObject <TestCase>());
                }
            }

            return(res);
        }
        public List <int> DeleteNonExistingTestsCases(List <TestCase> allTestCases = null)
        {
            List <int> deletedTestCases = new List <int>();

            GetTestCasesInSuite getTestCasesInSuite = new GetTestCasesInSuite(_props);
            List <TestCase>     allTestCasesInSuite;

            if (allTestCases == null)
            {
                allTestCasesInSuite = getTestCasesInSuite.GatherTestCases();
            }
            else
            {
                allTestCasesInSuite = allTestCases;
            }

            List <int> allTestCaseIdInSuite = new List <int>();

            foreach (TestCase curr in allTestCasesInSuite)
            {
                allTestCaseIdInSuite.Add(curr.TestCaseId);
            }

            TestCaseWebApiTools testCaseWebApiTools = new TestCaseWebApiTools();
            List <int>          allTestCasesInDb    = testCaseWebApiTools.GetAllTestCaseIds().Result;

            foreach (int currId in allTestCasesInDb)
            {
                if (!allTestCaseIdInSuite.Contains(currId))
                {
                    deletedTestCases.Add(currId);
                }
            }

            Console.WriteLine("Test");
            Console.WriteLine(deletedTestCases.Count);

            foreach (int curr in deletedTestCases)
            {
                Console.WriteLine(curr);
                HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
                HttpClient          newClient = client.CreateHttpClient();
                newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                string requestUri = "/api/TestCase/" + curr;
                var    method     = new HttpMethod("DELETE");
                var    request    = new HttpRequestMessage(method, requestUri)
                {
                };
                var response = newClient.SendAsync(request).Result;
            }

            return(deletedTestCases);
        }
Ejemplo n.º 8
0
        public Downloader(Properties props)
        {
            _saveLocation                = props.SaveLocation;
            _uri                         = props.Uri;
            _personalAccessToken         = props.PersonalAccessToken;
            _testCasesMissingAttachments = new List <TestCase>();
            _basePath                    = props.BasePath;

            HttpClientInitiator initiator = new HttpClientInitiator(_uri, _personalAccessToken);

            _client = initiator.CreateHttpClient();
        }
Ejemplo n.º 9
0
        public CreatePlaybooks(Properties props)
        {
            _uri = props.Uri;
            _personalAccessToken = props.PersonalAccessToken;
            _project             = props.Project;

            _logger = props.Logger;

            HttpClientInitiator clientInitiator = new HttpClientInitiator(_uri, _personalAccessToken);

            _client = clientInitiator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }
Ejemplo n.º 10
0
        public GetWorkItemType(Properties props)
        {
            _project      = props.Project;
            _fileLocation = props.SaveLocation;
            _testPlanId   = props.TestPlanId;
            _testSuite    = props.TestSuiteId;

            _logger = props.Logger;
            HttpClientInitiator clientInitator = new HttpClientInitiator(props.Uri, props.PersonalAccessToken);

            _client = clientInitator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }
Ejemplo n.º 11
0
        public CreateTestCase()
        {
            _uri = "http://10.3.16.122/";
            _personalAccessToken = "EXAMPLEACCESSTOKEN";
            _project             = "APHP";
            _testPlan            = 156611;
            _testSuite           = 156696;
            _logger = new Logger();

            HttpClientInitiator clientInitator = new HttpClientInitiator(_uri, _personalAccessToken);

            _client = clientInitator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }
Ejemplo n.º 12
0
        public TFSCommonFunctions(Properties props)
        {
            string _uri = props.Uri;
            string _personalAccessToken = props.PersonalAccessToken;

            _project      = props.Project;
            _saveLocation = props.SaveLocation;
            _logger       = props.Logger;

            HttpClientInitiator clientInitator = new HttpClientInitiator(_uri, _personalAccessToken);

            _client = clientInitator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }
Ejemplo n.º 13
0
        public TFSExecutionResults(Properties props)
        {
            _project      = props.Project;
            _fileLocation = props.SaveLocation;
            _testPlanId   = props.TestPlanId;
            _testSuite    = props.TestSuiteId;

            _logger = props.Logger;
            HttpClientInitiator clientInitator = new HttpClientInitiator(props.Uri, props.PersonalAccessToken);

            _client = clientInitator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            _testCaseIdToResults = new Dictionary <int, List <TestCaseResult> >();
        }
Ejemplo n.º 14
0
        public LinkTestCaseToRtm(Properties props)
        {
            _uri = props.Uri;
            _personalAccessToken = props.PersonalAccessToken;
            _project             = props.Project;
            _saveLocation        = props.SaveLocation;
            _testPlan            = props.TestPlanId;
            _testSuite           = props.TestSuiteId;

            _logger = props.Logger;

            HttpClientInitiator clientInitiator = new HttpClientInitiator(_uri, _personalAccessToken);

            _client = clientInitiator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }
        public UpdateContractRequirement(Properties props)
        {
            _props = props;

            _uri = props.Uri;
            _personalAccessToken = props.PersonalAccessToken;
            _project             = props.Project;

            _logger = props.Logger;

            _dictionary = new Dictionary <string, int>();

            HttpClientInitiator clientInitiator = new HttpClientInitiator(_uri, _personalAccessToken);

            _client = clientInitiator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Constructor. Manaully set values to match your account.
        /// </summary>
        public Attachments(Properties props)
        {
            string _uri = props.Uri;
            string _personalAccessToken = props.PersonalAccessToken;

            _project        = props.Project;
            _saveLocation   = props.SaveLocation;
            _testPlanId     = props.TestPlanId;
            _testSuiteId    = props.TestSuiteId;
            _firstIteration = true;

            _logger = new Logger(_saveLocation);

            HttpClientInitiator clientInitator = new HttpClientInitiator(_uri, _personalAccessToken);

            _client = clientInitator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }
Ejemplo n.º 17
0
        public GetTestCasesInSuite(Properties props, int planId, int suiteId)
        {
            _uri = props.Uri;
            _personalAccessToken = props.PersonalAccessToken;
            _project             = props.Project;
            _testPlanId          = planId;
            _testSuiteId         = suiteId;
            _firstIteration      = true;

            _logger = props.Logger;

            _props = props;

            HttpClientInitiator clientInitiator = new HttpClientInitiator(_uri, _personalAccessToken);

            _client = clientInitiator.CreateHttpClient();
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        }
Ejemplo n.º 18
0
        public void GatherTestRunAndResultsAndWriteToDb(Properties props)
        {
            GatherTestRun  gatherTestRun = new GatherTestRun(props);
            List <TestRun> testRuns      = gatherTestRun.GatherTestRunWithTestResult();

            Console.WriteLine("Number of Test Runs: {0}", testRuns.Count);

            Console.Write("Writing Test Runs and Test Results to DB...  ");
            int numTestRun = testRuns.Count;

            using (var progress = new ProgressBar())
            {
                int currentCount = 1;
                foreach (TestRun currTestRun in testRuns)
                {
                    progress.Report((double)currentCount / (double)numTestRun);

                    HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
                    HttpClient          newClient = client.CreateHttpClient();
                    newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                    var patchValue = new StringContent(JsonConvert.SerializeObject(currTestRun,
                                                                                   Formatting.None,
                                                                                   new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }), Encoding.UTF8, "application/json");

                    var requestUri = "/api/TestRun";
                    var method     = new HttpMethod("PATCH");
                    var request    = new HttpRequestMessage(method, requestUri)
                    {
                        Content = patchValue
                    };
                    string requestTxt = request.Content.ToString();
                    var    response   = newClient.SendAsync(request).Result;

                    currentCount += 1;
                }

                Console.WriteLine("Done.");
            }
        }
        public void PostHelper <T>(IEnumerable <T> entity, string endpoint)
        {
            using (var progress = new ProgressBar())
            {
                double totalCount = entity.Count <T>();
                double currCount  = 1;

                foreach (T curr in entity)
                {
                    currCount += 1;
                    progress.Report(currCount / totalCount);

                    HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
                    HttpClient          newClient = client.CreateHttpClient();
                    newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                    //currTestCase.TestCaseId = 114113;

                    var patchValue = new StringContent(JsonConvert.SerializeObject(curr,
                                                                                   Formatting.None,
                                                                                   new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }), Encoding.UTF8, "application/json");

                    var requestUri = endpoint;
                    var method     = new HttpMethod("POST");
                    var request    = new HttpRequestMessage(method, requestUri)
                    {
                        Content = patchValue
                    };
                    string requestTxt = request.Content.ToString();
                    var    response   = newClient.SendAsync(request).Result;

                    _props.Logger.Log(requestUri);
                    _props.Logger.Log(requestTxt);
                }
            }
        }
Ejemplo n.º 20
0
        public async Task <List <Defect> > UpdateListDefects(List <Defect> entities)
        {
            List <Defect> res = new List <Defect>();

            foreach (Defect currDefect in entities)
            {
                currDefect.TestCases = null;

                HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
                HttpClient          newClient = client.CreateHttpClient();
                newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                var patchValue = new StringContent(JsonConvert.SerializeObject(currDefect,
                                                                               Formatting.None,
                                                                               new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                }), Encoding.UTF8, "application/json");

                var requestUri = "/api/Defect";
                var method     = new HttpMethod("POST");
                var request    = new HttpRequestMessage(method, requestUri)
                {
                    Content = patchValue
                };
                Console.WriteLine(request.ToString());

                var response = await newClient.SendAsync(request);

                string workItem = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    res.Add(currDefect);
                }
            }

            return(res);
        }
Ejemplo n.º 21
0
        private async Task <List <TestRun> > GatherTestCaseRunsAPI()
        {
            List <TestRun>      res       = new List <TestRun>();
            HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
            HttpClient          newClient = client.CreateHttpClient();

            var requestUri = "api/TestRun";
            var method     = new HttpMethod("GET");
            var request    = new HttpRequestMessage(method, requestUri)
            {
            };
            var response = await newClient.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                string responseTxt = await response.Content.ReadAsStringAsync();

                _logger.Log(responseTxt);

                var jo = JArray.Parse(responseTxt);

                foreach (JToken currTestRun in jo)
                {
                    TestRun testRun = new TestRun();
                    testRun.TestRunId   = Convert.ToInt32(currTestRun["testRunId"]);
                    testRun.TestRunName = currTestRun["testRunName"].ToString();
                    testRun.PassedTests = Convert.ToInt32(currTestRun["passedTests"]);
                    testRun.State       = currTestRun["state"].ToString();

                    if (currTestRun["testSuiteId"].ToString() != "")
                    {
                        testRun.TestSuiteId = Convert.ToInt32(currTestRun["testSuiteId"]);
                    }

                    if (currTestRun["testPlanId"].ToString() != "")
                    {
                        testRun.TestPlanId = Convert.ToInt32(currTestRun["testPlanId"]);
                    }

                    List <TestCaseResult> allTestCaseResults = new List <TestCaseResult>();

                    //Console.WriteLine(currTestRun["testRunId"].ToString());
                    foreach (JToken currTestResult in currTestRun["testCaseResults"])
                    {
                        if (currTestResult["testCaseResultId"] != null)
                        {
                            TestCaseResult testCaseResult = new TestCaseResult
                            {
                                TestCaseResultId = Convert.ToInt32(currTestResult["testCaseResultId"]),
                                TestRunId        = testRun.TestRunId,
                                TestCaseId       = Convert.ToInt32(currTestResult["testCaseId"]),
                                Result           = currTestResult["result"].ToString(),
                                RunByName        = currTestResult["runByName"].ToString(),
                                ResultDT         = DateTime.Parse(currTestResult["resultDT"].ToString())
                            };

                            if (!_testCaseIdToResults.ContainsKey(testCaseResult.TestCaseId))
                            {
                                _testCaseIdToResults[testCaseResult.TestCaseId] = new List <TestCaseResult> {
                                    testCaseResult
                                };
                            }
                            else
                            {
                                _testCaseIdToResults[testCaseResult.TestCaseId].Add(testCaseResult);
                            }
                        }
                    }

                    if (allTestCaseResults.Count > 0)
                    {
                        testRun.TestCaseResults = allTestCaseResults;
                    }

                    res.Add(testRun);
                }

                return(res);
            }
            else
            {
                throw new Exception();
            }
        }
Ejemplo n.º 22
0
        public async Task <TestCase> GatherTestCase(TestCase testCase)
        {
            var requestUri                = "/api/TestCase/" + testCase.TestCaseId;
            HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
            HttpClient          newClient = client.CreateHttpClient();
            //var requestUri = "/APHP/_apis/wit/workitems/" + testCase.TestCaseId + "?api-version=3.0";
            var method  = new HttpMethod("GET");
            var request = new HttpRequestMessage(method, requestUri)
            {
            };
            var response = await newClient.SendAsync(request);

            _logger.Log(requestUri);

            if (response.IsSuccessStatusCode)
            {
                string responseTxt = await response.Content.ReadAsStringAsync();

                _logger.Log(responseTxt);

                JObject jo = JObject.Parse(responseTxt);

                //JToken fields = jo["fields"];

                //if (fields["APHP.ALM.TestCaseApplication"] != null)
                //{
                //    testCase.Application = fields["APHP.ALM.TestCaseApplication"].ToObject<string>();
                //}
                //testCase.ApplicationArea = fields["Microsoft.VSTS.CMMI.ApplicationArea"].ToObject<string>();
                //testCase.ApplicationProcess = fields["Microsoft.VSTS.CMMI.ApplicationProcess"].ToObject<string>();
                //if (fields["APHP.ALM.TestCaseApplicationSubArea"] != null)
                //{
                //    testCase.ApplicationSubArea = fields["APHP.ALM.TestCaseApplicationSubArea"].ToObject<string>();
                //}
                //testCase.TestCaseName = fields["System.Title"].ToObject<string>();
                //testCase.TestObjective = fields["Avanade.ACM.TestObjective"].ToObject<string>();
                //if (fields["System.Description"] != null)
                //{
                //    testCase.TestDescription = fields["System.Description"].ToObject<string>();
                //}
                //if (fields["Avanade.ACM.TestDataSetup"] != null)
                //{
                //    testCase.PreCondition = fields["Avanade.ACM.TestDataSetup"].ToObject<string>();
                //}
                ////testCase.Priority = Convert.ToInt32(fields["Avanade.ACM.Priority"].ToObject<string>().Substring(0,0));
                //testCase.Complexity = fields["Avanade.ACM.Complexity"].ToObject<string>();
                //testCase.ScenarioType = fields["Avanade.ACM.ScenarioType"].ToObject<string>();
                //testCase.TestCaseType = fields["APHP.ALM.TestCaseType"].ToObject<string>();

                testCase.Application        = jo["application"].ToString();
                testCase.ApplicationArea    = jo["applicationArea"].ToString();
                testCase.ApplicationProcess = jo["applicationProcess"].ToString();
                testCase.ApplicationSubArea = jo["applicationSubArea"].ToString();
                testCase.TestCaseName       = jo["testCaseName"].ToString();
                testCase.TestObjective      = jo["testObjective"].ToString();
                testCase.TestDescription    = jo["testDescription"].ToString();
                testCase.PreCondition       = jo["preCondition"].ToString();
                testCase.Priority           = Convert.ToInt32(jo["priority"]);
                testCase.Complexity         = jo["complexity"].ToString();
                testCase.ScenarioType       = jo["scenarioType"].ToString();
                testCase.TestCaseType       = jo["testCaseType"].ToString();
                testCase.TestSuiteId        = Convert.ToInt32(jo["testSuiteId"]);

                return(testCase);
            }
            else
            {
                Console.Write("Error getting Test Case: {0}", response.Content.ReadAsStringAsync().Result);
                throw new Exception();
            }

            //return testCase;
        }
Ejemplo n.º 23
0
        public async Task <TestCaseRowMapping> GetTestCaseIdFromName(TestCaseRowMapping currTestCaseRowMapping)
        {
            TestCaseRowMapping tempTestCaseRowMapping = new TestCaseRowMapping()
            {
                RowNumber    = currTestCaseRowMapping.RowNumber,
                TestCaseName = currTestCaseRowMapping.TestCaseName,
                TestSuiteId  = currTestCaseRowMapping.TestSuiteId
            };

            HttpClientInitiator client    = new HttpClientInitiator("https://localhost:44369/");
            HttpClient          newClient = client.CreateHttpClient();

            newClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var requestUri = "/api/TestCase/TestCaseName/" + tempTestCaseRowMapping.TestCaseName;
            var method     = new HttpMethod("GET");
            var request    = new HttpRequestMessage(method, requestUri)
            {
            };
            var response = await newClient.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                string responseString = await response.Content.ReadAsStringAsync();

                if (responseString != "")
                {
                    var jo = JObject.Parse(responseString);

                    tempTestCaseRowMapping.TestCaseId = Convert.ToInt32(jo["testCaseId"]);
                }
            }

            //Console.WriteLine(tempTestCaseRowMapping.TestCaseId);

            return(tempTestCaseRowMapping);

            //string stringQuery = "Select[System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Test Case' AND [System.Title] = '" + tempTestCaseRowMapping.TestCaseName + "'";

            //List<Object> patchDocument = new List<object>();
            //patchDocument.Add(new
            //{
            //    query = stringQuery
            //});

            //var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json");

            //var requestUri = "APHP/APHP%20Virginia/_api/_wit/search?searchText=" + tempTestCaseRowMapping.TestCaseName;
            //var method = new HttpMethod("GET");
            //var request = new HttpRequestMessage(method, requestUri) { };
            //var response = await _client.SendAsync(request);

            //List<int> listOfTestCasesInSuite = new List<int>();
            //listOfTestCasesInSuite = await GetTestCaseIdsInSuite(tempTestCaseRowMapping.TestSuiteId);

            //Console.WriteLine(listOfTestCasesInSuite);

            //if (response.IsSuccessStatusCode)
            //{
            //    string responseString = await response.Content.ReadAsStringAsync();
            //    var jo = JObject.Parse(responseString);

            //    int countTestCases = jo["payload"]["rows"].Count();

            //    Console.WriteLine(countTestCases);

            //    if (countTestCases > 0)
            //    {
            //        foreach (JToken currWorkItem in jo["payload"]["rows"])
            //        {
            //            if (listOfTestCasesInSuite.Contains(Convert.ToInt32(currWorkItem[0])))
            //            {
            //                tempTestCaseRowMapping.TestCaseId = Convert.ToInt32(currWorkItem[0]);
            //                return tempTestCaseRowMapping;
            //            }
            //        }
            //    }

            //    return null;
            //}
            //else
            //{
            //    throw new Exception();
            //}
        }