-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCombineTests.cs
389 lines (332 loc) · 14.3 KB
/
CombineTests.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
namespace Testably.Abstractions.Tests.FileSystem.Path;
// ReSharper disable once PartialTypeWithSinglePart
public abstract partial class CombineTests<TFileSystem>
: FileSystemTestBase<TFileSystem>
where TFileSystem : IFileSystem
{
[SkippableTheory]
[AutoData]
public void Combine_2Paths_OneEmpty_ShouldReturnCombinationOfOtherParts(
string path)
{
string result1 = FileSystem.Path.Combine(path, string.Empty);
string result2 = FileSystem.Path.Combine(string.Empty, path);
result1.Should().Be(path);
result2.Should().Be(path);
}
[SkippableTheory]
[AutoData]
public void Combine_2Paths_OneNull_ShouldThrowArgumentNullException(string path)
{
Exception? exception1 = Record.Exception(() =>
FileSystem.Path.Combine(path, null!));
Exception? exception2 = Record.Exception(() =>
FileSystem.Path.Combine(null!, path));
exception1.Should()
.BeException<ArgumentNullException>(paramName: "path2", hResult: -2147467261);
exception2.Should()
.BeException<ArgumentNullException>(paramName: "path1", hResult: -2147467261);
}
[SkippableTheory]
[AutoData]
public void Combine_2Paths_Rooted_ShouldReturnLastRootedPath(
string path1, string path2)
{
path1 = FileSystem.Path.DirectorySeparatorChar + path1;
path2 = FileSystem.Path.DirectorySeparatorChar + path2;
string result = FileSystem.Path.Combine(path1, path2);
result.Should().Be(path2);
}
[SkippableTheory]
[InlineAutoData("/foo/", "/bar/", "/bar/")]
[InlineAutoData("foo/", "/bar", "/bar")]
[InlineAutoData("foo/", "bar", "foo/bar")]
[InlineAutoData("foo", "/bar", "/bar")]
[InlineAutoData("foo", "bar", "foo/bar")]
[InlineAutoData("/foo", "bar/", "/foo/bar/")]
public void Combine_2Paths_ShouldReturnExpectedResult(
string path1, string path2, string expectedResult)
{
path1 = path1.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path2 = path2.Replace('/', FileSystem.Path.DirectorySeparatorChar);
expectedResult = expectedResult.Replace('/', FileSystem.Path.DirectorySeparatorChar);
string result = FileSystem.Path.Combine(path1, path2);
result.Should().Be(expectedResult);
}
[SkippableTheory]
[InlineAutoData]
[InlineAutoData(" ")]
[InlineAutoData("foo", " ")]
public void Combine_2Paths_ShouldReturnPathsCombinedByDirectorySeparatorChar(
string path1, string path2)
{
string expectedPath = path1
+ FileSystem.Path.DirectorySeparatorChar + path2;
string result = FileSystem.Path.Combine(path1, path2);
result.Should().Be(expectedPath);
}
[SkippableTheory]
[AutoData]
public void Combine_3Paths_OneEmpty_ShouldReturnCombinationOfOtherParts(
string pathA, string pathB)
{
string expectedPath = FileSystem.Path.Combine(pathA, pathB);
string result1 = FileSystem.Path.Combine(string.Empty, pathA, pathB);
string result2 = FileSystem.Path.Combine(pathA, string.Empty, pathB);
string result3 = FileSystem.Path.Combine(pathA, pathB, string.Empty);
result1.Should().Be(expectedPath);
result2.Should().Be(expectedPath);
result3.Should().Be(expectedPath);
}
[SkippableTheory]
[AutoData]
public void Combine_3Paths_OneNull_ShouldThrowArgumentNullException(string pathA, string pathB)
{
Exception? exception1 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, pathB, null!));
Exception? exception2 = Record.Exception(() =>
FileSystem.Path.Combine(null!, pathA, pathB));
Exception? exception3 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, null!, pathB));
exception1.Should()
.BeException<ArgumentNullException>(paramName: "path3", hResult: -2147467261);
exception2.Should()
.BeException<ArgumentNullException>(paramName: "path1", hResult: -2147467261);
exception3.Should()
.BeException<ArgumentNullException>(paramName: "path2", hResult: -2147467261);
}
[SkippableTheory]
[AutoData]
public void Combine_3Paths_Rooted_ShouldReturnLastRootedPath(
string path1, string path2, string path3)
{
path1 = FileSystem.Path.DirectorySeparatorChar + path1;
path2 = FileSystem.Path.DirectorySeparatorChar + path2;
path3 = FileSystem.Path.DirectorySeparatorChar + path3;
string result = FileSystem.Path.Combine(path1, path2, path3);
result.Should().Be(path3);
}
[SkippableTheory]
[InlineAutoData("/foo/", "/bar/", "/baz/", "/baz/")]
[InlineAutoData("foo/", "/bar/", "/baz", "/baz")]
[InlineAutoData("foo/", "bar", "/baz", "/baz")]
[InlineAutoData("foo", "/bar", "/baz", "/baz")]
[InlineAutoData("foo", "/bar/", "baz", "/bar/baz")]
[InlineAutoData("foo", "bar", "baz", "foo/bar/baz")]
[InlineAutoData("/foo", "bar", "baz/", "/foo/bar/baz/")]
public void Combine_3Paths_ShouldReturnExpectedResult(
string path1, string path2, string path3, string expectedResult)
{
path1 = path1.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path2 = path2.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path3 = path3.Replace('/', FileSystem.Path.DirectorySeparatorChar);
expectedResult = expectedResult.Replace('/', FileSystem.Path.DirectorySeparatorChar);
string result = FileSystem.Path.Combine(path1, path2, path3);
result.Should().Be(expectedResult);
}
[SkippableTheory]
[InlineAutoData]
[InlineAutoData(" ")]
[InlineAutoData("foo", " ")]
[InlineAutoData("foo", "bar", " ")]
public void Combine_3Paths_ShouldReturnPathsCombinedByDirectorySeparatorChar(
string path1, string path2, string path3)
{
string expectedPath = path1
+ FileSystem.Path.DirectorySeparatorChar + path2
+ FileSystem.Path.DirectorySeparatorChar + path3;
string result = FileSystem.Path.Combine(path1, path2, path3);
result.Should().Be(expectedPath);
}
[SkippableTheory]
[AutoData]
public void Combine_4Paths_OneEmpty_ShouldReturnCombinationOfOtherParts(
string pathA, string pathB, string pathC)
{
string expectedPath = FileSystem.Path.Combine(pathA, pathB, pathC);
string result1 = FileSystem.Path.Combine(string.Empty, pathA, pathB, pathC);
string result2 = FileSystem.Path.Combine(pathA, string.Empty, pathB, pathC);
string result3 = FileSystem.Path.Combine(pathA, pathB, string.Empty, pathC);
string result4 = FileSystem.Path.Combine(pathA, pathB, pathC, string.Empty);
result1.Should().Be(expectedPath);
result2.Should().Be(expectedPath);
result3.Should().Be(expectedPath);
result4.Should().Be(expectedPath);
}
[SkippableTheory]
[AutoData]
public void Combine_4Paths_OneNull_ShouldThrowArgumentNullException(string pathA, string pathB,
string pathC)
{
Exception? exception1 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, pathB, pathC, null!));
Exception? exception2 = Record.Exception(() =>
FileSystem.Path.Combine(null!, pathA, pathB, pathC));
Exception? exception3 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, null!, pathB, pathC));
Exception? exception4 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, pathB, null!, pathC));
exception1.Should()
.BeException<ArgumentNullException>(paramName: "path4", hResult: -2147467261);
exception2.Should()
.BeException<ArgumentNullException>(paramName: "path1", hResult: -2147467261);
exception3.Should()
.BeException<ArgumentNullException>(paramName: "path2", hResult: -2147467261);
exception4.Should()
.BeException<ArgumentNullException>(paramName: "path3", hResult: -2147467261);
}
[SkippableTheory]
[AutoData]
public void Combine_4Paths_Rooted_ShouldReturnLastRootedPath(
string path1, string path2, string path3, string path4)
{
path1 = FileSystem.Path.DirectorySeparatorChar + path1;
path2 = FileSystem.Path.DirectorySeparatorChar + path2;
path3 = FileSystem.Path.DirectorySeparatorChar + path3;
path4 = FileSystem.Path.DirectorySeparatorChar + path4;
string result = FileSystem.Path.Combine(path1, path2, path3, path4);
result.Should().Be(path4);
}
[SkippableTheory]
[InlineAutoData("/foo/", "/bar/", "/baz/", "/muh/", "/muh/")]
[InlineAutoData("foo/", "/bar/", "/baz/", "/muh", "/muh")]
[InlineAutoData("foo/", "bar", "/baz", "/muh", "/muh")]
[InlineAutoData("foo", "/bar", "/baz", "/muh", "/muh")]
[InlineAutoData("foo", "/bar/", "baz/", "muh", "/bar/baz/muh")]
[InlineAutoData("foo", "bar", "baz", "muh", "foo/bar/baz/muh")]
[InlineAutoData("/foo", "bar", "baz", "muh/", "/foo/bar/baz/muh/")]
public void Combine_4Paths_ShouldReturnExpectedResult(
string path1, string path2, string path3, string path4, string expectedResult)
{
path1 = path1.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path2 = path2.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path3 = path3.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path4 = path4.Replace('/', FileSystem.Path.DirectorySeparatorChar);
expectedResult = expectedResult.Replace('/', FileSystem.Path.DirectorySeparatorChar);
string result = FileSystem.Path.Combine(path1, path2, path3, path4);
result.Should().Be(expectedResult);
}
[SkippableTheory]
[InlineAutoData]
[InlineAutoData(" ")]
[InlineAutoData("foo", " ")]
[InlineAutoData("foo", "bar", " ")]
[InlineAutoData("foo", "bar", "baz", " ")]
public void Combine_4Paths_ShouldReturnPathsCombinedByDirectorySeparatorChar(
string path1, string path2, string path3, string path4)
{
string expectedPath = path1
+ FileSystem.Path.DirectorySeparatorChar + path2
+ FileSystem.Path.DirectorySeparatorChar + path3
+ FileSystem.Path.DirectorySeparatorChar + path4;
string result = FileSystem.Path.Combine(path1, path2, path3, path4);
result.Should().Be(expectedPath);
}
[SkippableFact]
public void Combine_ParamPaths_Null_ShouldThrowArgumentNullException()
{
Exception? exception = Record.Exception(() =>
FileSystem.Path.Combine(null!));
exception.Should()
.BeException<ArgumentNullException>(paramName: "paths", hResult: -2147467261);
}
[SkippableTheory]
[AutoData]
public void Combine_ParamPaths_OneEmpty_ShouldReturnCombinationOfOtherParts(
string path1, string path2, string path3, string path4)
{
string expectedPath = FileSystem.Path.Combine(path1, path2, path3, path4);
string result1 =
FileSystem.Path.Combine(string.Empty, path1, path2, path3, path4);
string result2 =
FileSystem.Path.Combine(path1, string.Empty, path2, path3, path4);
string result3 =
FileSystem.Path.Combine(path1, path2, string.Empty, path3, path4);
string result4 =
FileSystem.Path.Combine(path1, path2, path3, string.Empty, path4);
string result5 =
FileSystem.Path.Combine(path1, path2, path3, path4, string.Empty);
result1.Should().Be(expectedPath);
result2.Should().Be(expectedPath);
result3.Should().Be(expectedPath);
result4.Should().Be(expectedPath);
result5.Should().Be(expectedPath);
}
[SkippableTheory]
[AutoData]
public void Combine_ParamPaths_OneNull_ShouldThrowArgumentNullException(
string pathA, string pathB, string pathC, string pathD)
{
Exception? exception1 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, pathB, pathC, pathD, null!));
Exception? exception2 = Record.Exception(() =>
FileSystem.Path.Combine(null!, pathA, pathB, pathC, pathD));
Exception? exception3 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, null!, pathB, pathC, pathD));
Exception? exception4 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, pathB, null!, pathC, pathD));
Exception? exception5 = Record.Exception(() =>
FileSystem.Path.Combine(pathA, pathB, pathC, null!, pathD));
exception1.Should()
.BeException<ArgumentNullException>(paramName: "paths", hResult: -2147467261);
exception2.Should()
.BeException<ArgumentNullException>(paramName: "paths", hResult: -2147467261);
exception3.Should()
.BeException<ArgumentNullException>(paramName: "paths", hResult: -2147467261);
exception4.Should()
.BeException<ArgumentNullException>(paramName: "paths", hResult: -2147467261);
exception5.Should()
.BeException<ArgumentNullException>(paramName: "paths", hResult: -2147467261);
}
[SkippableTheory]
[AutoData]
public void Combine_ParamPaths_Rooted_ShouldReturnLastRootedPath(
string path1, string path2, string path3, string path4, string path5)
{
path1 = FileSystem.Path.DirectorySeparatorChar + path1;
path2 = FileSystem.Path.DirectorySeparatorChar + path2;
path3 = FileSystem.Path.DirectorySeparatorChar + path3;
path4 = FileSystem.Path.DirectorySeparatorChar + path4;
path5 = FileSystem.Path.DirectorySeparatorChar + path5;
string result = FileSystem.Path.Combine(path1, path2, path3, path4, path5);
result.Should().Be(path5);
}
[SkippableTheory]
[InlineAutoData("/foo/", "/bar/", "/baz/", "/muh/", "/maeh/", "/maeh/")]
[InlineAutoData("foo/", "/bar/", "/baz/", "/muh", "/maeh", "/maeh")]
[InlineAutoData("foo/", "bar", "/baz", "/muh", "/maeh", "/maeh")]
[InlineAutoData("foo", "/bar", "/baz", "/muh", "/maeh", "/maeh")]
[InlineAutoData("foo", "/bar/", "baz/", "muh/", "maeh", "/bar/baz/muh/maeh")]
[InlineAutoData("foo", "bar", "baz", "muh", "maeh", "foo/bar/baz/muh/maeh")]
[InlineAutoData("/foo", "bar", "baz", "muh", "maeh/", "/foo/bar/baz/muh/maeh/")]
public void Combine_ParamPaths_ShouldReturnExpectedResult(
string path1, string path2, string path3, string path4, string path5, string expectedResult)
{
path1 = path1.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path2 = path2.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path3 = path3.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path4 = path4.Replace('/', FileSystem.Path.DirectorySeparatorChar);
path5 = path5.Replace('/', FileSystem.Path.DirectorySeparatorChar);
expectedResult = expectedResult.Replace('/', FileSystem.Path.DirectorySeparatorChar);
string result = FileSystem.Path.Combine(path1, path2, path3, path4, path5);
result.Should().Be(expectedResult);
}
[SkippableTheory]
[InlineAutoData]
[InlineAutoData(" ")]
[InlineAutoData("foo", " ")]
[InlineAutoData("foo", "bar", " ")]
[InlineAutoData("foo", "bar", "baz", " ")]
[InlineAutoData("foo", "bar", "baz", "muh", " ")]
public void Combine_ParamPaths_ShouldReturnPathsCombinedByDirectorySeparatorChar(
string path1, string path2, string path3, string path4, string path5)
{
string expectedPath = path1
+ FileSystem.Path.DirectorySeparatorChar + path2
+ FileSystem.Path.DirectorySeparatorChar + path3
+ FileSystem.Path.DirectorySeparatorChar + path4
+ FileSystem.Path.DirectorySeparatorChar + path5;
string result = FileSystem.Path.Combine(path1, path2, path3, path4, path5);
result.Should().Be(expectedPath);
}
}