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

Commit 3098724

Browse files
author
Ian Hays
committed
Updated with PR feedback
1 parent 5aebb54 commit 3098724

File tree

8 files changed

+129
-75
lines changed

8 files changed

+129
-75
lines changed

src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void PathAlreadyExistsAsDirectory(FileAttributes attributes)
6363
}
6464

6565
[Fact]
66-
public void RootOath()
66+
public void RootPath()
6767
{
6868
string dirName = Path.GetPathRoot(Directory.GetCurrentDirectory());
6969
DirectoryInfo dir = Create(dirName);
@@ -219,13 +219,9 @@ public void UnixPathLongerThan256_Allowed()
219219
{
220220
DirectoryInfo testDir = Create(GetTestFilePath());
221221
PathInfo path = IOServices.GetPath(testDir.FullName, 257, IOInputs.MaxComponent);
222-
Assert.All(path.SubPaths, (subpath) =>
223-
{
224-
DirectoryInfo result = Create(subpath);
225-
226-
Assert.Equal(subpath, result.FullName);
227-
Assert.True(Directory.Exists(result.FullName));
228-
});
222+
DirectoryInfo result = Create(path.FullPath);
223+
Assert.Equal(path.FullPath, result.FullName);
224+
Assert.True(Directory.Exists(result.FullName));
229225
}
230226

231227
[Fact]
@@ -234,10 +230,7 @@ public void UnixPathLongerThan256_Throws()
234230
{
235231
DirectoryInfo testDir = Create(GetTestFilePath());
236232
PathInfo path = IOServices.GetPath(testDir.FullName, 257, IOInputs.MaxComponent);
237-
Assert.All(path.SubPaths, (subpath) =>
238-
{
239-
Assert.Throws<PathTooLongException>(() => Create(subpath));
240-
});
233+
Assert.Throws<PathTooLongException>(() => Create(path.FullPath));
241234
}
242235

243236
[Fact]
@@ -301,7 +294,7 @@ public void UnixNonSignificantTrailingWhiteSpace()
301294

302295
[Fact]
303296
[PlatformSpecific(PlatformID.Windows)] // alternate data streams
304-
public void PathWithAlternativeDataStreams_ThrowsNotSupportedException()
297+
public void PathWithAlternateDataStreams_ThrowsNotSupportedException()
305298
{
306299
var paths = IOInputs.GetPathsWithAlternativeDataStreams();
307300
Assert.All(paths, (path) =>
@@ -311,7 +304,6 @@ public void PathWithAlternativeDataStreams_ThrowsNotSupportedException()
311304
}
312305

313306
[Fact]
314-
[OuterLoop]
315307
[PlatformSpecific(PlatformID.Windows)] // device name prefixes
316308
public void PathWithReservedDeviceNameAsPath_ThrowsDirectoryNotFoundException()
317309
{ // Throws DirectoryNotFoundException, when the behavior really should be an invalid path

src/System.IO.FileSystem/tests/Directory/Delete.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ public virtual void Delete(string path)
1919
#region UniversalTests
2020

2121
[Fact]
22-
public void ShouldBeAbleToDeleteHiddenDirectory()
22+
public void NullParameters()
2323
{
24-
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
25-
testDir.Attributes = FileAttributes.Hidden;
26-
Delete(testDir.FullName);
27-
Assert.False(testDir.Exists);
24+
Assert.Throws<ArgumentNullException>(() => Delete(null));
25+
}
26+
27+
[Fact]
28+
public void InvalidParameters()
29+
{
30+
Assert.Throws<ArgumentException>(() => Delete(string.Empty));
2831
}
2932

3033
[Fact]
@@ -108,8 +111,28 @@ public void UnixDeleteReadOnlyDirectory()
108111
Assert.False(testDir.Exists);
109112
}
110113

111-
#endregion
114+
[Fact]
115+
[PlatformSpecific(PlatformID.Windows)]
116+
public void WindowsShouldBeAbleToDeleteHiddenDirectory()
117+
{
118+
DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());
119+
testDir.Attributes = FileAttributes.Hidden;
120+
Delete(testDir.FullName);
121+
Assert.False(testDir.Exists);
122+
}
112123

124+
[Fact]
125+
[PlatformSpecific(PlatformID.AnyUnix)]
126+
public void UnixShouldBeAbleToDeleteHiddenDirectory()
127+
{
128+
string testDir = "." + GetTestFileName();
129+
Directory.CreateDirectory(Path.Combine(TestDirectory, testDir));
130+
Assert.True(0 != (new DirectoryInfo(Path.Combine(TestDirectory, testDir)).Attributes & FileAttributes.Hidden));
131+
Delete(Path.Combine(TestDirectory, testDir));
132+
Assert.False(Directory.Exists(testDir));
133+
}
134+
135+
#endregion
113136
}
114137

