Skip to content

Commit c49e411

Browse files
Copilotjkotas
andcommitted
Refactor Delete, Move, and Exists tests to use shared test data
Co-authored-by: jkotas <[email protected]>
1 parent c87ce5b commit c49e411

File tree

3 files changed

+10
-170
lines changed

3 files changed

+10
-170
lines changed

src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Delete.cs

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -201,41 +201,8 @@ public void WindowsDeleteAlternateDataStream(string streamName)
201201
Assert.True(testFile.Exists);
202202
}
203203

204-
[Theory]
205-
[InlineData(" leading")]
206-
[InlineData(" leading")]
207-
[InlineData(".leading")]
208-
[InlineData("..leading")]
209-
public void DeleteLeadingSpacesDots(string fileName)
210-
{
211-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
212-
string filePath = Path.Combine(testDir.FullName, fileName);
213-
File.Create(filePath).Dispose();
214-
Assert.True(File.Exists(filePath));
215-
Delete(filePath);
216-
Assert.False(File.Exists(filePath));
217-
}
218-
219-
[Theory]
220-
[InlineData("-")]
221-
[InlineData("--")]
222-
[InlineData("-filename")]
223-
public void DeleteDashPrefixedNames(string fileName)
224-
{
225-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
226-
string filePath = Path.Combine(testDir.FullName, fileName);
227-
File.Create(filePath).Dispose();
228-
Assert.True(File.Exists(filePath));
229-
Delete(filePath);
230-
Assert.False(File.Exists(filePath));
231-
}
232-
233-
[Theory]
234-
[InlineData("file\tname")]
235-
[InlineData("file\rname")]
236-
[InlineData("file\vname")]
237-
[PlatformSpecific(TestPlatforms.AnyUnix)]
238-
public void UnixDeleteEmbeddedControlCharacters(string fileName)
204+
[Theory, MemberData(nameof(TestData.ValidFileNames), MemberType = typeof(TestData))]
205+
public void DeleteWithProblematicNames(string fileName)
239206
{
240207
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
241208
string filePath = Path.Combine(testDir.FullName, fileName);
@@ -246,10 +213,7 @@ public void UnixDeleteEmbeddedControlCharacters(string fileName)
246213
}
247214

248215
[ConditionalTheory(nameof(UsingNewNormalization))]
249-
[InlineData("trailing ")]
250-
[InlineData("trailing ")]
251-
[InlineData("trailing.")]
252-
[InlineData("trailing..")]
216+
[MemberData(nameof(TestData.WindowsTrailingProblematicFileNames), MemberType = typeof(TestData))]
253217
[PlatformSpecific(TestPlatforms.Windows)]
254218
public void WindowsDeleteTrailingSpacePeriod_ViaExtendedSyntax(string fileName)
255219
{
@@ -265,19 +229,6 @@ public void WindowsDeleteTrailingSpacePeriod_ViaExtendedSyntax(string fileName)
265229
Assert.False(File.Exists(extendedPath));
266230
}
267231

268-
[Theory]
269-
[InlineData("name with spaces")]
270-
[InlineData("name.with.periods")]
271-
public void DeleteEmbeddedSpacesPeriods(string fileName)
272-
{
273-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
274-
string filePath = Path.Combine(testDir.FullName, fileName);
275-
File.Create(filePath).Dispose();
276-
Assert.True(File.Exists(filePath));
277-
Delete(filePath);
278-
Assert.False(File.Exists(filePath));
279-
}
280-
281232
#endregion
282233
}
283234
}

src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Exists.cs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -230,37 +230,8 @@ public void DirectoryWithComponentLongerThanMaxComponentAsPath_ReturnsFalse(stri
230230
Assert.False(Exists(component));
231231
}
232232

233-
[Theory]
234-
[InlineData(" leading")]
235-
[InlineData(" leading")]
236-
[InlineData(".leading")]
237-
[InlineData("..leading")]
238-
public void ExistsLeadingSpacesDots(string fileName)
239-
{
240-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
241-
string filePath = Path.Combine(testDir.FullName, fileName);
242-
File.Create(filePath).Dispose();
243-
Assert.True(Exists(filePath));
244-
}
245-
246-
[Theory]
247-
[InlineData("-")]
248-
[InlineData("--")]
249-
[InlineData("-filename")]
250-
public void ExistsDashPrefixedNames(string fileName)
251-
{
252-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
253-
string filePath = Path.Combine(testDir.FullName, fileName);
254-
File.Create(filePath).Dispose();
255-
Assert.True(Exists(filePath));
256-
}
257-
258-
[Theory]
259-
[InlineData("file\tname")]
260-
[InlineData("file\rname")]
261-
[InlineData("file\vname")]
262-
[PlatformSpecific(TestPlatforms.AnyUnix)]
263-
public void UnixExistsEmbeddedControlCharacters(string fileName)
233+
[Theory, MemberData(nameof(TestData.ValidFileNames), MemberType = typeof(TestData))]
234+
public void ExistsWithProblematicNames(string fileName)
264235
{
265236
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
266237
string filePath = Path.Combine(testDir.FullName, fileName);
@@ -269,10 +240,7 @@ public void UnixExistsEmbeddedControlCharacters(string fileName)
269240
}
270241

