@@ -144,16 +144,16 @@ public void WhenLimitIsNotSpecifiedAndEncodingHasNoPreambleDataIsCorrectlyAppend
144
144
}
145
145
146
146
[ Fact ]
147
- public void WhenStreamWrapperIsSpecifiedOutputStreamIsWrapped ( )
147
+ public void OnOpenedLifecycleHookCanWrapUnderlyingStream ( )
148
148
{
149
149
var gzipWrapper = new GZipHooks ( ) ;
150
150
151
151
using ( var tmp = TempFolder . ForCaller ( ) )
152
152
{
153
- var nonexistent = tmp . AllocateFilename ( "txt" ) ;
153
+ var path = tmp . AllocateFilename ( "txt" ) ;
154
154
var evt = Some . LogEvent ( "Hello, world!" ) ;
155
155
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 ) )
157
157
{
158
158
sink . Emit ( evt ) ;
159
159
sink . Emit ( evt ) ;
@@ -164,7 +164,7 @@ public void WhenStreamWrapperIsSpecifiedOutputStreamIsWrapped()
164
164
List < string > lines ;
165
165
using ( var textStream = new MemoryStream ( ) )
166
166
{
167
- using ( var fs = System . IO . File . OpenRead ( nonexistent ) )
167
+ using ( var fs = System . IO . File . OpenRead ( path ) )
168
168
using ( var decompressStream = new GZipStream ( fs , CompressionMode . Decompress ) )
169
169
{
170
170
decompressStream . CopyTo ( textStream ) ;
@@ -179,6 +179,33 @@ public void WhenStreamWrapperIsSpecifiedOutputStreamIsWrapped()
179
179
}
180
180
}
181
181
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
+
182
209
static void WriteTwoEventsAndCheckOutputFileLength ( long ? maxBytes , Encoding encoding )
183
210
{
184
211
using ( var tmp = TempFolder . ForCaller ( ) )
0 commit comments