@@ -144,16 +144,16 @@ public void WhenLimitIsNotSpecifiedAndEncodingHasNoPreambleDataIsCorrectlyAppend
144144 }
145145
146146 [ Fact ]
147- public void WhenStreamWrapperIsSpecifiedOutputStreamIsWrapped ( )
147+ public void OnOpenedLifecycleHookCanWrapUnderlyingStream ( )
148148 {
149149 var gzipWrapper = new GZipHooks ( ) ;
150150
151151 using ( var tmp = TempFolder . ForCaller ( ) )
152152 {
153- var nonexistent = tmp . AllocateFilename ( "txt" ) ;
153+ var path = tmp . AllocateFilename ( "txt" ) ;
154154 var evt = Some . LogEvent ( "Hello, world!" ) ;
155155
156- using ( var sink = new FileSink ( nonexistent , new JsonFormatter ( ) , null , null , false , gzipWrapper ) )
156+ using ( var sink = new FileSink ( path , new JsonFormatter ( ) , null , null , false , gzipWrapper ) )
157157 {
158158 sink . Emit ( evt ) ;
159159 sink . Emit ( evt ) ;
@@ -164,7 +164,7 @@ public void WhenStreamWrapperIsSpecifiedOutputStreamIsWrapped()
164164 List < string > lines ;
165165 using ( var textStream = new MemoryStream ( ) )
166166 {
167- using ( var fs = System . IO . File . OpenRead ( nonexistent ) )
167+ using ( var fs = System . IO . File . OpenRead ( path ) )
168168 using ( var decompressStream = new GZipStream ( fs , CompressionMode . Decompress ) )
169169 {
170170 decompressStream . CopyTo ( textStream ) ;
@@ -179,6 +179,33 @@ public void WhenStreamWrapperIsSpecifiedOutputStreamIsWrapped()
179179 }
180180 }
181181
182+ [ Fact ]
183+ public static void OnOpenedLifecycleHookCanWriteFileHeader ( )
184+ {
185+ using ( var tmp = TempFolder . ForCaller ( ) )
186+ {
187+ var headerWriter = new FileHeaderWriter ( "This is the file header" ) ;
188+
189+ var path = tmp . AllocateFilename ( "txt" ) ;
190+ using ( new FileSink ( path , new JsonFormatter ( ) , null , new UTF8Encoding ( false ) , false , headerWriter ) )
191+ {
192+ // Open and write header
193+ }
194+
195+ using ( var sink = new FileSink ( path , new JsonFormatter ( ) , null , new UTF8Encoding ( false ) , false , headerWriter ) )
196+ {
197+ // Length check should prevent duplicate header here
198+ sink . Emit ( Some . LogEvent ( ) ) ;
199+ }
200+
201+ var lines = System . IO . File . ReadAllLines ( path ) ;
202+
203+ Assert . Equal ( 2 , lines . Length ) ;
204+ Assert . Equal ( headerWriter . Header , lines [ 0 ] ) ;
205+ Assert . Equal ( '{' , lines [ 1 ] [ 0 ] ) ;
206+ }
207+ }
208+
182209 static void WriteTwoEventsAndCheckOutputFileLength ( long ? maxBytes , Encoding encoding )
183210 {
184211 using ( var tmp = TempFolder . ForCaller ( ) )
0 commit comments