271242
[ConditionalTheory(nameof(UsingNewNormalization))]
272-
[InlineData("trailing ")]
273-
[InlineData("trailing ")]
274-
[InlineData("trailing.")]
275-
[InlineData("trailing..")]
243+
[MemberData(nameof(TestData.WindowsTrailingProblematicFileNames), MemberType = typeof(TestData))]
276244
[PlatformSpecific(TestPlatforms.Windows)]
277245
public void WindowsExistsTrailingSpacePeriod_ViaExtendedSyntax(string fileName)
278246
{
@@ -288,17 +256,6 @@ public void WindowsExistsTrailingSpacePeriod_ViaExtendedSyntax(string fileName)
288256
Assert.False(Exists(filePath));
289257
}
290258

291-
[Theory]
292-
[InlineData("name with spaces")]
293-
[InlineData("name.with.periods")]
294-
public void ExistsEmbeddedSpacesPeriods(string fileName)
295-
{
296-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
297-
string filePath = Path.Combine(testDir.FullName, fileName);
298-
File.Create(filePath).Dispose();
299-
Assert.True(Exists(filePath));
300-
}
301-
302259
#endregion
303260
}
304261

src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Move.cs

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -395,64 +395,12 @@ public void MoveOntoExistingFileNoOverwrite()
395395
Assert.Equal(destContents, File.ReadAllBytes(destPath));
396396
}
397397

398-
[Theory]
399-
[InlineData(" leading", "destination")]
400-
[InlineData("source", " leading")]
401-
[InlineData(" leading", " moved")]
402-
public void MoveWithLeadingSpaces(string sourceFileName, string destFileName)
398+
[Theory, MemberData(nameof(TestData.ValidFileNames), MemberType = typeof(TestData))]
399+
public void MoveWithProblematicNames(string fileName)
403400
{
404401
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
405-
string srcPath = Path.Combine(testDir.FullName, sourceFileName);
406-
string destPath = Path.Combine(testDir.FullName, destFileName);
407-
408-
File.Create(srcPath).Dispose();
409-
Move(srcPath, destPath);
410-
411-
Assert.False(File.Exists(srcPath));
412-
Assert.True(File.Exists(destPath));
413-
}
414-
415-
[Theory]
416-
[InlineData(".leading", "destination")]
417-
[InlineData("source", ".leading")]
418-
public void MoveWithLeadingDots(string sourceFileName, string destFileName)
419-
{
420-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
421-
string srcPath = Path.Combine(testDir.FullName, sourceFileName);
422-
string destPath = Path.Combine(testDir.FullName, destFileName);
423-
424-
File.Create(srcPath).Dispose();
425-
Move(srcPath, destPath);
426-
427-
Assert.False(File.Exists(srcPath));
428-
Assert.True(File.Exists(destPath));
429-
}
430-
431-
[Theory]
432-
[InlineData("-", "destination")]
433-
[InlineData("source", "--")]
434-
public void MoveWithDashPrefixedNames(string sourceFileName, string destFileName)
435-
{
436-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
437-
string srcPath = Path.Combine(testDir.FullName, sourceFileName);
438-
string destPath = Path.Combine(testDir.FullName, destFileName);
439-
440-
File.Create(srcPath).Dispose();
441-
Move(srcPath, destPath);
442-
443-
Assert.False(File.Exists(srcPath));
444-
Assert.True(File.Exists(destPath));
445-
}
446-
447-
[Theory]
448-
[InlineData("file\tname", "destination")]
449-
[InlineData("source", "file\rname")]
450-
[PlatformSpecific(TestPlatforms.AnyUnix)]
451-
public void UnixMoveWithEmbeddedControlCharacters(string sourceFileName, string destFileName)
452-
{
453-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
454-
string srcPath = Path.Combine(testDir.FullName, sourceFileName);
455-
string destPath = Path.Combine(testDir.FullName, destFileName);
402+
string srcPath = Path.Combine(testDir.FullName, fileName);
403+
string destPath = Path.Combine(testDir.FullName, fileName + "_moved");
456404

457405
File.Create(srcPath).Dispose();
458406
Move(srcPath, destPath);
@@ -487,21 +435,5 @@ public void WindowsMoveWithTrailingSpacePeriod_ViaExtendedSyntax(string sourceFi
487435
Assert.False(File.Exists(sourceToMove));
488436
Assert.True(File.Exists(destToMove));
489437
}
490-
491-
[Theory]
492-
[InlineData("name with spaces", "dest with spaces")]
493-
[InlineData("name.with.periods", "dest.with.periods")]
494-
public void MoveEmbeddedSpacesPeriods(string sourceFileName, string destFileName)
495-
{
496-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
497-
string srcPath = Path.Combine(testDir.FullName, sourceFileName);
498-
string destPath = Path.Combine(testDir.FullName, destFileName);
499-
500-
File.Create(srcPath).Dispose();
501-
Move(srcPath, destPath);
502-
503-
Assert.False(File.Exists(srcPath));
504-
Assert.True(File.Exists(destPath));
505-
}
506438
}
507439
}

0 commit comments

Comments
 (0)