forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetSetAttributes_SafeFileHandle.cs
More file actions
39 lines (33 loc) · 1.41 KB
/
GetSetAttributes_SafeFileHandle.cs
File metadata and controls
39 lines (33 loc) · 1.41 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
// 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 GetSetAttributes_SafeFileHandle : FileGetSetAttributes
{
protected virtual SafeFileHandle OpenFileHandle(string path, FileAccess fileAccess) =>
File.OpenHandle(
path,
FileMode.OpenOrCreate,
fileAccess,
FileShare.None);
protected override bool CanBeReadOnly => false;
protected override FileAttributes GetAttributes(string path)
{
using SafeFileHandle fileHandle = OpenFileHandle(path, FileAccess.Read);
return File.GetAttributes(fileHandle);
}
protected override void SetAttributes(string path, FileAttributes attributes)
{
using SafeFileHandle fileHandle = OpenFileHandle(path, FileAccess.ReadWrite);
File.SetAttributes(fileHandle, attributes);
}
[Fact]
public void NullArgumentValidation()
{
Assert.Throws<ArgumentNullException>("fileHandle", static () => File.GetAttributes(default(SafeFileHandle)!));
Assert.Throws<ArgumentNullException>("fileHandle", static () => File.SetAttributes(default(SafeFileHandle)!, (FileAttributes)0));
}
}
}