@@ -102,6 +102,53 @@ public void AttackLog_ShouldLogMessageAsInformation()
102102 It . IsAny < Func < It . IsAnyType , Exception ? , string > > ( ) ) , Times . Once ) ;
103103 }
104104
105+ [ Test ]
106+ public void WarningLog_ShouldLogMessageAsWarning ( )
107+ {
108+ var message = "Test warning message" ;
109+
110+ LogHelper . WarningLog ( _loggerMock . Object , message ) ;
111+
112+ _loggerMock . Verify ( logger => logger . Log (
113+ It . Is < LogLevel > ( level => level == LogLevel . Warning ) ,
114+ It . IsAny < EventId > ( ) ,
115+ It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) . EndsWith ( message ) ) ,
116+ It . IsAny < Exception ? > ( ) ,
117+ It . IsAny < Func < It . IsAnyType , Exception ? , string > > ( ) ) , Times . Once ) ;
118+ }
119+
120+ [ Test ]
121+ public void WarningLog_ShouldSanitizeMessage_WhenMessageContainsDangerousCharacters ( )
122+ {
123+ var message = "Warning\n message\r with\t details" ;
124+ var expectedSanitizedContent = "Warningmessagewithdetails" ;
125+
126+ LogHelper . WarningLog ( _loggerMock . Object , message ) ;
127+
128+ _loggerMock . Verify ( logger => logger . Log (
129+ It . Is < LogLevel > ( level => level == LogLevel . Warning ) ,
130+ It . IsAny < EventId > ( ) ,
131+ It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) . Contains ( expectedSanitizedContent ) ) ,
132+ It . IsAny < Exception ? > ( ) ,
133+ It . IsAny < Func < It . IsAnyType , Exception ? , string > > ( ) ) , Times . Once ) ;
134+ }
135+
136+ [ Test ]
137+ public void WarningLog_WithException_ShouldLogExceptionAsWarning ( )
138+ {
139+ var message = "Test warning with exception" ;
140+ var exception = new InvalidOperationException ( "test exception" ) ;
141+
142+ LogHelper . WarningLog ( _loggerMock . Object , exception , message ) ;
143+
144+ _loggerMock . Verify ( logger => logger . Log (
145+ It . Is < LogLevel > ( level => level == LogLevel . Warning ) ,
146+ It . IsAny < EventId > ( ) ,
147+ It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) ! . EndsWith ( message ) ) ,
148+ exception ,
149+ It . IsAny < Func < It . IsAnyType , Exception ? , string > > ( ) ) , Times . Once ) ;
150+ }
151+
105152 [ Test ]
106153 public void AttackLog_ShouldSanitizeMessage_WhenMessageContainsDangerousCharacters ( )
107154 {
0 commit comments