115138
public class Directory_Delete_str_bool : Directory_Delete_str

src/System.IO.FileSystem/tests/Directory/Exists.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,21 @@ public void DotDotAsPath_ReturnsTrue()
100100
Assert.True(Exists(Path.Combine(TestDirectory, GetTestFileName(), "..")));
101101
}
102102

103-
#if !TEST_WINRT // WinRT cannot access root
104-
/*
105103
[Fact]
106-
[ActiveIssue(1220)] // SetCurrentDirectory
107-
public void DotDotAsPath_WhenCurrentDirectoryIsRoot_ReturnsTrue()
104+
public void DirectoryLongerThanMaxPathAsPath_DoesntThrow()
108105
{
109-
string root = Path.GetPathRoot(Directory.GetCurrentDirectory());
110-
111-
using (CurrentDirectoryContext context = new CurrentDirectoryContext(root))
106+
Assert.All((IOInputs.GetPathsLongerThanMaxPath()), (path) =>
112107
{
113-
bool result = Exists("..");
114-
115-
Assert.True(result);
116-
}
108+
Assert.False(Exists(path), path);
109+
});
117110
}
118-
*/
119-
#endif
111+
112+
#endregion
113+
114+
#region PlatformSpecific
120115

121116
[Fact]
117+
[PlatformSpecific(PlatformID.Windows)]
122118
public void DirectoryLongerThanMaxDirectoryAsPath_DoesntThrow()
123119
{
124120
Assert.All((IOInputs.GetPathsLongerThanMaxDirectory()), (path) =>
@@ -127,19 +123,6 @@ public void DirectoryLongerThanMaxDirectoryAsPath_DoesntThrow()
127123
});
128124
}
129125

130-
[Fact]
131-
public void DirectoryLongerThanMaxPathAsPath_DoesntThrow()
132-
{
133-
Assert.All((IOInputs.GetPathsLongerThanMaxPath()), (path) =>
134-
{
135-
Assert.False(Exists(path), path);
136-
});
137-
}
138-
139-
#endregion
140-
141-
#region PlatformSpecific
142-
143126
[Fact]
144127
[PlatformSpecific(PlatformID.Windows)] // Unix equivalent tested already in CreateDirectory
145128
public void WindowsNonSignificantWhiteSpaceAsPath_ReturnsFalse()
@@ -184,7 +167,7 @@ public void TrimTrailingWhitespacePath()
184167

