|
1 | 1 | using NUnit.Framework; |
| 2 | +using System.Collections.Generic; |
2 | 3 |
|
3 | 4 | namespace System.IO.Abstractions.Extensions.Tests |
4 | 5 | { |
@@ -30,6 +31,59 @@ public void SubDirectory_Extension_Test() |
30 | 31 | Assert.IsFalse(fs.Directory.Exists(expectedPath)); |
31 | 32 | } |
32 | 33 |
|
| 34 | + [TestCase("test1", "test2")] |
| 35 | + [TestCase("test1", "", "test2")] |
| 36 | + [TestCase("test1", null, "test2")] |
| 37 | + public void SubDirectoryWithParams_Extension_Test(params string[] subFolders) |
| 38 | + { |
| 39 | + //arrange |
| 40 | + var fs = new FileSystem(); |
| 41 | + var current = fs.DirectoryInfo.New(fs.Directory.GetCurrentDirectory()); |
| 42 | + var expectedPath = fs.Path.Combine(current.FullName, "test1", "test2"); |
| 43 | + |
| 44 | + //make sure directory doesn't exists |
| 45 | + Assert.IsFalse(fs.Directory.Exists(expectedPath)); |
| 46 | + |
| 47 | + //create directory |
| 48 | + var created = current.SubDirectory(subFolders); |
| 49 | + created.Create(); |
| 50 | + |
| 51 | + //assert it exists |
| 52 | + Assert.IsTrue(fs.Directory.Exists(expectedPath)); |
| 53 | + Assert.AreEqual(expectedPath, created.FullName); |
| 54 | + |
| 55 | + //delete directory |
| 56 | + created.Delete(); |
| 57 | + Assert.IsFalse(fs.Directory.Exists(expectedPath)); |
| 58 | + } |
| 59 | + |
| 60 | + [TestCase("test1", "test2")] |
| 61 | + [TestCase("test1", "", "test2")] |
| 62 | + [TestCase("test1", null, "test2")] |
| 63 | + public void SubDirectoryWithIEnumerable_Extension_Test(params string[] names) |
| 64 | + { |
| 65 | + //arrange |
| 66 | + var fs = new FileSystem(); |
| 67 | + var current = fs.DirectoryInfo.New(fs.Directory.GetCurrentDirectory()); |
| 68 | + var expectedPath = fs.Path.Combine(current.FullName, "test1", "test2"); |
| 69 | + |
| 70 | + //make sure directory doesn't exists |
| 71 | + Assert.IsFalse(fs.Directory.Exists(expectedPath)); |
| 72 | + |
| 73 | + //create directory |
| 74 | + var list = new List<string>(names); |
| 75 | + var created = current.SubDirectory(list); |
| 76 | + created.Create(); |
| 77 | + |
| 78 | + //assert it exists |
| 79 | + Assert.IsTrue(fs.Directory.Exists(expectedPath)); |
| 80 | + Assert.AreEqual(expectedPath, created.FullName); |
| 81 | + |
| 82 | + //delete directory |
| 83 | + created.Delete(); |
| 84 | + Assert.IsFalse(fs.Directory.Exists(expectedPath)); |
| 85 | + } |
| 86 | + |
33 | 87 | [Test] |
34 | 88 | public void File_Extension_Test() |
35 | 89 | { |
@@ -58,6 +112,38 @@ public void File_Extension_Test() |
58 | 112 | Assert.IsFalse(fs.File.Exists(expectedPath)); |
59 | 113 | } |
60 | 114 |
|
| 115 | + [TestCase("test1", "test2", "test.txt")] |
| 116 | + [TestCase("test1", "", "test2", "test.txt")] |
| 117 | + [TestCase("test1", null, "test2", "test.txt")] |
| 118 | + |
| 119 | + public void FileWithParams_Extension_Test(params string[] names) |
| 120 | + { |
| 121 | + //arrange |
| 122 | + var fs = new FileSystem(); |
| 123 | + var current = fs.DirectoryInfo.New(fs.Directory.GetCurrentDirectory()); |
| 124 | + var expectedPath = fs.Path.Combine(current.FullName, "test1", "test2", "test.txt"); |
| 125 | + |
| 126 | + //make sure file doesn't exists |
| 127 | + Assert.IsFalse(fs.File.Exists(expectedPath)); |
| 128 | + |
| 129 | + //act, create file |
| 130 | + var created = current.File(names); |
| 131 | + created.Directory.Create(); |
| 132 | + using (var stream = created.Create()) |
| 133 | + { |
| 134 | + stream.Dispose(); |
| 135 | + } |
| 136 | + |
| 137 | + //assert it exists |
| 138 | + Assert.IsTrue(fs.File.Exists(expectedPath)); |
| 139 | + Assert.AreEqual(expectedPath, created.FullName); |
| 140 | + |
| 141 | + //delete file |
| 142 | + created.Delete(); |
| 143 | + created.Directory.Delete(); |
| 144 | + Assert.IsFalse(fs.File.Exists(expectedPath)); |
| 145 | + } |
| 146 | + |
61 | 147 | [Test] |
62 | 148 | public void ThrowIfNotFound_IfDirectoryDoesNotExists_ThrowsException() |
63 | 149 | { |
|
0 commit comments