-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
120 additions
and
59 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- The namespace for the TrxParser has changed | ||
- The TrxParser now parses the ResultSummary tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
using ModularPipelines.DotNet.Enums; | ||
using ModularPipelines.DotNet.Parsers.NUnitTrx; | ||
using ModularPipelines.DotNet.Parsers.Trx; | ||
|
||
namespace ModularPipelines.DotNet; | ||
|
||
public record DotNetTestResult(IReadOnlyList<UnitTestResult> UnitTestResults) | ||
public record DotNetTestResult(IReadOnlyList<UnitTestResult> UnitTestResults, ResultSummary ResultSummary) | ||
{ | ||
public bool Successful => UnitTestResults.All(x => x.Outcome != TestOutcome.Failed); | ||
public bool Successful => ResultSummary.Outcome is "Passed" or "Completed"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace ModularPipelines.DotNet.Parsers.Trx; | ||
|
||
public record Counters( | ||
int Total, | ||
int Executed, | ||
int Passed, | ||
int Failed, | ||
int Error, | ||
int Timeout, | ||
int Aborted, | ||
int Inconclusive, | ||
int PassedButRunAborted, | ||
int NotRunnable, | ||
int NotExecuted, | ||
int Disconnected, | ||
int Warning, | ||
int Completed, | ||
int InProgress, | ||
int Pending); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace ModularPipelines.DotNet.Parsers.Trx; | ||
|
||
public record ResultSummary(string Outcome, Counters Counters); |
2 changes: 1 addition & 1 deletion
2
...nes.DotNet/Parsers/NUnitTrx/TestOutput.cs → ...ipelines.DotNet/Parsers/Trx/TestOutput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.Xml.Linq; | ||
using ModularPipelines.DotNet.Enums; | ||
|
||
namespace ModularPipelines.DotNet.Parsers.Trx; | ||
|
||
public class TrxParser : ITrxParser | ||
{ | ||
public DotNetTestResult ParseTrxContents(string input) | ||
{ | ||
var xDocument = XDocument.Load(new StringReader(input)); | ||
return new DotNetTestResult(GetUnitTestResults(xDocument), GetResultSummary(xDocument)); | ||
} | ||
|
||
private ResultSummary GetResultSummary(XDocument document) | ||
{ | ||
return ParseResultSummary(document | ||
.Descendants() | ||
.First(e => e.Name.LocalName == "ResultSummary")); | ||
} | ||
|
||
private ResultSummary ParseResultSummary(XElement element) | ||
{ | ||
var outcome = element.Attribute("outcome")!.Value; | ||
|
||
var counters = ParseCounters(element.Descendants().First(e => e.Name.LocalName == "Counters")); | ||
|
||
return new ResultSummary(outcome, counters); | ||
} | ||
|
||
private Counters ParseCounters(XElement element) | ||
{ | ||
return new Counters( | ||
int.Parse(element.Attribute("total")!.Value), | ||
int.Parse(element.Attribute("executed")!.Value), | ||
int.Parse(element.Attribute("passed")!.Value), | ||
int.Parse(element.Attribute("failed")!.Value), | ||
int.Parse(element.Attribute("error")!.Value), | ||
int.Parse(element.Attribute("timeout")!.Value), | ||
int.Parse(element.Attribute("aborted")!.Value), | ||
int.Parse(element.Attribute("inconclusive")!.Value), | ||
int.Parse(element.Attribute("passedButRunAborted")!.Value), | ||
int.Parse(element.Attribute("notRunnable")!.Value), | ||
int.Parse(element.Attribute("notExecuted")!.Value), | ||
int.Parse(element.Attribute("disconnected")!.Value), | ||
int.Parse(element.Attribute("warning")!.Value), | ||
int.Parse(element.Attribute("completed")!.Value), | ||
int.Parse(element.Attribute("inProgress")!.Value), | ||
int.Parse(element.Attribute("pending")!.Value) | ||
); | ||
} | ||
|
||
private List<UnitTestResult> GetUnitTestResults(XDocument xDocument) | ||
{ | ||
return xDocument.Descendants() | ||
.Where(d => d.Name.LocalName == "UnitTestResult") | ||
.Select(ParseUnitTestResult) | ||
.ToList(); | ||
} | ||
|
||
private UnitTestResult ParseUnitTestResult(XElement element) | ||
{ | ||
var errorInfo = element.Descendants().FirstOrDefault(x => x.Name.LocalName == "ErrorInfo"); | ||
|
||
return new UnitTestResult | ||
{ | ||
ExecutionId = element.Attribute("executionId")!.Value, | ||
TestId = element.Attribute("testId")!.Value, | ||
TestName = element.Attribute("testName")!.Value, | ||
ComputerName = element.Attribute("computerName")!.Value, | ||
Duration = TimeSpan.Parse(element.Attribute("duration")!.Value), | ||
StartTime = DateTimeOffset.Parse(element.Attribute("startTime")!.Value), | ||
EndTime = DateTimeOffset.Parse(element.Attribute("endTime")!.Value), | ||
TestType = element.Attribute("testType")!.Value, | ||
Outcome = Enum.Parse<TestOutcome>(element.Attribute("outcome")!.Value), | ||
TestListId = element.Attribute("testListId")!.Value, | ||
RelativeResultsDirectory = element.Attribute("relativeResultsDirectory")!.Value, | ||
Output = new TestOutput | ||
{ | ||
StdOut = element.Descendants().FirstOrDefault(x => x.Name.LocalName == "StdOut")?.Value, | ||
ErrorInfo = errorInfo == null ? null : new ErrorInfo | ||
{ | ||
Message = errorInfo.Descendants().FirstOrDefault(x => x.Name.LocalName == "Message")?.Value, | ||
StackTrace = errorInfo.Descendants().FirstOrDefault(x => x.Name.LocalName == "StackTrace")?.Value, | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/ModularPipelines.UnitTests/Helpers/DotNetTestResultsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters