@@ -125,8 +125,20 @@ public void SelfDiagnosticsEventListener_EmitEvent_OmitAsConfigured()
125125 using FileStream file = File . Open ( LOGFILEPATH , FileMode . Open , FileAccess . Read , FileShare . ReadWrite | FileShare . Delete ) ;
126126 var buffer = new byte [ 256 ] ;
127127
128- // Suppress CA2022 error: Avoid inexact read with 'System.IO.FileStream.Read(byte[], int, int)'
129- _ = file . Read ( buffer , 0 , buffer . Length ) ;
128+ int bytesRead = 0 ;
129+ int totalBytesRead = 0 ;
130+
131+ while ( totalBytesRead < buffer . Length )
132+ {
133+ bytesRead = file . Read ( buffer , totalBytesRead , buffer . Length - totalBytesRead ) ;
134+ if ( bytesRead == 0 )
135+ {
136+ break ;
137+ }
138+
139+ totalBytesRead += bytesRead ;
140+ }
141+
130142 Assert . Equal ( '\0 ' , ( char ) buffer [ 0 ] ) ;
131143 }
132144
@@ -259,9 +271,21 @@ private static void AssertFileOutput(string filePath, string eventMessage)
259271 using FileStream file = File . Open ( filePath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite | FileShare . Delete ) ;
260272 var buffer = new byte [ 256 ] ;
261273
262- // Suppress CA2022 error: Avoid inexact read with 'System.IO.FileStream.Read(byte[], int, int)'
263- _ = file . Read ( buffer , 0 , buffer . Length ) ;
264- string logLine = Encoding . UTF8 . GetString ( buffer ) ;
274+ int bytesRead = 0 ;
275+ int totalBytesRead = 0 ;
276+
277+ while ( totalBytesRead < buffer . Length )
278+ {
279+ bytesRead = file . Read ( buffer , totalBytesRead , buffer . Length - totalBytesRead ) ;
280+ if ( bytesRead == 0 )
281+ {
282+ break ;
283+ }
284+
285+ totalBytesRead += bytesRead ;
286+ }
287+
288+ string logLine = Encoding . UTF8 . GetString ( buffer , 0 , totalBytesRead ) ;
265289 string logMessage = ParseLogMessage ( logLine ) ;
266290 Assert . StartsWith ( eventMessage , logMessage ) ;
267291 }
0 commit comments