44using Microsoft . Build . BackEnd ;
55using Microsoft . Build . BackEnd . Logging ;
66using Microsoft . Build . Shared ;
7+ using Shouldly ;
78using System ;
89using Xunit ;
10+ using Xunit . Abstractions ;
911
1012namespace Microsoft . Build . UnitTests . BackEnd
1113{
@@ -14,29 +16,36 @@ namespace Microsoft.Build.UnitTests.BackEnd
1416 /// </summary>
1517 public class LoggingContext_Tests
1618 {
19+ private readonly ITestOutputHelper _output ;
20+
21+ public LoggingContext_Tests ( ITestOutputHelper outputHelper )
22+ {
23+ _output = outputHelper ;
24+ }
25+
1726 /// <summary>
1827 /// A few simple tests for NodeLoggingContexts.
1928 /// </summary>
2029 [ Fact ]
2130 public void CreateValidNodeLoggingContexts ( )
2231 {
23- NodeLoggingContext context = new NodeLoggingContext ( new MockLoggingService ( ) , 1 , true ) ;
24- Assert . True ( context . IsInProcNode ) ;
25- Assert . True ( context . IsValid ) ;
32+ NodeLoggingContext context = new NodeLoggingContext ( new MockLoggingService ( _output . WriteLine ) , 1 , true ) ;
33+ context . IsInProcNode . ShouldBeTrue ( ) ;
34+ context . IsValid . ShouldBeTrue ( ) ;
2635
2736 context . LogBuildFinished ( true ) ;
28- Assert . False ( context . IsValid ) ;
37+ context . IsValid . ShouldBeFalse ( ) ;
2938
30- Assert . Equal ( 1 , context . BuildEventContext . NodeId ) ;
39+ context . BuildEventContext . NodeId . ShouldBe ( 1 ) ;
3140
32- NodeLoggingContext context2 = new NodeLoggingContext ( new MockLoggingService ( ) , 2 , false ) ;
33- Assert . False ( context2 . IsInProcNode ) ;
34- Assert . True ( context2 . IsValid ) ;
41+ NodeLoggingContext context2 = new NodeLoggingContext ( new MockLoggingService ( _output . WriteLine ) , 2 , false ) ;
42+ context2 . IsInProcNode . ShouldBeFalse ( ) ;
43+ context2 . IsValid . ShouldBeTrue ( ) ;
3544
3645 context2 . LogBuildFinished ( true ) ;
37- Assert . False ( context2 . IsValid ) ;
46+ context2 . IsValid . ShouldBeFalse ( ) ;
3847
39- Assert . Equal ( 2 , context2 . BuildEventContext . NodeId ) ;
48+ context2 . BuildEventContext . NodeId . ShouldBe ( 2 ) ;
4049 }
4150
4251 /// <summary>
@@ -49,9 +58,25 @@ public void InvalidNodeIdOnNodeLoggingContext()
4958 {
5059 Assert . Throws < InternalErrorException > ( ( ) =>
5160 {
52- NodeLoggingContext context = new NodeLoggingContext ( new MockLoggingService ( ) , - 2 , true ) ;
61+ _ = new NodeLoggingContext ( new MockLoggingService ( ) , - 2 , true ) ;
5362 }
5463 ) ;
5564 }
65+
66+ [ Fact ]
67+ public void HasLoggedErrors ( )
68+ {
69+ NodeLoggingContext context = new NodeLoggingContext ( new MockLoggingService ( _output . WriteLine ) , 1 , true ) ;
70+ context . HasLoggedErrors . ShouldBeFalse ( ) ;
71+
72+ context . LogCommentFromText ( Framework . MessageImportance . High , "Test message" ) ;
73+ context . HasLoggedErrors . ShouldBeFalse ( ) ;
74+
75+ context . LogWarningFromText ( null , null , null , null , "Test warning" ) ;
76+ context . HasLoggedErrors . ShouldBeFalse ( ) ;
77+
78+ context . LogErrorFromText ( null , null , null , null , "Test error" ) ;
79+ context . HasLoggedErrors . ShouldBeTrue ( ) ;
80+ }
5681 }
57- }
82+ }
0 commit comments