forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertPatchTest.cs
More file actions
180 lines (151 loc) · 7.24 KB
/
Copy pathInsertPatchTest.cs
File metadata and controls
180 lines (151 loc) · 7.24 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
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using NSubstitute;
using TestUtils;
using ModuleManager;
using ModuleManager.Logging;
using ModuleManager.Patches;
using ModuleManager.Patches.PassSpecifiers;
using ModuleManager.Progress;
namespace ModuleManagerTests.Patches
{
public class InsertPatchTest
{
[Fact]
public void TestConstructor__UrlConfigNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new InsertPatch(null, "A_NODE", Substitute.For<IPassSpecifier>());
});
Assert.Equal("urlConfig", ex.ParamName);
}
[Fact]
public void TestConstructor__NodeTypeNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), null, Substitute.For<IPassSpecifier>());
});
Assert.Equal("nodeType", ex.ParamName);
}
[Fact]
public void TestConstructor__PassSpecifierNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", null);
});
Assert.Equal("passSpecifier", ex.ParamName);
}
[Fact]
public void TestUrlConfig()
{
UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode());
InsertPatch patch = new InsertPatch(urlConfig, "A_NODE", Substitute.For<IPassSpecifier>());
Assert.Same(urlConfig, patch.UrlConfig);
}
[Fact]
public void TestNodeType()
{
InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", Substitute.For<IPassSpecifier>());
Assert.Equal("A_NODE", patch.NodeType);
}
[Fact]
public void TestPassSpecifier()
{
IPassSpecifier passSpecifier = Substitute.For<IPassSpecifier>();
InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", passSpecifier);
Assert.Same(passSpecifier, patch.PassSpecifier);
}
[Fact]
public void TestCountsAsPatch()
{
InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", Substitute.For<IPassSpecifier>());
Assert.False(patch.CountsAsPatch);
}
[Fact]
public void TestApply()
{
UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new TestConfigNode("A_NODE:NEEDS[someMod]:FOR[somePass]")
{
{ "key1", "value1" },
{ "key2", "value2" },
new TestConfigNode("NODE_1")
{
{ "key3", "value3" },
},
new TestConfigNode("NODE_2")
{
{ "key4", "value4" },
},
});
InsertPatch patch = new InsertPatch(urlConfig, "A_NODE", Substitute.For<IPassSpecifier>());
LinkedList<IProtoUrlConfig> databaseConfigs = new LinkedList<IProtoUrlConfig>();
IProtoUrlConfig config1 = Substitute.For<IProtoUrlConfig>();
IProtoUrlConfig config2 = Substitute.For<IProtoUrlConfig>();
databaseConfigs.AddLast(config1);
databaseConfigs.AddLast(config2);
patch.Apply(databaseConfigs, Substitute.For<IPatchProgress>(), Substitute.For<IBasicLogger>());
IProtoUrlConfig[] databaseConfigsArray = databaseConfigs.ToArray();
Assert.Equal(3, databaseConfigsArray.Length);
Assert.Same(config1, databaseConfigsArray[0]);
Assert.Same(config2, databaseConfigsArray[1]);
Assert.Same(urlConfig.parent, databaseConfigsArray[2].UrlFile);
Assert.Equal("abc/def.cfg", databaseConfigsArray[2].FileUrl);
Assert.Equal("A_NODE", databaseConfigsArray[2].NodeType);
Assert.Equal("abc/def.cfg/A_NODE", databaseConfigsArray[2].FullUrl);
Assert.NotSame(urlConfig.config, databaseConfigsArray[2].Node);
Assert.Equal("A_NODE", databaseConfigsArray[2].Node.name);
Assert.Equal("A_NODE:NEEDS[someMod]:FOR[somePass]", urlConfig.config.name); // make sure this hasn't been changed
Assert.Equal(2, databaseConfigsArray[2].Node.values.Count);
Assert.Equal("key1", databaseConfigsArray[2].Node.values[0].name);
Assert.Equal("value1", databaseConfigsArray[2].Node.values[0].value);
Assert.Equal("key2", databaseConfigsArray[2].Node.values[1].name);
Assert.Equal("value2", databaseConfigsArray[2].Node.values[1].value);
Assert.Equal(2, databaseConfigsArray[2].Node.nodes.Count);
Assert.Equal("NODE_1", databaseConfigsArray[2].Node.nodes[0].name);
Assert.Equal(1, databaseConfigsArray[2].Node.nodes[0].values.Count);
Assert.Equal("key3", databaseConfigsArray[2].Node.nodes[0].values[0].name);
Assert.Equal("value3", databaseConfigsArray[2].Node.nodes[0].values[0].value);
Assert.Equal(0, databaseConfigsArray[2].Node.nodes[0].nodes.Count);
Assert.Equal("NODE_2", databaseConfigsArray[2].Node.nodes[1].name);
Assert.Equal(1, databaseConfigsArray[2].Node.nodes[1].values.Count);
Assert.Equal("key4", databaseConfigsArray[2].Node.nodes[1].values[0].name);
Assert.Equal("value4", databaseConfigsArray[2].Node.nodes[1].values[0].value);
Assert.Equal(0, databaseConfigsArray[2].Node.nodes[1].nodes.Count);
}
[Fact]
public void TestApply__DatabaseConfigsNull()
{
InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", Substitute.For<IPassSpecifier>());
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
patch.Apply(null, Substitute.For<IPatchProgress>(), Substitute.For<IBasicLogger>());
});
Assert.Equal("configs", ex.ParamName);
}
[Fact]
public void TestApply__ProgressNull()
{
InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", Substitute.For<IPassSpecifier>());
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
patch.Apply(new LinkedList<IProtoUrlConfig>(), null, Substitute.For<IBasicLogger>());
});
Assert.Equal("progress", ex.ParamName);
}
[Fact]
public void TestApply__LoggerNull()
{
InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", Substitute.For<IPassSpecifier>());
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
patch.Apply(new LinkedList<IProtoUrlConfig>(), Substitute.For<IPatchProgress>(), null);
});
Assert.Equal("logger", ex.ParamName);
}
}
}