@@ -215,15 +215,25 @@ private static BuildDetails GetBuildDetails(int buildId)
215
215
string buildJsonString = RequestHelper . GetJson ( url ) ;
216
216
dynamic buildJson = JsonConvert . DeserializeObject < dynamic > ( buildJsonString ) ;
217
217
218
- dynamic testResults = buildJson . testOccurrences ;
218
+ BuildDetails result = new BuildDetails
219
+ {
220
+ Number = ( string ) buildJson . number
221
+ } ;
219
222
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
+ }
227
237
228
238
if ( buildJson . finishDate != null )
229
239
{
@@ -275,5 +285,32 @@ private static BuildStatistics GetBuildStatistics(int buildId)
275
285
276
286
return result ;
277
287
}
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
+ }
278
315
}
279
316
}
0 commit comments