-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathMockFileSetAttributesTests.cs
More file actions
66 lines (54 loc) · 2.44 KB
/
MockFileSetAttributesTests.cs
File metadata and controls
66 lines (54 loc) · 2.44 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
using System.Collections.Generic;
using NUnit.Framework;
using XFS = System.IO.Abstractions.TestingHelpers.MockUnixSupport;
namespace System.IO.Abstractions.TestingHelpers.Tests
{
[TestFixture]
public class MockFileSetAttributesTests
{
[Test]
public void MockFile_SetAttributes_ShouldSetAttributesOnFile()
{
var path = XFS.Path(@"c:\something\demo.txt");
var filedata = new MockFileData("test");
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{path, filedata},
});
fileSystem.File.SetAttributes(path, FileAttributes.Hidden);
var attributes = fileSystem.File.GetAttributes(path);
Assert.That(attributes, Is.EqualTo(FileAttributes.Hidden));
}
[Test]
public void MockFile_SetAttributes_ShouldSetAttributesOnDirectory()
{
var fileSystem = new MockFileSystem();
var path = XFS.Path(@"c:\something");
fileSystem.AddDirectory(path);
var directoryInfo = fileSystem.DirectoryInfo.New(path);
directoryInfo.Attributes = FileAttributes.Directory | FileAttributes.Normal;
fileSystem.File.SetAttributes(path, FileAttributes.Directory | FileAttributes.Hidden);
var attributes = fileSystem.File.GetAttributes(path);
Assert.That(attributes, Is.EqualTo(FileAttributes.Directory | FileAttributes.Hidden));
}
[Test]
[TestCase("", FileAttributes.Normal)]
[TestCase(" ", FileAttributes.Normal)]
public void MockFile_SetAttributes_ShouldThrowArgumentExceptionIfPathContainsOnlyWhitespaces(string path, FileAttributes attributes)
{
var fileSystem = new MockFileSystem();
TestDelegate action = () => fileSystem.File.SetAttributes(path, attributes);
Assert.Throws<ArgumentException>(action);
}
[Test]
public void MockFile_SetAttributes_ShouldThrowFileNotFoundExceptionIfMissingDirectory()
{
var path = XFS.Path(@"C:\something");
var attributes = FileAttributes.Normal;
var fileSystem = new MockFileSystem();
TestDelegate action = () => fileSystem.File.SetAttributes(path, attributes);
var exception = Assert.Throws<FileNotFoundException>(action);
Assert.That(exception.FileName, Is.EqualTo(path));
}
}
}