/
Tests.cs
205 lines (165 loc) · 5.55 KB
/
Tests.cs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using System;
using System.IO;
using NoFake.IO.Extensions;
using NUnit.Framework;
namespace NoFake.IO.Tests
{
/// <summary>
/// Main test class shows library functional
/// </summary>
public class Tests
{
#region Directory
[Test]
public void TestEmptyFolderPathConstructor()
{
using (var dir = DirectoryFactory.New(String.Empty))
{
var directoryPath = dir.FullPath;
Assert.That(Directory.Exists(directoryPath), Is.True);
}
using (var dir = DirectoryFactory.New())
{
var directoryPath = dir.FullPath;
Assert.That(Directory.Exists(directoryPath), Is.True);
}
}
[Test]
public void TestEnsureDirectoryDeleted()
{
String path;
using (var dir = DirectoryFactory.New())
{
path = dir.FullPath;
}
Assert.That(Directory.Exists(path), Is.False);
}
[Test]
public void TestOneLevelFolder()
{
var path = "folder";
using (var dir = DirectoryFactory.New(path))
{
var directoryPath = dir.FullPath;
Assert.That(Directory.Exists(directoryPath), Is.True);
Assert.That(directoryPath.EndsWith(path), Is.True);
}
}
[Test]
public void TestTwoLevelFolder()
{
var path = @"folder1\folder2";
using (var dir = DirectoryFactory.New(path))
{
var directoryPath = dir.FullPath;
Assert.That(Directory.Exists(directoryPath), Is.True);
Assert.That(directoryPath.EndsWith(path), Is.True);
}
}
[Test]
public void TestThirdLevelFolder()
{
var path = @"folder1\Folder2\folder3";
using (var dir = DirectoryFactory.New(path))
{
var directoryPath = dir.FullPath;
Assert.That(Directory.Exists(directoryPath), Is.True);
Assert.That(directoryPath.EndsWith(path), Is.True);
}
}
[Test]
public void TestFolderPathWithRoot()
{
var path = "folder";
var root = @"C:\";
var fullPath = root + path;
using (var dir = DirectoryFactory.New(fullPath))
{
var directoryPath = dir.FullPath;
Assert.That(Directory.Exists(directoryPath), Is.True);
Assert.That(directoryPath.EndsWith(path), Is.True);
Assert.That(directoryPath.Contains(fullPath), Is.False);
}
}
[Test]
[Ignore("NetworkPath not supported")]
public void TestNetWorkPath()
{
var networkPath = @"\\127.0.0.1\Folder";
var endPath = "Folder";
using (var dir = DirectoryFactory.New(networkPath))
{
var directoryPath = dir.FullPath;
Assert.That(Directory.Exists(directoryPath), Is.True);
Assert.That(directoryPath.EndsWith(endPath), Is.True);
Assert.That(directoryPath.Contains(networkPath), Is.False);
}
}
[Test]
public void TestFtpPath()
{
var ftpPath = @"ftp://127.0.0.1/Folder";
var endPath = "Folder";
using (var dir = DirectoryFactory.New(ftpPath))
{
var directoryPath = dir.FullPath;
Assert.That(Directory.Exists(directoryPath), Is.True);
Assert.That(directoryPath.EndsWith(endPath), Is.True);
Assert.That(directoryPath.Contains(ftpPath), Is.False);
}
}
public void TestAddFolder2Folder()
{
var folderName = @"folderChild";
using (var d = DirectoryFactory.New())
{
d.Add<NDirectory>(folderName);
Assert.That(Directory.Exists(Path.Combine(d.FullPath, folderName)));
}
//Or, factory Syntax
using (var d = DirectoryFactory.New())
{
var subFolder = DirectoryFactory.Add(d, folderName);
Assert.That(Directory.Exists(subFolder.FullPath));
}
}
#endregion
#region File
[Test]
public void TestFileConstructor()
{
var fileName = @"1.file";
using (var file = FileFactory.New(fileName))
{
Assert.That(File.Exists(file.FullPath));
}
}
[Test]
public void TestFileWithFolder()
{
var fullPath = @"folder\1.file";
using (var file = FileFactory.New(fullPath))
{
Assert.That(File.Exists(file.FullPath));
Assert.That(file.FullPath.Contains(fullPath), Is.True);
}
}
[Test]
public void TestAddFileToFolder()
{
const string fileName = @"1.file";
using (var d = DirectoryFactory.New())
{
var file = d.Add<NFile>(fileName);
Assert.That(File.Exists(Path.Combine(d.FullPath, fileName)));
}
//Or, with Factory syntax
using (var d = DirectoryFactory.New())
{
var file = FileFactory.Add(d, fileName);
Assert.That(File.Exists(file.FullPath));
}
}
#endregion
}
}