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,97 @@ 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 ( Stream stream = fs . OpenRead ( path ) )
22+ using ( StreamReader reader = new ( stream ) )
23+ {
24+ string data = reader . ReadToEnd ( ) ;
2225
23- Assert . Equal ( testData , data ) ;
26+ Assert . Equal ( testData , data ) ;
27+ }
28+ }
29+ finally
30+ {
31+ File . Delete ( path ) ;
2432 }
33+ }
2534
26- File . Delete ( path ) ;
35+ [ Fact ]
36+ public async Task OpenReadAsynchronous ( )
37+ {
38+ string path = Path . GetTempFileName ( ) ;
39+ try
40+ {
41+ string testData = Guid . NewGuid ( ) . ToString ( ) ;
42+ File . WriteAllText ( path , testData ) ;
43+
44+ LocalFileSystem fs = new ( ) ;
45+
46+ await using ( Stream stream = fs . OpenReadAsynchronous ( path ) )
47+ using ( StreamReader reader = new ( stream ) )
48+ {
49+ string data = await reader . ReadToEndAsync ( ) ;
50+
51+ Assert . Equal ( testData , data ) ;
52+ }
53+ }
54+ finally
55+ {
56+ File . Delete ( path ) ;
57+ }
2758 }
2859
2960 [ Fact ]
3061 public void Create ( )
3162 {
3263 string path = Path . GetTempFileName ( ) ;
33- string testData = Guid . NewGuid ( ) . ToString ( ) ;
34- var fs = new LocalFileSystem ( ) ;
64+ try
65+ {
66+ string testData = Guid . NewGuid ( ) . ToString ( ) ;
67+ LocalFileSystem fs = new ( ) ;
3568
36- using ( var r = new StreamWriter ( fs . Create ( path ) ) )
69+ using ( Stream stream = fs . Create ( path ) )
70+ using ( StreamWriter writer = new ( stream ) )
71+ {
72+ writer . Write ( testData ) ;
73+ }
74+
75+ string data = File . ReadAllText ( path ) ;
76+ Assert . Equal ( testData , data ) ;
77+ }
78+ finally
3779 {
38- r . Write ( testData ) ;
80+ File . Delete ( path ) ;
3981 }
82+ }
4083
41- string data = File . ReadAllText ( path ) ;
42- Assert . Equal ( testData , data ) ;
84+ [ Fact ]
85+ public async Task CreateAsynchronous ( )
86+ {
87+ string path = Path . GetTempFileName ( ) ;
88+ try
89+ {
90+ string testData = Guid . NewGuid ( ) . ToString ( ) ;
91+ LocalFileSystem fs = new ( ) ;
4392
44- File . Delete ( path ) ;
93+ await using ( Stream stream = fs . CreateAsynchronous ( path ) )
94+ using ( StreamWriter writer = new ( stream ) )
95+ {
96+ await writer . WriteAsync ( testData ) ;
97+ }
98+
99+ string data = File . ReadAllText ( path ) ;
100+ Assert . Equal ( testData , data ) ;
101+ }
102+ finally
103+ {
104+ File . Delete ( path ) ;
105+ }
45106 }
46107}
0 commit comments