185168
[Fact]
186169
[PlatformSpecific(PlatformID.Windows)] // alternate data stream
187-
public void PathWithAlternativeDataStreams_ReturnsFalse()
170+
public void PathWithAlternateDataStreams_ReturnsFalse()
188171
{
189172
Assert.All((IOInputs.GetPathsWithAlternativeDataStreams()), (component) =>
190173
{

src/System.IO.FileSystem/tests/Directory/GetSetTimes.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Directory_GetSetTimes : FileSystemTest
1414

1515
public IEnumerable<Tuple<SetTime, GetTime, DateTimeKind>> TimeFunctions()
1616
{
17-
if (Interop.IsWindows | Interop.IsOSX)
17+
if (IOInputs.SupportsCreationTime)
1818
{
1919
yield return Tuple.Create<SetTime, GetTime, DateTimeKind>(
2020
((path, time) => Directory.SetCreationTime(path, time)),
@@ -80,18 +80,16 @@ public void SettingUpdatesProperties()
8080
public void CreationSetsAllTimes()
8181
{
8282
string path = GetTestFilePath();
83-
long beforeTime = DateTime.Now.AddSeconds(-3).Ticks;
84-
long utcBeforeTime = DateTime.UtcNow.AddSeconds(-3).Ticks;
83+
long beforeTime = DateTime.UtcNow.AddSeconds(-3).Ticks;
8584

8685
DirectoryInfo testDirectory = new DirectoryInfo(GetTestFilePath());
8786
testDirectory.Create();
8887

89-
long afterTime = DateTime.Now.AddSeconds(3).Ticks;
90-
long utcAfterTime = DateTime.UtcNow.AddSeconds(3).Ticks;
88+
long afterTime = DateTime.UtcNow.AddSeconds(3).Ticks;
9189

9290
Assert.All(TimeFunctions(), (tuple) =>
9391
{
94-
Assert.InRange(tuple.Item2(testDirectory.FullName).Ticks, tuple.Item3 == DateTimeKind.Local ? beforeTime : utcBeforeTime, tuple.Item3 == DateTimeKind.Local ? afterTime : utcAfterTime);
92+
Assert.InRange(tuple.Item2(testDirectory.FullName).ToUniversalTime().Ticks, beforeTime, afterTime);
9593
});
9694
}
9795

@@ -107,7 +105,7 @@ public void DirectoryDoesntExist_ReturnDefaultValues()
107105
Assert.Equal(DateTime.FromFileTime(0).Ticks, new DirectoryInfo(path).LastAccessTime.Ticks);
108106
Assert.Equal(DateTime.FromFileTime(0).Ticks, Directory.GetLastWriteTime(path).Ticks);
109107
Assert.Equal(DateTime.FromFileTime(0).Ticks, new DirectoryInfo(path).LastWriteTime.Ticks);
110-
if (Interop.IsWindows | Interop.IsOSX)
108+
if (IOInputs.SupportsCreationTime)
111109
{
112110
Assert.Equal(DateTime.FromFileTime(0).Ticks, Directory.GetCreationTime(path).Ticks);
113111
Assert.Equal(DateTime.FromFileTime(0).Ticks, new DirectoryInfo(path).CreationTime.Ticks);
@@ -118,11 +116,41 @@ public void DirectoryDoesntExist_ReturnDefaultValues()
118116
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, new DirectoryInfo(path).LastAccessTimeUtc.Ticks);
119117
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, Directory.GetLastWriteTimeUtc(path).Ticks);
120118
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, new DirectoryInfo(path).LastWriteTimeUtc.Ticks);
121-
if (Interop.IsWindows | Interop.IsOSX)
119+
if (IOInputs.SupportsCreationTime)
122120
{
123121
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, Directory.GetCreationTimeUtc(path).Ticks);
124122
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, new DirectoryInfo(path).CreationTimeUtc.Ticks);
125123
}
126124
}
125+
126+
[OuterLoop]
127+
[Fact]
128+
[PlatformSpecific(PlatformID.AnyUnix)]
129+
public void UnixDirectoryDoesntExist_Throws()
130+
{
131+
string path = GetTestFilePath();
132+
133+
//non-utc
134+
Assert.Throws<FileNotFoundException>(() => Directory.GetLastAccessTime(path));
135+
Assert.Throws<DirectoryNotFoundException>(() => new DirectoryInfo(path).LastAccessTime);
136+
Assert.Throws<FileNotFoundException>(() => Directory.GetLastWriteTime(path));
137+
Assert.Throws<DirectoryNotFoundException>(() => new DirectoryInfo(path).LastWriteTime);
138+
if (IOInputs.SupportsCreationTime)
139+
{
140+
Assert.Throws<FileNotFoundException>(() => Directory.GetCreationTime(path));
141+
Assert.Throws<DirectoryNotFoundException>(() => new DirectoryInfo(path).CreationTime);
142+
}
143+
144+
//utc
145+
Assert.Throws<FileNotFoundException>(() => Directory.GetLastAccessTimeUtc(path));
146+
Assert.Throws<DirectoryNotFoundException>(() => new DirectoryInfo(path).LastAccessTimeUtc);
147+
Assert.Throws<FileNotFoundException>(() => Directory.GetLastWriteTimeUtc(path));
148+
Assert.Throws<DirectoryNotFoundException>(() => new DirectoryInfo(path).LastWriteTimeUtc);
149+
if (IOInputs.SupportsCreationTime)
150+
{
151+
Assert.Throws<FileNotFoundException>(() => Directory.GetCreationTimeUtc(path));
152+
Assert.Throws<DirectoryNotFoundException>(() => new DirectoryInfo(path).CreationTimeUtc);
153+
}
154+
}
127155
}
128156
}

src/System.IO.FileSystem/tests/DirectoryInfo/GetSetTimes.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DirectoryInfo_GetSetTimes : FileSystemTest
1414

