-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProjectLoaderTests.cs
More file actions
116 lines (91 loc) · 2.82 KB
/
ProjectLoaderTests.cs
File metadata and controls
116 lines (91 loc) · 2.82 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
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
namespace RunScript;
[Trait("category", "unit")]
[UsesVerify]
public class ProjectLoaderTests
{
[Fact]
public void Should_throw_if_no_globaljson_found_in_tree()
{
// Given
var projectLoader = new ProjectLoader();
// When
var action = () => projectLoader.LoadAsync(Path.GetTempPath());
// Then
var ex = action.ShouldThrow<RunScriptException>();
ex.Message.ShouldBe("No global.json found in folder path");
}
[Fact]
public void Should_throw_if_malformed_file()
{
// Given
var testPath = TestPath("malformed");
var projectLoader = new ProjectLoader();
// When
var action = () => projectLoader.LoadAsync(testPath);
// Then
var ex = action.ShouldThrow<RunScriptException>();
ex.Message.ShouldBe("Error parsing global.json");
}
[Fact]
public void Should_throw_if_no_scripts_found()
{
// Given
var testPath = TestPath("no-scripts");
var projectLoader = new ProjectLoader();
// When
var action = () => projectLoader.LoadAsync(testPath);
// Then
var ex = action.ShouldThrow<RunScriptException>();
ex.Message.ShouldBe("No scripts found in the global.json");
}
[Fact]
public async Task Should_find_in_root()
{
// Given
var testPath = TestPath("dir1");
var projectLoader = new ProjectLoader();
// When
var (project, workingDirectory) = await projectLoader.LoadAsync(testPath);
// Then
project.ShouldNotBeNull();
await Verify(project);
workingDirectory.ShouldBe(TestPath("dir1"));
}
[Fact]
public async Task Should_look_up_the_tree()
{
// Given
var testPath = TestPath("dir1", "dir2", "dir3");
var projectLoader = new ProjectLoader();
// When
var (project, workingDirectory) = await projectLoader.LoadAsync(testPath);
// Then
project.ShouldNotBeNull();
await Verify(project);
workingDirectory.ShouldBe(TestPath("dir1"));
}
[Fact]
public async Task Should_not_treat_script_names_as_always_lowercase()
{
// Given
var testPath = TestPath("script-names");
var projectLoader = new ProjectLoader();
// When
var (project, _) = await projectLoader.LoadAsync(testPath);
// Then
await Verify(project);
}
private string TestPath(params string[] folders)
{
return Path.Join(segments().ToArray());
IEnumerable<string> segments()
{
yield return AttributeReader.GetProjectDirectory(GetType().Assembly);
yield return "test-configs";
foreach (var folder in folders)
{
yield return folder;
}
}
}
}