44
55namespace Coverlet . Core . Reporters . Tests
66{
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='50']" , output ) ;
94- Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='1']" , output ) ;
95- Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='2']" , 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='50']" , output ) ;
106- Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='1']" , output ) ;
107- Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='2']" , 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='100']" , output ) ;
118- Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='1']" , output ) ;
119- Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='1']" , output ) ;
120- }
121- }
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+ new BranchInfo
41+ {
42+ Line = 1 ,
43+ Hits = 0 ,
44+ Offset = 23 ,
45+ EndOffset = 27 ,
46+ Path = 1 ,
47+ Ordinal = 2
48+ }
49+ } ;
50+
51+ var methods = new Methods ( ) ;
52+ var methodString = "System.Void Coverlet.Core.Reporters.Tests.CoberturaReporterTests::TestReport()" ;
53+ methods . Add ( methodString , new Method ( ) ) ;
54+ methods [ methodString ] . Lines = lines ;
55+ methods [ methodString ] . Branches = branches ;
56+
57+ var classes = new Classes { { "Coverlet.Core.Reporters.Tests.CoberturaReporterTests" , methods } } ;
58+
59+ var documents = new Documents { { "doc.cs" , classes } } ;
60+
61+ _result . Modules = new Modules { { "module" , documents } } ;
62+ }
63+
64+ [ Fact ]
65+ public void OutputType_IsConsoleOutputType ( )
66+ {
67+ // Assert
68+ Assert . Equal ( ReporterOutputType . Console , _reporter . OutputType ) ;
69+ }
70+
71+ [ Fact ]
72+ public void Format_IsExpectedValue ( )
73+ {
74+ // Assert
75+ Assert . Equal ( "teamcity" , _reporter . Format ) ;
76+ }
77+
78+ [ Fact ]
79+ public void Format_IsNull ( )
80+ {
81+ // Assert
82+ Assert . Null ( _reporter . Extension ) ;
83+ }
84+
85+ [ Fact ]
86+ public void Report_ReturnsNonNullString ( )
87+ {
88+ // Act
89+ var output = _reporter . Report ( _result ) ;
90+
91+ // Assert
92+ Assert . False ( string . IsNullOrWhiteSpace ( output ) , "Output is not null or whitespace" ) ;
93+ }
94+
95+ [ Fact ]
96+ public void Report_ReportsLineCoverage ( )
97+ {
98+ // Act
99+ var output = _reporter . Report ( _result ) ;
100+
101+ // Assert
102+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageL' value='50']" , output ) ;
103+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='1']" , output ) ;
104+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='2']" , output ) ;
105+ }
106+
107+ [ Fact ]
108+ public void Report_ReportsBranchCoverage ( )
109+ {
110+ // Act
111+ var output = _reporter . Report ( _result ) ;
112+
113+ // Assert
114+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageR' value='33.3']" , output ) ;
115+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsRCovered' value='1']" , output ) ;
116+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsRTotal' value='3']" , output ) ;
117+ }
118+
119+ [ Fact ]
120+ public void Report_ReportsMethodCoverage ( )
121+ {
122+ // Act
123+ var output = _reporter . Report ( _result ) ;
124+
125+ // Assert
126+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageM' value='100']" , output ) ;
127+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='1']" , output ) ;
128+ Assert . Contains ( "##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='1']" , output ) ;
129+ }
130+ }
122131}
0 commit comments