1515
public IEnumerable<Tuple<SetTime, GetTime, DateTimeKind>> TimeFunctions()
1616
{
17-
if (Interop.IsWindows | Interop.IsOSX)
17+
if (IOInputs.SupportsCreationTime)
1818
{
1919
yield return Tuple.Create<SetTime, GetTime, DateTimeKind>(
2020
((testDir, time) => {testDir.CreationTime = time; }),
@@ -60,18 +60,16 @@ public void SettingUpdatesProperties()
6060
public void CreationSetsAllTimes()
6161
{
6262
string path = GetTestFilePath();
63-
long beforeTime = DateTime.Now.AddSeconds(-3).Ticks;
64-
long utcBeforeTime = DateTime.UtcNow.AddSeconds(-3).Ticks;
63+
long beforeTime = DateTime.UtcNow.AddSeconds(-3).Ticks;
6564

6665
DirectoryInfo testDirectory = new DirectoryInfo(GetTestFilePath());
6766
testDirectory.Create();
6867

69-
long afterTime = DateTime.Now.AddSeconds(3).Ticks;
70-
long utcAfterTime = DateTime.UtcNow.AddSeconds(3).Ticks;
68+
long afterTime = DateTime.UtcNow.AddSeconds(3).Ticks;
7169

7270
Assert.All(TimeFunctions(), (tuple) =>
7371
{
74-
Assert.InRange(tuple.Item2(testDirectory).Ticks, tuple.Item3 == DateTimeKind.Local ? beforeTime : utcBeforeTime, tuple.Item3 == DateTimeKind.Local ? afterTime : utcAfterTime);
72+
Assert.InRange(tuple.Item2(testDirectory).ToUniversalTime().Ticks, beforeTime, afterTime);
7573
});
7674
}
7775
}

src/System.IO.FileSystem/tests/File/GetSetTimes.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class File_GetSetTimes : FileSystemTest
1414

1515
public IEnumerable<Tuple<SetTime, GetTime, DateTimeKind>> TimeFunctions()
1616
{
17-
if (Interop.IsWindows | Interop.IsOSX)
17+
if (IOInputs.SupportsCreationTime)
1818
{
1919
yield return Tuple.Create<SetTime, GetTime, DateTimeKind>(
2020
((path, time) => File.SetCreationTime(path, time)),
@@ -81,18 +81,16 @@ public void SettingUpdatesProperties()
8181
public void CreationSetsAllTimes()
8282
{
8383
string path = GetTestFilePath();
84-
long beforeTime = DateTime.Now.AddSeconds(-3).Ticks;
85-
long utcBeforeTime = DateTime.UtcNow.AddSeconds(-3).Ticks;
84+
long beforeTime = DateTime.UtcNow.AddSeconds(-3).Ticks;
8685

8786
FileInfo testFile = new FileInfo(GetTestFilePath());
8887
testFile.Create().Dispose();
8988

90-
long afterTime = DateTime.Now.AddSeconds(3).Ticks;
91-
long utcAfterTime = DateTime.UtcNow.AddSeconds(3).Ticks;
89+
long afterTime = DateTime.UtcNow.AddSeconds(3).Ticks;
9290

9391
Assert.All(TimeFunctions(), (tuple) =>
9492
{
95-
Assert.InRange(tuple.Item2(testFile.FullName).Ticks, tuple.Item3 == DateTimeKind.Local ? beforeTime : utcBeforeTime, tuple.Item3 == DateTimeKind.Local ? afterTime : utcAfterTime);
93+
Assert.InRange(tuple.Item2(testFile.FullName).ToUniversalTime().Ticks, beforeTime, afterTime);
9694
});
9795
}
9896

@@ -108,7 +106,7 @@ public void FileDoesntExist_ReturnDefaultValues()
108106
Assert.Equal(DateTime.FromFileTime(0).Ticks, new FileInfo(path).LastAccessTime.Ticks);
109107
Assert.Equal(DateTime.FromFileTime(0).Ticks, File.GetLastWriteTime(path).Ticks);
110108
Assert.Equal(DateTime.FromFileTime(0).Ticks, new FileInfo(path).LastWriteTime.Ticks);
111-
if (Interop.IsWindows | Interop.IsOSX)
109+
if (IOInputs.SupportsCreationTime)
112110
{
113111
Assert.Equal(DateTime.FromFileTime(0).Ticks, File.GetCreationTime(path).Ticks);
114112
Assert.Equal(DateTime.FromFileTime(0).Ticks, new FileInfo(path).CreationTime.Ticks);
@@ -119,11 +117,41 @@ public void FileDoesntExist_ReturnDefaultValues()
119117
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, new FileInfo(path).LastAccessTimeUtc.Ticks);
120118
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, File.GetLastWriteTimeUtc(path).Ticks);
121119
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, new FileInfo(path).LastWriteTimeUtc.Ticks);
122-
if (Interop.IsWindows | Interop.IsOSX)
120+
if (IOInputs.SupportsCreationTime)
123121
{
124122
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, File.GetCreationTimeUtc(path).Ticks);
125123
Assert.Equal(DateTime.FromFileTimeUtc(0).Ticks, new FileInfo(path).CreationTimeUtc.Ticks);
126124
}
127125
}
126+
127+
[OuterLoop]
128+
[Fact]
129+
[PlatformSpecific(PlatformID.AnyUnix)]
130+
public void UnixFileDoesntExist_Throws()
131+
{
132+
string path = GetTestFilePath();
133+
134+
//non-utc
135+
Assert.Throws<FileNotFoundException>(() => File.GetLastAccessTime(path));
136+
Assert.Throws<FileNotFoundException>(() => new FileInfo(path).LastAccessTime);
137+
Assert.Throws<FileNotFoundException>(() => File.GetLastWriteTime(path));
138+
Assert.Throws<FileNotFoundException>(() => new FileInfo(path).LastWriteTime);
139+
if (IOInputs.SupportsCreationTime)
140+
{
141+
Assert.Throws<FileNotFoundException>(() => File.GetCreationTime(path));
142+
Assert.Throws<FileNotFoundException>(() => new FileInfo(path).CreationTime);
143+
}
144+
145+
//utc
146+
Assert.Throws<FileNotFoundException>(() => File.GetLastAccessTimeUtc(path));
147+
Assert.Throws<FileNotFoundException>(() => new FileInfo(path).LastAccessTimeUtc);
148+
Assert.Throws<FileNotFoundException>(() => File.GetLastWriteTimeUtc(path));
149+
Assert.Throws<FileNotFoundException>(() => new FileInfo(path).LastWriteTimeUtc);
150+
if (IOInputs.SupportsCreationTime)
151+
{
152+
Assert.Throws<FileNotFoundException>(() => File.GetCreationTimeUtc(path));
153+
Assert.Throws<FileNotFoundException>(() => new FileInfo(path).CreationTimeUtc);
154+
}
155+
}
128156
}
129157
}

