forked from KSP-ModularManagement/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatchListTest.cs
More file actions
217 lines (182 loc) · 9.06 KB
/
Copy pathPatchListTest.cs
File metadata and controls
217 lines (182 loc) · 9.06 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using NSubstitute;
using TestUtils;
using ModuleManager;
using ModuleManager.Patches;
using ModuleManager.Patches.PassSpecifiers;
using ModuleManager.Progress;
namespace ModuleManagerTests
{
public class PatchListTest
{
[Fact]
public void TestConstructor__ModListNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new PatchList(null, new IPatch[0], Substitute.For<IPatchProgress>());
});
Assert.Equal("modList", ex.ParamName);
}
[Fact]
public void TestConstructor__PatchesNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new PatchList(new string[0], null, Substitute.For<IPatchProgress>());
});
Assert.Equal("patches", ex.ParamName);
}
[Fact]
public void TestConstructor__ProgressNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new PatchList(new string[0], new IPatch[0], null);
});
Assert.Equal("progress", ex.ParamName);
}
[Fact]
public void TestConstructor__UnknownMod()
{
IPatch patch = Substitute.For<IPatch>();
UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode("NODE"));
patch.PassSpecifier.Returns(new BeforePassSpecifier("mod3", urlConfig));
IPatchProgress progress = Substitute.For<IPatchProgress>();
KeyNotFoundException ex = Assert.Throws<KeyNotFoundException>(delegate
{
new PatchList(new[] { "mod1", "mod2" }, new[] { patch }, progress);
});
Assert.Equal("Mod 'mod3' not found", ex.Message);
progress.DidNotReceive().PatchAdded();
}
[Fact]
public void TestConstructor__UnknownPassSpecifier()
{
IPatch patch = Substitute.For<IPatch>();
UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode("NODE"));
IPassSpecifier passSpecifier = Substitute.For<IPassSpecifier>();
passSpecifier.Descriptor.Returns(":SOMEPASS");
patch.PassSpecifier.Returns(passSpecifier);
IPatchProgress progress = Substitute.For<IPatchProgress>();
NotImplementedException ex = Assert.Throws<NotImplementedException>(delegate
{
new PatchList(new string[0], new[] { patch }, progress);
});
Assert.Equal("Don't know what to do with pass specifier: :SOMEPASS", ex.Message);
progress.DidNotReceive().PatchAdded();
}
[Fact]
public void Test__Lifecycle()
{
IPatch[] patches = new IPatch[]
{
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
};
UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode("NODE"));
patches[00].PassSpecifier.Returns(new InsertPassSpecifier());
patches[01].PassSpecifier.Returns(new InsertPassSpecifier());
patches[02].PassSpecifier.Returns(new FirstPassSpecifier());
patches[03].PassSpecifier.Returns(new FirstPassSpecifier());
patches[04].PassSpecifier.Returns(new LegacyPassSpecifier());
patches[05].PassSpecifier.Returns(new LegacyPassSpecifier());
patches[06].PassSpecifier.Returns(new BeforePassSpecifier("mod1", urlConfig));
patches[07].PassSpecifier.Returns(new BeforePassSpecifier("MOD1", urlConfig));
patches[08].PassSpecifier.Returns(new ForPassSpecifier("mod1", urlConfig));
patches[09].PassSpecifier.Returns(new ForPassSpecifier("MOD1", urlConfig));
patches[10].PassSpecifier.Returns(new AfterPassSpecifier("mod1", urlConfig));
patches[11].PassSpecifier.Returns(new AfterPassSpecifier("MOD1", urlConfig));
patches[12].PassSpecifier.Returns(new LastPassSpecifier("mod1"));
patches[13].PassSpecifier.Returns(new LastPassSpecifier("MOD1"));
patches[14].PassSpecifier.Returns(new BeforePassSpecifier("mod2", urlConfig));
patches[15].PassSpecifier.Returns(new BeforePassSpecifier("MOD2", urlConfig));
patches[16].PassSpecifier.Returns(new ForPassSpecifier("mod2", urlConfig));
patches[17].PassSpecifier.Returns(new ForPassSpecifier("MOD2", urlConfig));
patches[18].PassSpecifier.Returns(new AfterPassSpecifier("mod2", urlConfig));
patches[19].PassSpecifier.Returns(new AfterPassSpecifier("MOD2", urlConfig));
patches[20].PassSpecifier.Returns(new LastPassSpecifier("mod2"));
patches[21].PassSpecifier.Returns(new LastPassSpecifier("MOD2"));
patches[22].PassSpecifier.Returns(new FinalPassSpecifier());
patches[23].PassSpecifier.Returns(new FinalPassSpecifier());
patches[00].CountsAsPatch.Returns(false);
patches[01].CountsAsPatch.Returns(false);
patches[02].CountsAsPatch.Returns(true);
patches[03].CountsAsPatch.Returns(true);
patches[04].CountsAsPatch.Returns(true);
patches[05].CountsAsPatch.Returns(true);
patches[06].CountsAsPatch.Returns(true);
patches[07].CountsAsPatch.Returns(true);
patches[08].CountsAsPatch.Returns(true);
patches[09].CountsAsPatch.Returns(true);
patches[10].CountsAsPatch.Returns(true);
patches[11].CountsAsPatch.Returns(true);
patches[12].CountsAsPatch.Returns(true);
patches[13].CountsAsPatch.Returns(true);
patches[14].CountsAsPatch.Returns(true);
patches[15].CountsAsPatch.Returns(true);
patches[16].CountsAsPatch.Returns(true);
patches[17].CountsAsPatch.Returns(true);
patches[18].CountsAsPatch.Returns(true);
patches[19].CountsAsPatch.Returns(true);
patches[20].CountsAsPatch.Returns(true);
patches[21].CountsAsPatch.Returns(true);
patches[22].CountsAsPatch.Returns(true);
patches[23].CountsAsPatch.Returns(true);
IPatchProgress progress = Substitute.For<IPatchProgress>();
PatchList patchList = new PatchList(new[] { "mod1", "mod2" }, patches, progress);
IPass[] passes = patchList.ToArray();
Assert.Equal(12, passes.Length);
Assert.Equal(":INSERT (initial)", passes[0].Name);
Assert.Equal(new[] { patches[0], patches[1] }, passes[0]);
Assert.Equal(":FIRST", passes[1].Name);
Assert.Equal(new[] { patches[2], patches[3] }, passes[1]);
Assert.Equal(":LEGACY (default)", passes[2].Name);
Assert.Equal(new[] { patches[4], patches[5] }, passes[2]);
Assert.Equal(":BEFORE[MOD1]", passes[3].Name);
Assert.Equal(new[] { patches[6], patches[7] }, passes[3]);
Assert.Equal(":FOR[MOD1]", passes[4].Name);
Assert.Equal(new[] { patches[8], patches[9] }, passes[4]);
Assert.Equal(":AFTER[MOD1]", passes[5].Name);
Assert.Equal(new[] { patches[10], patches[11] }, passes[5]);
Assert.Equal(":BEFORE[MOD2]", passes[6].Name);
Assert.Equal(new[] { patches[14], patches[15] }, passes[6]);
Assert.Equal(":FOR[MOD2]", passes[7].Name);
Assert.Equal(new[] { patches[16], patches[17] }, passes[7]);
Assert.Equal(":AFTER[MOD2]", passes[8].Name);
Assert.Equal(new[] { patches[18], patches[19] }, passes[8]);
Assert.Equal(":LAST[MOD1]", passes[9].Name);
Assert.Equal(new[] { patches[12], patches[13] }, passes[9]);
Assert.Equal(":LAST[MOD2]", passes[10].Name);
Assert.Equal(new[] { patches[20], patches[21] }, passes[10]);
Assert.Equal(":FINAL", passes[11].Name);
Assert.Equal(new[] { patches[22], patches[23] }, passes[11]);
progress.Received(22).PatchAdded();
}
}
}