5
5
using System . Linq ;
6
6
using System . Security . Cryptography ;
7
7
using Xunit ;
8
+ using Xunit . Abstractions ;
8
9
9
10
namespace System . IO . Tests
10
11
{
@@ -236,6 +237,17 @@ public void WindowsAlternateDataStream(string defaultStream, string alternateStr
236
237
File . WriteAllText ( testFile2DefaultStream , "Bar" ) ;
237
238
Assert . Throws < IOException > ( ( ) => Copy ( testFile2DefaultStream , testFileAlternateStream ) ) ;
238
239
240
+ try
241
+ {
242
+ Copy ( testFile2DefaultStream , testFileAlternateStream ) ;
243
+ Assert . Fail ( ) ;
244
+ }
245
+ catch ( IOException e )
246
+ {
247
+ // Error code for "the file exists".
248
+ Assert . Equal ( - 2147024816 , e . HResult ) ;
249
+ }
250
+
239
251
// This always throws as you can't copy an alternate stream out (oddly)
240
252
Assert . Throws < IOException > ( ( ) => Copy ( testFileAlternateStream , testFile2 ) ) ;
241
253
Assert . Throws < IOException > ( ( ) => Copy ( testFileAlternateStream , testFile2 + alternateStream ) ) ;
@@ -275,6 +287,12 @@ public void OverwriteCopyOntoLink()
275
287
276
288
public class File_Copy_str_str_b : File_Copy_str_str
277
289
{
290
+ private ITestOutputHelper _output ;
291
+ public File_Copy_str_str_b ( ITestOutputHelper output )
292
+ {
293
+ _output = output ;
294
+ }
295
+
278
296
protected override void Copy ( string source , string dest )
279
297
{
280
298
File . Copy ( source , dest , false ) ;
@@ -352,6 +370,8 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt
352
370
353
371
// Copy the default stream into an alternate stream
354
372
File . WriteAllText ( testFileDefaultStream , "Foo" ) ;
373
+ Assert . Equal ( "Foo" , File . ReadAllText ( testFileDefaultStream ) ) ;
374
+ _output . WriteLine ( "Copying default stream into alternate stream." ) ;
355
375
Copy ( testFileDefaultStream , testFileAlternateStream ) ;
356
376
Assert . Equal ( testFile , testDirectory . GetFiles ( ) . Single ( ) . FullName ) ;
357
377
Assert . Equal ( "Foo" , File . ReadAllText ( testFileDefaultStream ) ) ;
@@ -361,6 +381,11 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt
361
381
string testFile2 = Path . Combine ( testDirectory . FullName , GetTestFileName ( ) ) ;
362
382
string testFile2DefaultStream = testFile2 + defaultStream ;
363
383
File . WriteAllText ( testFile2DefaultStream , "Bar" ) ;
384
+ Assert . Equal ( "Bar" , File . ReadAllText ( testFile2DefaultStream ) ) ;
385
+ Assert . Equal ( "Foo" , File . ReadAllText ( testFileAlternateStream ) ) ;
386
+ _output . WriteLine ( $ "Attributes for '{ testFile2DefaultStream } ': { File . GetAttributes ( testFile2DefaultStream ) } ") ;
387
+ _output . WriteLine ( $ "Attributes for '{ testFileAlternateStream } ': { File . GetAttributes ( testFileAlternateStream ) } ") ;
388
+ _output . WriteLine ( "Overwriting alternate stream." ) ;
364
389
Copy ( testFile2DefaultStream , testFileAlternateStream , overwrite : true ) ;
365
390
Assert . Equal ( "Foo" , File . ReadAllText ( testFileDefaultStream ) ) ;
366
391
Assert . Equal ( "Bar" , File . ReadAllText ( testFileAlternateStream ) ) ;
0 commit comments