private async Task SendTestsCompleted(CancellationToken cancellationToken)
        {
            string completedDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ");

            // Mark all parents as completed (but only if we actually created a parent)
            if (TestRunEndpoint != null)
            {
                string parentRequest = "[ " + string.Join(", ", Parents.Values.Select(x =>
                                                                                      $@"{{
                    ""id"": {x.Id},
                    ""state"": ""Completed"",
                    ""startedDate"": ""{x.StartedDate.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ")}"",
                    ""completedDate"": ""{completedDate}""
                }}")) + " ]";
                await _apiClient.SendAsync(new HttpMethod("PATCH"), TestRunEndpoint, "5.0", parentRequest, cancellationToken).ConfigureAwait(false);

                // Mark the overall test run as completed
                string testRunRequest = $@"{{
                        ""state"": ""Completed"",
                        ""startedDate"": ""{StartedDate.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ")}"",
                        ""completedDate"": ""{completedDate}""
                    }}";
                await _apiClient.SendAsync(new HttpMethod("PATCH"), $"/{RunId}", "5.0", testRunRequest, cancellationToken).ConfigureAwait(false);
            }
        }
        // Internal for testing
        internal async Task <int> CreateTestRun(CancellationToken cancellationToken)
        {
            string runName = $"{(string.IsNullOrEmpty(Source) ? "Unknown Test Source" : Source)} (OS: {System.Runtime.InteropServices.RuntimeInformation.OSDescription}, Job: {_jobName}, Agent: {_agentName})";
            Dictionary <string, object> request = new Dictionary <string, object>
            {
                { "name", runName },
                { "build", new Dictionary <string, object> {
                      { "id", _buildId }
                  } },
                { "startedDate", StartedDate.ToString("yyyy-MM-ddTHH:mm:ss.FFFZ") },
                { "isAutomated", true }
            };
            string responseString = await _apiClient.SendAsync(HttpMethod.Post, null, "5.0", request.ToJson(), cancellationToken).ConfigureAwait(false);

            using (StringReader reader = new StringReader(responseString))
            {
                JsonObject response = JsonDeserializer.Deserialize(reader) as JsonObject;
                return(response.ValueAsInt("id"));
            }
        }
