forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllGetSetAttributes.cs
More file actions
80 lines (68 loc) · 3.17 KB
/
AllGetSetAttributes.cs
File metadata and controls
80 lines (68 loc) · 3.17 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
namespace System.IO.Tests
{
// Tests that are valid for File, FileInfo, and DirectoryInfo
public abstract class AllGetSetAttributes : BaseGetSetAttributes
{
[Fact]
public void NullParameters()
{
Assert.Throws<ArgumentNullException>(() => GetAttributes(null));
Assert.Throws<ArgumentNullException>(() => SetAttributes(null, FileAttributes.Normal));
}
[Fact]
public void InvalidParameters()
{
Assert.Throws<ArgumentException>(() => GetAttributes(string.Empty));
Assert.Throws<ArgumentException>(() => SetAttributes(string.Empty, FileAttributes.Normal));
}
[Theory, MemberData(nameof(TrailingCharacters))]
public void SetAttributes_MissingFile(char trailingChar)
{
if (!CanBeReadOnly) return;
Assert.Throws<FileNotFoundException>(() => SetAttributes(GetTestFilePath() + trailingChar, FileAttributes.ReadOnly));
}
[Theory, MemberData(nameof(TrailingCharacters))]
public void SetAttributes_MissingDirectory(char trailingChar)
{
if (!CanBeReadOnly) return;
Assert.Throws<DirectoryNotFoundException>(() => SetAttributes(Path.Combine(GetTestFilePath(), "file" + trailingChar), FileAttributes.ReadOnly));
}
[ConditionalFact(typeof(MountHelper), nameof(MountHelper.CanCreateSymbolicLinks))]
public void SymLinksAreReparsePoints()
{
string path = CreateItem();
string linkPath = GetRandomLinkPath();
Assert.True(MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: IsDirectory));
Assert.NotEqual(FileAttributes.ReparsePoint, FileAttributes.ReparsePoint & GetAttributes(path));
Assert.Equal(FileAttributes.ReparsePoint, FileAttributes.ReparsePoint & GetAttributes(linkPath));
}
[ConditionalFact(typeof(MountHelper), nameof(MountHelper.CanCreateSymbolicLinks))]
public void SymLinksReflectSymLinkAttributes()
{
string path = CreateItem();
string linkPath = GetRandomLinkPath();
Assert.True(MountHelper.CreateSymbolicLink(linkPath, path, isDirectory: IsDirectory));
SetAttributes(path, FileAttributes.ReadOnly);
try
{
Assert.Equal(FileAttributes.ReadOnly, FileAttributes.ReadOnly & GetAttributes(path));
if (OperatingSystem.IsWindows())
{
Assert.NotEqual(FileAttributes.ReadOnly, FileAttributes.ReadOnly & GetAttributes(linkPath));
}
else
{
// On Unix, Get/SetAttributes FileAttributes.ReadOnly operates on the target of the link.
Assert.Equal(FileAttributes.ReadOnly, FileAttributes.ReadOnly & GetAttributes(linkPath));
}
}
finally
{
SetAttributes(path, GetAttributes(path) & ~FileAttributes.ReadOnly);
}
}
}
}