Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 7713698

Browse files
committed
Merge pull request #2558 from ianhays/filestream
Modified calls to GetTestFilePath within loops to not use the same filename
2 parents b6b18dd + 1dbfabb commit 7713698

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ public void FileShareOpen()
6161
public void FileShareCreate()
6262
{
6363
// just check that the inputs are accepted, actual sharing varies by platform so we seperate the behavior testing
64+
int i = 0;
6465
foreach (FileShare share in shares)
6566
{
66-
using (FileStream fs = CreateFileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, share))
67+
using (FileStream fs = CreateFileStream(GetTestFilePath(i++), FileMode.Create, FileAccess.ReadWrite, share))
6768
{ }
6869

69-
using (FileStream fs = CreateFileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write, share))
70+
using (FileStream fs = CreateFileStream(GetTestFilePath(i++), FileMode.Create, FileAccess.Write, share))
7071
{ }
7172
}
7273
}
@@ -75,15 +76,16 @@ public void FileShareCreate()
7576
public void FileShareOpenOrCreate()
7677
{
7778
// just check that the inputs are accepted, actual sharing varies by platform so we seperate the behavior testing
79+
int i = 0;
7880
foreach (FileShare share in shares)
7981
{
80-
using (FileStream fs = CreateFileStream(GetTestFilePath(), FileMode.OpenOrCreate, FileAccess.ReadWrite, share))
82+
using (FileStream fs = CreateFileStream(GetTestFilePath(i++), FileMode.OpenOrCreate, FileAccess.ReadWrite, share))
8183
{ }
8284

83-
using (FileStream fs = CreateFileStream(GetTestFilePath(), FileMode.OpenOrCreate, FileAccess.Write, share))
85+
using (FileStream fs = CreateFileStream(GetTestFilePath(i++), FileMode.OpenOrCreate, FileAccess.Write, share))
8486
{ }
8587

86-
using (FileStream fs = CreateFileStream(GetTestFilePath(), FileMode.OpenOrCreate, FileAccess.Read, share))
88+
using (FileStream fs = CreateFileStream(GetTestFilePath(i++), FileMode.OpenOrCreate, FileAccess.Read, share))
8789
{ }
8890
}
8991
}

src/System.IO.FileSystem/tests/FileStream/ctor_str_fm_fa_fs_buffer_fo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public void InvalidFileOptionsThrow()
2626
}
2727

2828
[Fact]
29-
[ActiveIssue(1434)]
3029
public void ValidFileOptions()
3130
{
31+
int i = 0;
3232
foreach(FileOptions option in Enum.GetValues(typeof(FileOptions)))
3333
{
34-
using (CreateFileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, c_DefaultBufferSize, option))
34+
using (CreateFileStream(GetTestFilePath(i++), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, c_DefaultBufferSize, option))
3535
{ }
3636
}
3737

src/System.IO.FileSystem/tests/FileSystemTest.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,22 @@ public FileSystemTest()
3030
}
3131

3232
// Generates a test file path to use that is unique name per test case / call
33-
public string GetTestFilePath([CallerMemberName]string fileName = null, [CallerLineNumber] int lineNumber = 0)
33+
public string GetTestFilePath([CallerMemberName]string memberName = null, [CallerLineNumber] int lineNumber = 0)
3434
{
35-
return Path.Combine(TestDirectory, String.Format("{0}_{1}", fileName ?? "testFile", lineNumber));
35+
return Path.Combine(TestDirectory, String.Format("{0}_{1}", memberName ?? "testFile", lineNumber));
36+
}
37+
38+
// Generates a test file path to use that is unique name per test case / call with an additional
39+
// variable to specify a trailing identifier
40+
public string GetTestFilePath(int index, [CallerMemberName]string memberName = null, [CallerLineNumber] int lineNumber = 0)
41+
{
42+
return Path.Combine(TestDirectory, String.Format("{0}_{1}_{2}", memberName ?? "testFile", lineNumber, index));
3643
}
3744

3845
// Generates a test file name to use that is unique name per test case / call
39-
public string GetTestFileName([CallerMemberName]string fileName = null, [CallerLineNumber] int lineNumber = 0)
46+
public string GetTestFileName([CallerMemberName]string memberName = null, [CallerLineNumber] int lineNumber = 0)
4047
{
41-
return String.Format("{0}_{1}", fileName ?? "testFile", lineNumber);
48+
return String.Format("{0}_{1}", memberName ?? "testFile", lineNumber);
4249
}
4350

4451
public void Dispose()

0 commit comments

Comments
 (0)