-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDisposableFileTests.cs
More file actions
40 lines (34 loc) · 1.35 KB
/
DisposableFileTests.cs
File metadata and controls
40 lines (34 loc) · 1.35 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
using NUnit.Framework;
using Assert = NUnit.Framework.Legacy.ClassicAssert;
namespace System.IO.Abstractions.Extensions.Tests
{
[TestFixture]
public class DisposableFileTests
{
[Test]
public void DisposableFile_Throws_ArgumentNullException_For_Null_IFileInfo_Test()
{
Assert.Throws<ArgumentNullException>(() => new DisposableFile(null));
}
[Test]
public void DisposableFile_Delete_On_Dispose_Test()
{
// Arrange
var fs = new FileSystem();
var path = fs.Path.Combine(fs.Directory.GetCurrentDirectory(), fs.Path.GetRandomFileName());
var fileInfo = fs.FileInfo.New(path);
fileInfo.Create().Dispose();
// Assert file exists
Assert.IsTrue(fs.File.Exists(path), "File exists");
Assert.IsTrue(fileInfo.Exists, "IFileInfo.Exists should be true");
// Act
var disposableFile = new DisposableFile(fileInfo);
disposableFile.Dispose();
// Assert directory is deleted
Assert.IsFalse(fs.File.Exists(path), "File does not exist");
Assert.IsFalse(fileInfo.Exists, "IFileInfo.Exists should be false");
// Assert a second dispose does not throw
Assert.DoesNotThrow(() => disposableFile.Dispose());
}
}
}