1919
2020
2121using System ;
22- using System . Diagnostics ;
23-
2422using log4net . Appender ;
2523using log4net . Config ;
2624using log4net . Core ;
@@ -33,22 +31,21 @@ namespace log4net.Tests.Appender;
3331/// <summary>
3432/// Used for internal unit testing the <see cref="OutputDebugStringAppender"/> class.
3533/// </summary>
36- /// <remarks>
37- /// Used for internal unit testing the <see cref="OutputDebugStringAppender"/> class.
38- /// </remarks>
3934[ TestFixture ]
4035[ Platform ( Include = "Win" ) ]
4136public sealed class OutputDebugStringAppenderTest
4237{
38+ private const string DebugMessage = "Message - Сообщение - הודעה" ;
39+
4340 /// <summary>
4441 /// Verifies that the OutputDebugString api is called by the appender without issues
4542 /// </summary>
4643 [ Test ]
4744 public void AppendShouldNotCauseAnyErrors ( )
4845 {
4946 ILoggerRepository rep = LogManager . CreateRepository ( Guid . NewGuid ( ) . ToString ( ) ) ;
50-
51- OutputDebugStringAppender outputDebugStringAppender = new ( )
47+ string ? lastDebugString = null ;
48+ OutputAppender outputDebugStringAppender = new ( value => lastDebugString = value )
5249 {
5350 Layout = new SimpleLayout ( ) ,
5451 ErrorHandler = new FailOnError ( )
@@ -58,15 +55,18 @@ public void AppendShouldNotCauseAnyErrors()
5855 BasicConfigurator . Configure ( rep , outputDebugStringAppender ) ;
5956
6057 ILog log = LogManager . GetLogger ( rep . Name , GetType ( ) ) ;
61- log . Debug ( "Message - Сообщение - הודעה" ) ;
62-
63- // need a way to check that the api is actually called and the string is properly marshalled.
58+ log . Debug ( DebugMessage ) ;
59+ Assert . That ( lastDebugString , Is . Not . Null . And . Contains ( DebugMessage ) ) ;
6460 }
6561}
6662
67- class FailOnError : IErrorHandler
63+ file sealed class OutputAppender ( Action < string > outputDebugString )
64+ : OutputDebugStringAppender ( outputDebugString )
65+ { }
66+
67+ file sealed class FailOnError : IErrorHandler
6868{
6969 public void Error ( string message , Exception ? e , ErrorCode errorCode ) => Assert . Fail ( $ "Unexpected error: { message } exception: { e } , errorCode: { errorCode } ") ;
7070 public void Error ( string message , Exception e ) => Assert . Fail ( $ "Unexpected error: { message } exception: { e } ") ;
71- public void Error ( string message ) => Assert . Fail ( $ "Unexpected error: { message } ") ;
72- }
71+ public void Error ( string message ) => Assert . Fail ( $ "Unexpected error: { message } ") ;
72+ }
0 commit comments