src/System.IO.FileSystem/tests/FileInfo/GetSetTimes.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class FileInfo_GetSetTimes : FileSystemTest
1414

1515
public IEnumerable<Tuple<SetTime, GetTime, DateTimeKind>> TimeFunctions()
1616
{
17-
if (Interop.IsWindows | Interop.IsOSX)
17+
if (IOInputs.SupportsCreationTime)
1818
{
1919
yield return Tuple.Create<SetTime, GetTime, DateTimeKind>(
2020
((testFile, time) => { testFile.CreationTime = time; }),
@@ -61,18 +61,16 @@ public void SettingUpdatesProperties()
6161
public void CreationSetsAllTimes()
6262
{
6363
string path = GetTestFilePath();
64-
long beforeTime = DateTime.Now.AddSeconds(-3).Ticks;
65-
long utcBeforeTime = DateTime.UtcNow.AddSeconds(-3).Ticks;
64+
long beforeTime = DateTime.UtcNow.AddSeconds(-3).Ticks;
6665

6766
FileInfo testFile = new FileInfo(GetTestFilePath());
6867
testFile.Create().Dispose();
6968

70-
long afterTime = DateTime.Now.AddSeconds(3).Ticks;
71-
long utcAfterTime = DateTime.UtcNow.AddSeconds(3).Ticks;
69+
long afterTime = DateTime.UtcNow.AddSeconds(3).Ticks;
7270

7371
Assert.All(TimeFunctions(), (tuple) =>
7472
{
75-
Assert.InRange(tuple.Item2(testFile).Ticks, tuple.Item3 == DateTimeKind.Local ? beforeTime : utcBeforeTime, tuple.Item3 == DateTimeKind.Local ? afterTime : utcAfterTime);
73+
Assert.InRange(tuple.Item2(testFile).ToUniversalTime().Ticks, beforeTime, afterTime);
7674
});
7775
}
7876
}

0 commit comments

Comments
 (0)