-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathMockFileArgumentPathTests.cs
More file actions
74 lines (70 loc) · 3.95 KB
/
MockFileArgumentPathTests.cs
File metadata and controls
74 lines (70 loc) · 3.95 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
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32.SafeHandles;
using NUnit.Framework;
namespace System.IO.Abstractions.TestingHelpers.Tests
{
public class MockFileArgumentPathTests
{
private static IEnumerable<Action<IFile>> GetFileSystemActionsForArgumentNullException()
{
yield return fs => fs.AppendAllLines(null, new[] { "does not matter" });
yield return fs => fs.AppendAllLines(null, new[] { "does not matter" }, Encoding.ASCII);
yield return fs => fs.AppendAllText(null, "does not matter");
yield return fs => fs.AppendAllText(null, "does not matter", Encoding.ASCII);
yield return fs => fs.AppendText(null);
yield return fs => fs.WriteAllBytes(null, new byte[] { 0 });
yield return fs => fs.WriteAllLines(null, new[] { "does not matter" });
yield return fs => fs.WriteAllLines(null, new[] { "does not matter" }, Encoding.ASCII);
yield return fs => fs.WriteAllLines(null, new[] { "does not matter" }.ToArray());
yield return fs => fs.WriteAllLines(null, new[] { "does not matter" }.ToArray(), Encoding.ASCII);
yield return fs => fs.Create(null);
yield return fs => fs.Delete(null);
yield return fs => fs.GetCreationTime((string)null);
yield return fs => fs.GetCreationTimeUtc((string)null);
yield return fs => fs.GetLastAccessTime((string)null);
yield return fs => fs.GetLastAccessTimeUtc((string)null);
yield return fs => fs.GetLastWriteTime((string)null);
yield return fs => fs.GetLastWriteTimeUtc((string)null);
yield return fs => fs.WriteAllText(null, "does not matter");
yield return fs => fs.WriteAllText(null, "does not matter", Encoding.ASCII);
yield return fs => fs.Open(null, FileMode.OpenOrCreate);
yield return fs => fs.Open(null, FileMode.OpenOrCreate, FileAccess.Read);
yield return fs => fs.Open(null, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Inheritable);
yield return fs => fs.OpenRead(null);
yield return fs => fs.OpenText(null);
yield return fs => fs.OpenWrite(null);
yield return fs => fs.ReadAllBytes(null);
yield return fs => fs.ReadAllLines(null);
yield return fs => fs.ReadAllLines(null, Encoding.ASCII);
yield return fs => fs.ReadAllText(null);
yield return fs => fs.ReadAllText(null, Encoding.ASCII);
yield return fs => fs.ReadLines(null);
yield return fs => fs.ReadLines(null, Encoding.ASCII);
yield return fs => fs.SetAttributes((string)null, FileAttributes.Archive);
yield return fs => fs.GetAttributes((string)null);
yield return fs => fs.SetCreationTime((string)null, DateTime.Now);
yield return fs => fs.SetCreationTimeUtc((string)null, DateTime.Now);
yield return fs => fs.SetLastAccessTime((string)null, DateTime.Now);
yield return fs => fs.SetLastAccessTimeUtc((string)null, DateTime.Now);
yield return fs => fs.SetLastWriteTime((string)null, DateTime.Now);
yield return fs => fs.SetLastWriteTimeUtc((string)null, DateTime.Now);
#pragma warning disable CA1416
yield return fs => fs.Decrypt(null);
yield return fs => fs.Encrypt(null);
#pragma warning restore CA1416
}
[TestCaseSource(nameof(GetFileSystemActionsForArgumentNullException))]
public void Operations_ShouldThrowArgumentNullExceptionIfPathIsNull(Action<IFile> action)
{
// Arrange
var fileSystem = new MockFileSystem();
// Act
TestDelegate wrapped = () => action(fileSystem.File);
// Assert
var exception = Assert.Throws<ArgumentNullException>(wrapped);
Assert.That(exception.ParamName, Is.EqualTo("path"));
}
}
}