/
FileSystemResolverTests.cs
126 lines (112 loc) · 5.01 KB
/
FileSystemResolverTests.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;
using SquishIt.Framework.Resolvers;
namespace SquishIt.Tests
{
[TestFixture]
public class FileSystemResolverTests
{
[Test, Platform(Exclude = "Unix, Linux, Mono")]
public void CanResolveFile()
{
//dealing with working directory on a non-C location
var currentDirectory = Environment.CurrentDirectory;
var driveLetter = currentDirectory.Substring(0, currentDirectory.IndexOf("\\"));//ignoring UNC paths
//resharper doesn't support the TestCase attribute
var values = new Dictionary<string, string>
{
{@"C:\testfile.js", @"C:\testfile.js"},
{@"C:\test\testfile.js", @"C:\test\testfile.js"},
{@"D:\testfile.js", @"D:\testfile.js"},
{@"\testfile.js", driveLetter + @"\testfile.js"},
{@"\test\testfile.js", driveLetter + @"\test\testfile.js"},
{@"\test\test3\testfile.js", driveLetter + @"\test\test3\testfile.js"},
{@"testfile.js", Environment.CurrentDirectory + @"\testfile.js"},
{@"..\testfile.js", Path.GetFullPath(Environment.CurrentDirectory + @"\..\testfile.js")},
{@"..\..\testfile.js", Path.GetFullPath(Environment.CurrentDirectory + @"\..\..\testfile.js")}
};
var fileResolver = new FileSystemResolver();
foreach (string key in values.Keys)
{
var resolvedFile = fileResolver.TryResolve(key);
Assert.AreEqual(values[key], resolvedFile, key);
}
}
[Test, Platform(Include = "Unix, Linux, Mono")]
public void CanResolveFile_Unix()
{
var currentDirectory = Environment.CurrentDirectory;
var values = new Dictionary<string, string>
{
{@"testfile.js", Path.Combine(currentDirectory, "testfile.js")},
{@"/testfile.js", @"/testfile.js"},
{@"../testfile.js", Path.Combine(currentDirectory.Substring(0, currentDirectory.LastIndexOf("/")), "testfile.js")}
};
var fileResolver = new FileSystemResolver();
foreach (string key in values.Keys)
{
var resolvedFile = fileResolver.TryResolve(key);
Assert.AreEqual(values[key], resolvedFile, key);
}
}
[Test]
public void CanResolveDirectory()
{
string path = Guid.NewGuid().ToString();
var directory = Directory.CreateDirectory(path);
try
{
File.Create(Path.Combine(directory.FullName, "file1")).Close();
File.Create(Path.Combine(directory.FullName, "file2")).Close();
var result = new FileSystemResolver().TryResolveFolder(path, true, null).ToList();
Assert.AreEqual(2, result.Count);
Assert.Contains(path + Path.DirectorySeparatorChar + "file1", result);
Assert.Contains(path + Path.DirectorySeparatorChar + "file2", result);
}
finally
{
Directory.Delete(path, true);
}
}
[Test]
public void CanResolveDirectory_Filters_Files_By_Extension()
{
var path = Guid.NewGuid().ToString();
var directory = Directory.CreateDirectory(path);
try
{
File.Create(Path.Combine(directory.FullName, "file1.js")).Close();
File.Create(Path.Combine(directory.FullName, "file2.css")).Close();
File.Create(Path.Combine(directory.FullName, "file21.JS")).Close();
var result = new FileSystemResolver().TryResolveFolder(path, true, new[] { ".js" }).ToList();
Assert.AreEqual(2, result.Count);
Assert.Contains(path + Path.DirectorySeparatorChar + "file1.js", result);
Assert.Contains(path + Path.DirectorySeparatorChar + "file21.JS", result);
}
finally
{
Directory.Delete(path, true);
}
}
[Test]
public void IsDirectory()
{
var path = Guid.NewGuid().ToString();
var directory = Directory.CreateDirectory(path);
File.Create(Path.Combine(directory.FullName, "file")).Close();
try
{
var resolver = new FileSystemResolver();
Assert.IsTrue(resolver.IsDirectory(path));
Assert.IsFalse(resolver.IsDirectory(Path.Combine(path, "file")));
}
finally
{
Directory.Delete(path, true);
}
}
}
}