예제 #1
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.");
            }
        }
예제 #2
0
        public void GatherTestRunAndResultsAndWriteToDb()
        {
            GatherTestRun  gatherTestRun = new GatherTestRun(_props);
            List <TestRun> testRuns      = gatherTestRun.GatherTestRunWithTestResult();

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

            if (_props.UseWebApi == 1)
            {
                Console.Write("Writing Test Runs to DB... ");
                PostHelper <TestRun>(testRuns, "/api/TestRun");
                Console.WriteLine();
                Console.WriteLine("Finished writing Test Runs to DB...");
            }
            else
            {
                Console.WriteLine("Not using WebAPI. Not writing to DB... ");
            }
        }