1
+ using coverlet . core . Reporters ;
2
+ using System ;
3
+ using Xunit ;
4
+
5
+ namespace Coverlet . Core . Reporters . Tests
6
+ {
7
+ public class TestCreateReporterTests
8
+ {
9
+ private readonly CoverageResult _result ;
10
+ private readonly TeamCityReporter _reporter ;
11
+
12
+ public TestCreateReporterTests ( )
13
+ {
14
+ _reporter = new TeamCityReporter ( ) ;
15
+ _result = new CoverageResult ( ) ;
16
+ _result . Identifier = Guid . NewGuid ( ) . ToString ( ) ;
17
+
18
+ var lines = new Lines { { 1 , 1 } , { 2 , 0 } } ;
19
+
20
+ var branches = new Branches
21
+ {
22
+ new BranchInfo
23
+ {
24
+ Line = 1 ,
25
+ Hits = 1 ,
26
+ Offset = 23 ,
27
+ EndOffset = 24 ,
28
+ Path = 0 ,
29
+ Ordinal = 1
30
+ } ,
31
+ new BranchInfo
32
+ {
33
+ Line = 1 ,
34
+ Hits = 0 ,
35
+ Offset = 23 ,
36
+ EndOffset = 27 ,
37
+ Path = 1 ,
38
+ Ordinal = 2
39
+ }
40
+ } ;
41
+
42
+ var methods = new Methods ( ) ;
43
+ var methodString = "System.Void Coverlet.Core.Reporters.Tests.CoberturaReporterTests::TestReport()" ;
44
+ methods . Add ( methodString , new Method ( ) ) ;
45
+ methods [ methodString ] . Lines = lines ;
46
+ methods [ methodString ] . Branches = branches ;
47
+
48
+ var classes = new Classes { { "Coverlet.Core.Reporters.Tests.CoberturaReporterTests" , methods } } ;
49
+
50
+ var documents = new Documents { { "doc.cs" , classes } } ;
51
+
52
+ _result . Modules = new Modules { { "module" , documents } } ;
53
+ }
54
+
55
+ [ Fact ]
56
+ public void OutputType_IsConsoleOutputType ( )
57
+ {
58
+ // Assert
59
+ Assert . Equal ( ReporterOutputType . Console , _reporter . OutputType ) ;
60
+ }
61
+
62
+ [ Fact ]
63
+ public void Format_IsExpectedValue ( )
64
+ {
65
+ // Assert
66
+ Assert . Equal ( "teamcity" , _reporter . Format ) ;
67
+ }
68
+
69
+ [ Fact ]
70
+ public void Format_IsNull ( )
71
+ {
72
+ // Assert
73
+ Assert . Null ( _reporter . Extension ) ;
74
+ }
75
+
76
+ [ Fact ]
77
+ public void Report_ReturnsNonNullString ( )
78
+ {
79
+ // Act
80
+ var output = _reporter . Report ( _result ) ;
81
+
82
+ // Assert
83
+ Assert . False ( string . IsNullOrWhiteSpace ( output ) , "Output is not null or whitespace" ) ;
84
+ }
85
+
86
+ [ Fact ]
87
+ public void Report_ReportsLineCoverage ( )
88
+ {
89
+ // Act
90
+ var output = _reporter . Report ( _result ) ;
91
+
92
+ // Assert
93
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageL' value='2']" , output ) ;
94
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='1']" , output ) ;
95
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='50']" , output ) ;
96
+ }
97
+
98
+ [ Fact ]
99
+ public void Report_ReportsBranchCoverage ( )
100
+ {
101
+ // Act
102
+ var output = _reporter . Report ( _result ) ;
103
+
104
+ // Assert
105
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageR' value='2']" , output ) ;
106
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='1']" , output ) ;
107
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='50']" , output ) ;
108
+ }
109
+
110
+ [ Fact ]
111
+ public void Report_ReportsMethodCoverage ( )
112
+ {
113
+ // Act
114
+ var output = _reporter . Report ( _result ) ;
115
+
116
+ // Assert
117
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageM' value='1']" , output ) ;
118
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='1']" , output ) ;
119
+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='100']" , output ) ;
120
+ }
121
+ }
122
+ }
0 commit comments