@@ -32,20 +32,21 @@ public void NullFileName()
32
32
[ Fact ]
33
33
public void EmptyFileName ( )
34
34
{
35
- Assert . Throws < ArgumentException > ( ( ) => GetEntries ( "" ) ) ;
35
+ Assert . Throws < ArgumentException > ( ( ) => GetEntries ( String . Empty ) ) ;
36
36
}
37
37
38
38
[ Fact ]
39
- public void NonexistentDirectory ( )
39
+ public void InvalidFileNames ( )
40
40
{
41
- Assert . Throws < DirectoryNotFoundException > ( ( ) => GetEntries ( GetTestFilePath ( ) ) ) ;
41
+ DirectoryInfo testDir = new DirectoryInfo ( TestDirectory ) ;
42
+ Assert . Throws < DirectoryNotFoundException > ( ( ) => GetEntries ( "," ) ) ;
43
+ Assert . Throws < DirectoryNotFoundException > ( ( ) => GetEntries ( "DoesNotExist" ) ) ;
42
44
}
43
45
44
46
[ Fact ]
45
- public void FileNameWithSpaces ( )
47
+ public void NonexistentFile ( )
46
48
{
47
- String strTempDir = " " ;
48
- Assert . Throws < ArgumentException > ( ( ) => GetEntries ( strTempDir ) ) ;
49
+ Assert . Throws < DirectoryNotFoundException > ( ( ) => GetEntries ( GetTestFilePath ( ) ) ) ;
49
50
}
50
51
51
52
[ Fact ]
@@ -68,7 +69,7 @@ public void CurrentDirectory()
68
69
[ Fact ]
69
70
public void ValidDirectoryEmpty ( )
70
71
{
71
- String testDir = Path . Combine ( TestDirectory , GetTestFilePath ( ) ) ;
72
+ String testDir = Path . Combine ( TestDirectory , GetTestFileName ( ) ) ;
72
73
new DirectoryInfo ( testDir ) . Create ( ) ;
73
74
String [ ] strArr = GetEntries ( testDir ) ;
74
75
Assert . NotNull ( strArr ) ;
@@ -78,7 +79,7 @@ public void ValidDirectoryEmpty()
78
79
[ Fact ]
79
80
public void ValidDirectoryNotEmpty ( )
80
81
{
81
- using ( FileStream fs1 = new FileInfo ( Path . Combine ( TestDirectory , GetTestFilePath ( ) ) ) . Create ( ) )
82
+ using ( File . Create ( Path . Combine ( TestDirectory , GetTestFileName ( ) ) ) )
82
83
{
83
84
String [ ] strArr = GetEntries ( TestDirectory ) ;
84
85
Assert . NotNull ( strArr ) ;
@@ -93,47 +94,73 @@ public void NonexistentPath()
93
94
}
94
95
95
96
[ Fact ]
96
- public void SubDirectories ( )
97
+ public void GetEntriesThenDelete ( )
97
98
{
98
- DirectoryInfo testDir = new DirectoryInfo ( TestDirectory ) ;
99
- testDir . CreateSubdirectory ( "TestDir1" ) ;
100
- testDir . CreateSubdirectory ( "TestDir2" ) ;
101
- testDir . CreateSubdirectory ( "TestDir3" ) ;
102
- using ( new FileInfo ( Path . Combine ( TestDirectory , "TestFile1" ) ) . Create ( ) )
103
- using ( new FileInfo ( Path . Combine ( TestDirectory , "TestFile2" ) ) . Create ( ) )
104
- using ( new FileInfo ( Path . Combine ( TestDirectory , "Test1File2" ) ) . Create ( ) )
105
- using ( new FileInfo ( Path . Combine ( TestDirectory , "Test1Dir2" ) ) . Create ( ) )
99
+ String testDirPath = Path . Combine ( TestDirectory , GetTestFilePath ( ) ) ;
100
+ DirectoryInfo testDirInfo = new DirectoryInfo ( testDirPath ) ;
101
+ testDirInfo . Create ( ) ;
102
+ String testDir1 = GetTestFileName ( ) ;
103
+ String testDir2 = GetTestFileName ( ) ;
104
+ String testFile1 = GetTestFileName ( ) ;
105
+ String testFile2 = GetTestFileName ( ) ;
106
+ String testFile3 = GetTestFileName ( ) ;
107
+ String testFile4 = GetTestFileName ( ) ;
108
+ String testFile5 = GetTestFileName ( ) ;
109
+ testDirInfo . CreateSubdirectory ( testDir1 ) ;
110
+ testDirInfo . CreateSubdirectory ( testDir2 ) ;
111
+ using ( File . Create ( Path . Combine ( testDirPath , testFile1 ) ) )
112
+ using ( File . Create ( Path . Combine ( testDirPath , testFile2 ) ) )
113
+ using ( File . Create ( Path . Combine ( testDirPath , testFile3 ) ) )
106
114
{
107
- String [ ] strArr = GetEntries ( TestDirectory ) ;
108
- Assert . Equal ( 7 , strArr . Length ) ;
109
- Assert . Contains ( Path . Combine ( TestDirectory , "TestDir1" ) , strArr ) ;
110
- Assert . Contains ( Path . Combine ( TestDirectory , "TestDir2" ) , strArr ) ;
111
- Assert . Contains ( Path . Combine ( TestDirectory , "TestDir3" ) , strArr ) ;
112
- Assert . Contains ( Path . Combine ( TestDirectory , "Test1File2" ) , strArr ) ;
113
- Assert . Contains ( Path . Combine ( TestDirectory , "Test1Dir2" ) , strArr ) ;
114
- Assert . Contains ( Path . Combine ( TestDirectory , "TestFile1" ) , strArr ) ;
115
- Assert . Contains ( Path . Combine ( TestDirectory , "TestFile2" ) , strArr ) ;
115
+ String [ ] results ;
116
+ using ( File . Create ( Path . Combine ( testDirPath , testFile4 ) ) )
117
+ using ( File . Create ( Path . Combine ( testDirPath , testFile5 ) ) )
118
+ {
119
+ results = GetEntries ( testDirPath ) ;
120
+ Assert . NotNull ( results ) ;
121
+ Assert . NotEmpty ( results ) ;
122
+ Assert . Contains ( Path . Combine ( testDirPath , testFile1 ) , results ) ;
123
+ Assert . Contains ( Path . Combine ( testDirPath , testFile2 ) , results ) ;
124
+ Assert . Contains ( Path . Combine ( testDirPath , testFile3 ) , results ) ;
125
+ Assert . Contains ( Path . Combine ( testDirPath , testFile4 ) , results ) ;
126
+ Assert . Contains ( Path . Combine ( testDirPath , testFile5 ) , results ) ;
127
+ Assert . Contains ( Path . Combine ( testDirPath , testDir1 ) , results ) ;
128
+ Assert . Contains ( Path . Combine ( testDirPath , testDir2 ) , results ) ;
129
+ }
130
+
131
+ File . Delete ( Path . Combine ( testDirPath , testFile4 ) ) ;
132
+ File . Delete ( Path . Combine ( testDirPath , testFile5 ) ) ;
133
+ FailSafeDirectoryOperations . DeleteDirectory ( testDir1 , true ) ;
134
+
135
+ results = GetEntries ( testDirPath ) ;
136
+ Assert . NotNull ( results ) ;
137
+ Assert . NotEmpty ( results ) ;
138
+ Assert . Contains ( Path . Combine ( testDirPath , testFile1 ) , results ) ;
139
+ Assert . Contains ( Path . Combine ( testDirPath , testFile2 ) , results ) ;
140
+ Assert . Contains ( Path . Combine ( testDirPath , testFile3 ) , results ) ;
141
+ Assert . Contains ( Path . Combine ( testDirPath , testDir2 ) , results ) ;
116
142
}
117
143
}
118
144
119
145
[ Fact ]
120
146
public void IgnoreSubDirectoryFiles ( )
121
147
{
122
- String testDir1Str = GetTestFileName ( ) ;
123
- String testDir11Str = GetTestFileName ( ) ;
124
- DirectoryInfo testDir = new DirectoryInfo ( TestDirectory ) ;
125
- DirectoryInfo testDir1 = testDir . CreateSubdirectory ( testDir1Str ) ;
126
- testDir1 . CreateSubdirectory ( testDir11Str ) ;
127
- using ( new FileInfo ( Path . Combine ( TestDirectory , testDir1Str , testDir11Str , GetTestFileName ( ) ) ) . Create ( ) )
128
- using ( new FileInfo ( Path . Combine ( TestDirectory , testDir1Str , GetTestFileName ( ) ) ) . Create ( ) )
148
+ String testDir = GetTestFileName ( ) ;
149
+ String testFile1 = Path . Combine ( TestDirectory , GetTestFileName ( ) ) ;
150
+ String testFile2 = Path . Combine ( TestDirectory , testDir , GetTestFileName ( ) ) ;
151
+ Directory . CreateDirectory ( Path . Combine ( TestDirectory , testDir ) ) ;
152
+ using ( File . Create ( testFile1 ) )
153
+ using ( File . Create ( testFile2 ) )
129
154
{
130
- Assert . Equal ( 2 , GetEntries ( Path . Combine ( TestDirectory , testDir1Str ) ) . Length ) ;
155
+ String [ ] results = GetEntries ( TestDirectory ) ;
156
+ Assert . Contains ( testFile1 , results ) ;
157
+ Assert . DoesNotContain ( testFile2 , results ) ;
131
158
}
132
159
}
133
160
134
161
#endregion
135
162
136
- #region WindowsOnly
163
+ #region PlatformSpecific
137
164
138
165
[ Fact ]
139
166
[ PlatformSpecific ( PlatformID . Windows ) ]
@@ -143,9 +170,51 @@ public void WildCharactersFileName()
143
170
Assert . Throws < ArgumentException > ( ( ) => GetEntries ( strTempDir ) ) ;
144
171
}
145
172
146
- #endregion
147
- }
148
-
173
+ [ Fact ]
174
+ [ PlatformSpecific ( PlatformID . Windows ) ]
175
+ public void WindowsFileNameWithSpaces ( )
176
+ {
177
+ Assert . Throws < ArgumentException > ( ( ) => GetEntries ( "\n " ) ) ;
178
+ Assert . Throws < ArgumentException > ( ( ) => GetEntries ( " " ) ) ;
179
+ Assert . Throws < ArgumentException > ( ( ) => GetEntries ( " " ) ) ;
180
+ Assert . Throws < ArgumentException > ( ( ) => GetEntries ( "" ) ) ;
181
+ Assert . Throws < ArgumentException > ( ( ) => GetEntries ( ">" ) ) ;
182
+ Assert . Throws < ArgumentException > ( ( ) => GetEntries ( "\0 " ) ) ;
183
+ }
149
184
185
+ [ Fact ]
186
+ [ PlatformSpecific ( PlatformID . AnyUnix ) ]
187
+ [ ActiveIssue ( 2205 ) ]
188
+ public void UnixFileNameWithSpaces ( )
189
+ {
190
+ String testDirPath = Path . Combine ( TestDirectory , GetTestFileName ( ) ) ;
191
+ using ( File . Create ( Path . Combine ( testDirPath , " " ) ) )
192
+ using ( File . Create ( Path . Combine ( testDirPath , " " ) ) )
193
+ using ( File . Create ( Path . Combine ( testDirPath , "\n " ) ) )
194
+ {
195
+ String [ ] results = GetEntries ( testDirPath ) ;
196
+ Assert . Contains ( Path . Combine ( testDirPath , " " ) , results ) ;
197
+ Assert . Contains ( Path . Combine ( testDirPath , " " ) , results ) ;
198
+ Assert . Contains ( Path . Combine ( testDirPath , "\n " ) , results ) ;
199
+ }
200
+ }
150
201
202
+ [ Fact ]
203
+ [ PlatformSpecific ( PlatformID . AnyUnix ) ]
204
+ [ ActiveIssue ( 2205 ) ]
205
+ public void UnixDirectoryNameWithSpaces ( )
206
+ {
207
+ String testDirPath = Path . Combine ( TestDirectory , GetTestFileName ( ) ) ;
208
+ DirectoryInfo testDir = new DirectoryInfo ( testDirPath ) ;
209
+ testDir . CreateSubdirectory ( " " ) ;
210
+ testDir . CreateSubdirectory ( "\n " ) ;
211
+ testDir . CreateSubdirectory ( " " ) ;
212
+
213
+ String [ ] results = GetEntries ( testDirPath ) ;
214
+ Assert . Contains ( Path . Combine ( testDirPath , " " ) , results ) ;
215
+ Assert . Contains ( Path . Combine ( testDirPath , " " ) , results ) ;
216
+ Assert . Contains ( Path . Combine ( testDirPath , "\n " ) , results ) ;
217
+ }
218
+ #endregion
219
+ }
151
220
0 commit comments