1- // Copyright (c) Six Labors.
1+ // Copyright (c) Six Labors.
22// Licensed under the Six Labors Split License.
33
44using SixLabors . ImageSharp . IO ;
@@ -11,36 +11,113 @@ public class LocalFileSystemTests
1111 public void OpenRead ( )
1212 {
1313 string path = Path . GetTempFileName ( ) ;
14- string testData = Guid . NewGuid ( ) . ToString ( ) ;
15- File . WriteAllText ( path , testData ) ;
14+ try
15+ {
16+ string testData = Guid . NewGuid ( ) . ToString ( ) ;
17+ File . WriteAllText ( path , testData ) ;
1618
17- var fs = new LocalFileSystem ( ) ;
19+ LocalFileSystem fs = new ( ) ;
1820
19- using ( var r = new StreamReader ( fs . OpenRead ( path ) ) )
20- {
21- string data = r . ReadToEnd ( ) ;
21+ using ( FileStream stream = ( FileStream ) fs . OpenRead ( path ) )
22+ using ( StreamReader reader = new ( stream ) )
23+ {
24+ Assert . False ( stream . IsAsync ) ;
25+ Assert . True ( stream . CanRead ) ;
26+ Assert . False ( stream . CanWrite ) ;
2227
23- Assert . Equal ( testData , data ) ;
28+ string data = reader . ReadToEnd ( ) ;
29+
30+ Assert . Equal ( testData , data ) ;
31+ }
2432 }
33+ finally
34+ {
35+ File . Delete ( path ) ;
36+ }
37+ }
2538
26- File . Delete ( path ) ;
39+ [ Fact ]
40+ public async Task OpenReadAsynchronous ( )
41+ {
42+ string path = Path . GetTempFileName ( ) ;
43+ try
44+ {
45+ string testData = Guid . NewGuid ( ) . ToString ( ) ;
46+ File . WriteAllText ( path , testData ) ;
47+
48+ LocalFileSystem fs = new ( ) ;
49+
50+ await using ( FileStream stream = ( FileStream ) fs . OpenReadAsynchronous ( path ) )
51+ using ( StreamReader reader = new ( stream ) )
52+ {
53+ Assert . True ( stream . IsAsync ) ;
54+ Assert . True ( stream . CanRead ) ;
55+ Assert . False ( stream . CanWrite ) ;
56+
57+ string data = await reader . ReadToEndAsync ( ) ;
58+
59+ Assert . Equal ( testData , data ) ;
60+ }
61+ }
62+ finally
63+ {
64+ File . Delete ( path ) ;
65+ }
2766 }
2867
2968 [ Fact ]
3069 public void Create ( )
3170 {
3271 string path = Path . GetTempFileName ( ) ;
33- string testData = Guid . NewGuid ( ) . ToString ( ) ;
34- var fs = new LocalFileSystem ( ) ;
72+ try
73+ {
74+ string testData = Guid . NewGuid ( ) . ToString ( ) ;
75+ LocalFileSystem fs = new ( ) ;
76+
77+ using ( FileStream stream = ( FileStream ) fs . Create ( path ) )
78+ using ( StreamWriter writer = new ( stream ) )
79+ {
80+ Assert . False ( stream . IsAsync ) ;
81+ Assert . True ( stream . CanRead ) ;
82+ Assert . True ( stream . CanWrite ) ;
3583
36- using ( var r = new StreamWriter ( fs . Create ( path ) ) )
84+ writer . Write ( testData ) ;
85+ }
86+
87+ string data = File . ReadAllText ( path ) ;
88+ Assert . Equal ( testData , data ) ;
89+ }
90+ finally
3791 {
38- r . Write ( testData ) ;
92+ File . Delete ( path ) ;
3993 }
94+ }
4095
41- string data = File . ReadAllText ( path ) ;
42- Assert . Equal ( testData , data ) ;
96+ [ Fact ]
97+ public async Task CreateAsynchronous ( )
98+ {
99+ string path = Path . GetTempFileName ( ) ;
100+ try
101+ {
102+ string testData = Guid . NewGuid ( ) . ToString ( ) ;
103+ LocalFileSystem fs = new ( ) ;
104+
105+ await using ( FileStream stream = ( FileStream ) fs . CreateAsynchronous ( path ) )
106+ await using ( StreamWriter writer = new ( stream ) )
107+ {
108+ Assert . True ( stream . IsAsync ) ;
109+ Assert . True ( stream . CanRead ) ;
110+ Assert . True ( stream . CanWrite ) ;
111+
112+ await writer . WriteAsync ( testData ) ;
113+ }
43114
44- File . Delete ( path ) ;
115+ string data = File . ReadAllText ( path ) ;
116+ Assert . Equal ( testData , data ) ;
117+ }
118+ finally
119+ {
120+ File . Delete ( path ) ;
121+ }
45122 }
46123}
0 commit comments