Repository navigation
Expand file tree
/
Copy pathMockFileSetAccessControlTests.cs
More file actions
67 lines (56 loc) · 2.2 KB
/
Copy pathMockFileSetAccessControlTests.cs
File metadata and controls
67 lines (56 loc) · 2.2 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
using NUnit.Framework;
using System.Collections.Generic;
using System.Runtime.Versioning;
using System.Security.AccessControl;
using XFS = System.IO.Abstractions.TestingHelpers.MockUnixSupport;
namespace System.IO.Abstractions.TestingHelpers.Tests;
[TestFixture]
[WindowsOnly(WindowsSpecifics.AccessControlLists)]
[SupportedOSPlatform("windows")]
public class MockFileSetAccessControlTests
{
[TestCase(" ")]
[TestCase(" ")]
public async Task MockFile_SetAccessControl_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path)
{
// Arrange
var fileSystem = new MockFileSystem();
var fileSecurity = new FileSecurity();
// Act
Action action = () => fileSystem.File.SetAccessControl(path, fileSecurity);
// Assert
var exception = await That(action).Throws<ArgumentException>();
await That(exception.ParamName).IsEqualTo("path");
}
[Test]
public async Task MockFile_SetAccessControl_ShouldThrowFileNotFoundExceptionIfFileDoesNotExistInMockData()
{
// Arrange
var fileSystem = new MockFileSystem();
var expectedFileName = XFS.Path(@"c:\a.txt");
var fileSecurity = new FileSecurity();
// Act
Action action = () => fileSystem.File.SetAccessControl(expectedFileName, fileSecurity);
// Assert
var exception = await That(action).Throws<FileNotFoundException>();
await That(exception.FileName).IsEqualTo(expectedFileName);
}
[Test]
public async Task MockFile_SetAccessControl_ShouldSetAccessControlOfFileData()
{
// Arrange
var filePath = XFS.Path(@"c:\a.txt");
var fileData = new MockFileData("Test content");
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>()
{
{ filePath, fileData }
});
// Act
var expectedAccessControl = new FileSecurity();
expectedAccessControl.SetAccessRuleProtection(false, false);
fileSystem.File.SetAccessControl(filePath, expectedAccessControl);
// Assert
var accessControl = fileSystem.File.GetAccessControl(filePath);
await That(accessControl).IsEqualTo(expectedAccessControl);
}
}