Exemplo n.º 3
0
        public void ReadsResultsReturnsCorrectValues()
        {
            SetupMocks();
            String trxContents = "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" +
                                 "<TestRun id = \"ee3d8b3b-1ac9-4a7e-abfa-3d3ed2008613\" name = \"kaadhina@KAADHINA1 2015-03-20 16:53:32\" runUser = \"FAREAST\\kaadhina\" xmlns =\"http://microsoft.com/schemas/VisualStudio/TeamTest/2010\"><Times creation = \"2015-03-20T16:53:32.3309380+05:30\" queuing = \"2015-03-20T16:53:32.3319381+05:30\" start = \"2015-03-20T16:53:32.3349628+05:30\" finish = \"2015-03-20T16:53:32.9232329+05:30\" />" +

                                 "<TestDefinitions>" +
                                 "<UnitTest name = \"TestMethod2\" storage = \"c:/users/kaadhina/source/repos/projectx/unittestproject4/unittestproject4/bin/debug/unittestproject4.dll\" priority = \"1\" id = \"f0d6b58f-dc08-9c0b-aab7-0a1411d4a346\"><Owners><Owner name = \"asdf2\" /></Owners><Execution id = \"48ec1e47-b9df-43b9-aef2-a2cc8742353d\" /><TestMethod codeBase = \"c:/users/kaadhina/source/repos/projectx/unittestproject4/unittestproject4/bin/debug/unittestproject4.dll\" adapterTypeName = \"Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter\" className = \"UnitTestProject4.UnitTest1\" name = \"TestMethod2\" /></UnitTest>" +
                                 "<WebTest name=\"PSD_Startseite\" storage=\"c:\\vsoagent\\a284d2cc\\vseqa1\\psd_startseite.webtest\" id=\"01da1a13-b160-4ee6-9d84-7a6dfe37b1d2\" persistedWebTest=\"7\"><TestCategory><TestCategoryItem TestCategory=\"PSD\" /></TestCategory><Execution id=\"eb421c16-4546-435a-9c24-0d2878ea76d4\" /></WebTest>" +
                                 "</TestDefinitions>" +

                                 "<TestSettings name=\"TestSettings1\" id=\"e9d264e9-30da-48df-aa95-c6b53f699464\"><Description>These are default test settings for a local test run.</Description>" +
                                 "<Execution>" +
                                 "<AgentRule name=\"LocalMachineDefaultRole\">" +
                                 "<DataCollectors>" +
                                 "<DataCollector uri=\"datacollector://microsoft/CodeCoverage/1.0\" assemblyQualifiedName=\"Microsoft.VisualStudio.TestTools.CodeCoverage.CoveragePlugIn, Microsoft.VisualStudio.QualityTools.Plugins.CodeCoverage, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\" friendlyName=\"Code Coverage (Visual Studio 2010)\">" +
                                 "<Configuration><CodeCoverage xmlns=\"\"><Regular>" +
                                 "<CodeCoverageItem binaryFile=\"C:\\mstest.static.UnitTestProject3.dll\" pdbFile=\"C:\\mstest.static.UnitTestProject3.instr.pdb\" instrumentInPlace=\"true\" />" +
                                 "</Regular></CodeCoverage></Configuration>" +
                                 "</DataCollector>" +
                                 "</DataCollectors>" +
                                 "</AgentRule>" +
                                 "</Execution>" +
                                 "</TestSettings>" +

                                 "<Results>" +
                                 "<UnitTestResult executionId = \"48ec1e47-b9df-43b9-aef2-a2cc8742353d\" testId = \"f0d6b58f-dc08-9c0b-aab7-0a1411d4a346\" testName = \"TestMethod2\" computerName = \"KAADHINA1\" duration = \"00:00:00.0834563\" startTime = \"2015-03-20T16:53:32.3099353+05:30\" endTime = \"2015-03-20T16:53:32.3939623+05:30\" testType = \"13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b\" outcome = \"Failed\" testListId = \"8c84fa94-04c1-424b-9868-57a2d4851a1d\" relativeResultsDirectory = \"48ec1e47-b9df-43b9-aef2-a2cc8742353d\" ><Output><StdOut>Show console log output.</StdOut><ErrorInfo><Message>Assert.Fail failed.</Message><StackTrace>at UnitTestProject4.UnitTest1.TestMethod2() in C:\\Users\\kaadhina\\Source\\Repos\\Projectx\\UnitTestProject4\\UnitTestProject4\\UnitTest1.cs:line 21</StackTrace></ErrorInfo></Output>" +
                                 "<ResultFiles><ResultFile path=\"DIGANR-DEV4\\x.txt\" /></ResultFiles>" +
                                 "</UnitTestResult>" +

                                 "<WebTestResult executionId=\"eb421c16-4546-435a-9c24-0d2878ea76d4\" testId=\"01da1a13-b160-4ee6-9d84-7a6dfe37b1d2\" testName=\"PSD_Startseite\" computerName=\"LAB-BUILDVNEXT\" duration=\"00:00:01.6887389\" startTime=\"2015-05-20T18:53:51.1063165+00:00\" endTime=\"2015-05-20T18:54:03.9160742+00:00\" testType=\"4e7599fa-5ecb-43e9-a887-cd63cf72d207\" outcome=\"Passed\" testListId=\"8c84fa94-04c1-424b-9868-57a2d4851a1d\" relativeResultsDirectory=\"eb421c16-4546-435a-9c24-0d2878ea76d4\"><Output><StdOut>Do not show console log output.</StdOut></Output>" +
                                 "<ResultFiles>" +
                                 "<ResultFile path=\"PSD_Startseite.webtestResult\" />" +
                                 "</ResultFiles>" +
                                 "<WebTestResultFilePath>LOCAL SERVICE_LAB-BUILDVNEXT 2015-05-20 18_53_41\\In\\eb421c16-4546-435a-9c24-0d2878ea76d4\\PSD_Startseite.webtestResult</WebTestResultFilePath>" +
                                 "</WebTestResult>" +
                                 "</Results>" +

                                 "<ResultSummary outcome=\"Failed\"><Counters total = \"2\" executed = \"2\" passed=\"1\" failed=\"1\" error=\"0\" timeout=\"0\" aborted=\"0\" inconclusive=\"0\" passedButRunAborted=\"0\" notRunnable=\"0\" notExecuted=\"0\" disconnected=\"0\" warning=\"0\" completed=\"0\" inProgress=\"0\" pending=\"0\" />" +

                                 "<CollectorDataEntries>" +
                                 "<Collector agentName=\"DIGANR-DEV4\" uri=\"datacollector://microsoft/CodeCoverage/2.0\" collectorDisplayName=\"Code Coverage\"><UriAttachments><UriAttachment>" +
                                 "<A href=\"DIGANR-DEV4\\vstest_console.dynamic.data.coverage\"></A></UriAttachment></UriAttachments>" +
                                 "</Collector>" +
                                 "<Collector agentName=\"DIGANR-DEV4\" uri=\"datacollector://microsoft/CodeCoverage/1.0\" collectorDisplayName=\"MSTestAdapter\"><UriAttachments>" +
                                 "<UriAttachment><A href=\"DIGANR-DEV4\\unittestproject3.dll\">c:\\vstest.static.unittestproject3.dll</A></UriAttachment>" +
                                 "<UriAttachment><A href=\"DIGANR-DEV4\\UnitTestProject3.instr.pdb\">C:\\vstest.static.UnitTestProject3.instr.pdb</A></UriAttachment>" +
                                 "</UriAttachments></Collector>" +
                                 "</CollectorDataEntries>" +

                                 "<ResultFiles>" +
                                 "<ResultFile path=\"vstest_console.static.data.coverage\" /></ResultFiles>" +
                                 "<ResultFile path=\"DIGANR-DEV4\\mstest.static.data.coverage\" />" +
                                 "</ResultSummary>" +

                                 "</TestRun>";

            var runData = GetTestRunData(trxContents, null, new TestRunContext("Owner", "any cpu", "debug", 1, "", "releaseUri", "releaseEnvironmentUri"));

            DateTime StartedDate;

            DateTime.TryParse("2015-03-20T16:53:32.3099353+05:30", out StartedDate);
            Assert.Equal(runData.Results[0].StartedDate, StartedDate.ToString("o"));

            TimeSpan Duration;

            TimeSpan.TryParse("00:00:00.0834563", out Duration);
            Assert.Equal(runData.Results[0].DurationInMs, ((int)Duration.TotalMilliseconds).ToString());

            DateTime CompletedDate = StartedDate.AddTicks(Duration.Ticks);

            Assert.Equal(runData.Results[0].CompletedDate, CompletedDate.ToString("o"));

            Assert.Equal(runData.Name, "VSTest Test Run debug any cpu");
            Assert.Equal(runData.State, "InProgress");
            Assert.Equal(runData.Results.Length, 2);

            Assert.Equal(runData.Results[0].Outcome, "Failed");
            Assert.Equal(runData.Results[0].TestCaseTitle, "TestMethod2");
            Assert.Equal(runData.Results[0].ComputerName, "KAADHINA1");
            Assert.Equal(runData.Results[0].AutomatedTestType, "UnitTest");
            Assert.Equal(runData.Results[0].AutomatedTestName, "UnitTestProject4.UnitTest1.TestMethod2");
            Assert.Equal(runData.Results[0].AutomatedTestId, "f0d6b58f-dc08-9c0b-aab7-0a1411d4a346");
            Assert.Equal(runData.Results[0].AutomatedTestStorage, "unittestproject4.dll");
            Assert.Equal(runData.Results[0].AutomatedTestTypeId, "13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b");
            Assert.Equal(runData.Results[0].ErrorMessage, "Assert.Fail failed.");
            Assert.Equal(runData.Results[0].StackTrace, "at UnitTestProject4.UnitTest1.TestMethod2() in C:\\Users\\kaadhina\\Source\\Repos\\Projectx\\UnitTestProject4\\UnitTestProject4\\UnitTest1.cs:line 21");
            Assert.Equal(runData.Results[0].TestCasePriority, "1");
            Assert.Equal(runData.Results[0].ConsoleLog, "Show console log output.");
            Assert.Equal(runData.Results[0].Attachments.Length, 1);
            Assert.True(runData.Results[0].Attachments[0].Contains("x.txt"));

            Assert.Equal(runData.Results[1].Outcome, "Passed");
            Assert.Equal(runData.Results[1].TestCaseTitle, "PSD_Startseite");
            Assert.Equal(runData.Results[1].ComputerName, "LAB-BUILDVNEXT");
            Assert.Equal(runData.Results[1].AutomatedTestType, "WebTest");
            Assert.Equal(runData.Results[1].ConsoleLog, null);
            Assert.Equal(runData.Results[1].Attachments.Length, 1);
            Assert.True(runData.Results[1].Attachments[0].Contains("PSD_Startseite.webtestResult"));

            Assert.Equal(runData.BuildFlavor, "debug");
            Assert.Equal(runData.BuildPlatform, "any cpu");
            // 3 files related mstest.static, 3 files related to vstest.static, and 1 file for vstest.dynamic
            Assert.Equal(runData.Attachments.Length, 7);

            int buildId;

            int.TryParse(runData.Build.Id, out buildId);
            Assert.Equal(buildId, 1);

            Assert.Equal(runData.ReleaseUri, "releaseUri");
            Assert.Equal(runData.ReleaseEnvironmentUri, "releaseEnvironmentUri");
        }