forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetSetAttributes.cs
More file actions
84 lines (70 loc) · 3.19 KB
/
Copy pathGetSetAttributes.cs
File metadata and controls
84 lines (70 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Win32.SafeHandles;
using Xunit;
namespace System.IO.Tests
{
public class File_GetSetAttributes : BaseGetSetAttributes
{
protected override FileAttributes GetAttributes(string path) => File.GetAttributes(path);
protected FileAttributes GetAttributes(SafeFileHandle fileHandle) => File.GetAttributes(fileHandle);
protected override void SetAttributes(string path, FileAttributes attributes) => File.SetAttributes(path, attributes);
protected void SetAttributes(SafeFileHandle fileHandle, FileAttributes attributes) => File.SetAttributes(fileHandle, attributes);
// Getting only throws for File, not FileInfo
[Theory, MemberData(nameof(TrailingCharacters))]
public void GetAttributes_MissingFile(char trailingChar)
{
Assert.Throws<FileNotFoundException>(() => GetAttributes(GetTestFilePath() + trailingChar));
}
[Theory, MemberData(nameof(TrailingCharacters))]
[PlatformSpecific(TestPlatforms.Windows)]
public void GetAttributes_MissingFile_SafeFileHandle(char trailingChar)
{
Assert.Throws<FileNotFoundException>(() =>
{
using var fileHandle = File.OpenHandle(GetTestFilePath() + trailingChar);
GetAttributes(fileHandle);
});
}
// Getting only throws for File, not FileInfo
[Theory,
InlineData(":bar"),
InlineData(":bar:$DATA")]
[PlatformSpecific(TestPlatforms.Windows)]
public void GetAttributes_MissingAlternateDataStream_Windows(string streamName)
{
string path = CreateItem();
streamName = path + streamName;
Assert.Throws<FileNotFoundException>(() => GetAttributes(streamName));
}
[Theory,
InlineData(":bar"),
InlineData(":bar:$DATA")]
[PlatformSpecific(TestPlatforms.Windows)]
public void GetAttributes_MissingAlternateDataStream_Windows_SafeFileHandle(string streamName)
{
string path = CreateItem();
streamName = path + streamName;
Assert.Throws<FileNotFoundException>(() =>
{
using var fileHandle = File.OpenHandle(streamName);
GetAttributes(fileHandle);
});
}
[Theory, MemberData(nameof(TrailingCharacters))]
public void GetAttributes_MissingDirectory(char trailingChar)
{
Assert.Throws<DirectoryNotFoundException>(() => GetAttributes(Path.Combine(GetTestFilePath(), "dir" + trailingChar)));
}
[Theory, MemberData(nameof(TrailingCharacters))]
[PlatformSpecific(TestPlatforms.Windows)]
public void GetAttributes_MissingDirectory_SafeFileHandle(char trailingChar)
{
Assert.Throws<DirectoryNotFoundException>(() =>
{
using var fileHandle = File.OpenHandle(Path.Combine(GetTestFilePath(), "dir" + trailingChar), access: FileAccess.ReadWrite);
GetAttributes(fileHandle);
});
}
}
}