Skip to content

Commit babb3a4

Browse files
committed
ADDED: Reading test counts from build statistics if not found in testOccurences.
1 parent da5156d commit babb3a4

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

Diff for: BuildMonitor/Helpers/TestsHelper.cs

+45-8
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,25 @@ private static BuildDetails GetBuildDetails(int buildId)
215215
string buildJsonString = RequestHelper.GetJson(url);
216216
dynamic buildJson = JsonConvert.DeserializeObject<dynamic>(buildJsonString);
217217

218-
dynamic testResults = buildJson.testOccurrences;
218+
BuildDetails result = new BuildDetails
219+
{
220+
Number = (string) buildJson.number
221+
};
219222

220-
BuildDetails result = new BuildDetails
221-
{
222-
Number = (string)buildJson.number,
223-
PassedCount = testResults != null && testResults.passed != null ? (int)testResults.passed : 0,
224-
FailedCount = testResults != null && testResults.failed != null ? (int)testResults.failed : 0,
225-
IgnoredCount = testResults != null && testResults.ignored != null ? (int)testResults.ignored : 0
226-
};
223+
dynamic testResults = buildJson.testOccurrences;
224+
if (testResults != null)
225+
{
226+
result.PassedCount = testResults.passed != null ? (int) testResults.passed : 0;
227+
result.FailedCount = testResults.failed != null ? (int) testResults.failed : 0;
228+
result.IgnoredCount = testResults.ignored != null ? (int) testResults.ignored : 0;
229+
}
230+
else
231+
{
232+
TestRunResult testResult = TestsHelper.GetTestResultsFromBuildStatistics(buildId);
233+
result.PassedCount = testResult.PassedCount;
234+
result.FailedCount = testResult.FailedCount;
235+
result.IgnoredCount = testResult.IgnoredCount;
236+
}
227237

228238
if (buildJson.finishDate != null)
229239
{
@@ -275,5 +285,32 @@ private static BuildStatistics GetBuildStatistics(int buildId)
275285

276286
return result;
277287
}
288+
289+
private static TestRunResult GetTestResultsFromBuildStatistics(int buildId)
290+
{
291+
string url = String.Format(CultureInfo.InvariantCulture, TestsHelper.BuildStatisticsUrl, buildId);
292+
string buildStatisticsJsonString = RequestHelper.GetJson(url);
293+
dynamic buildStatisticsJson = JsonConvert.DeserializeObject<dynamic>(buildStatisticsJsonString);
294+
295+
TestRunResult result = new TestRunResult();
296+
297+
foreach (dynamic property in buildStatisticsJson.property)
298+
{
299+
switch ((string) property.name)
300+
{
301+
case "PassedTestCount":
302+
result.PassedCount = (int) property.value;
303+
break;
304+
case "FailedTestCount":
305+
result.FailedCount = (int) property.value;
306+
break;
307+
case "IgnoredTestCount":
308+
result.IgnoredCount = (int) property.value;
309+
break;
310+
}
311+
}
312+
313+
return result;
314+
}
278315
}
279316
}

0 commit comments

Comments
 (0)