forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInGameTestRunnerTest.cs
More file actions
188 lines (156 loc) · 5.8 KB
/
Copy pathInGameTestRunnerTest.cs
File metadata and controls
188 lines (156 loc) · 5.8 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
using System;
using System.Linq;
using Xunit;
using NSubstitute;
using UnityEngine;
using TestUtils;
using ModuleManager;
using ModuleManager.Logging;
namespace ModuleManagerTests
{
public class InGameTestRunnerTest
{
private readonly IBasicLogger logger;
private readonly UrlDir databaseRoot;
private readonly InGameTestRunner testRunner;
public InGameTestRunnerTest()
{
logger = Substitute.For<IBasicLogger>();
databaseRoot = UrlBuilder.CreateRoot();
testRunner = new InGameTestRunner(logger);
}
[Fact]
public void TestConstructor__LoggerNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new InGameTestRunner(null);
});
Assert.Equal("logger", ex.ParamName);
}
[Fact]
public void TestRunTestCases__DatabaseRootNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
testRunner.RunTestCases(null);
});
Assert.Equal("gameDatabaseRoot", ex.ParamName);
}
[Fact]
public void TestRunTestCases__WrongNumberOfNodes()
{
UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/blah1.cfg", databaseRoot);
// Call CreateCopy otherwise XUnit sees that it's an IEnumerable and attempts to compare by enumeration
ConfigNode testNode1 = new TestConfigNode("NODE1")
{
{ "key1", "value1" },
}.CreateCopy();
ConfigNode testNode2 = new ConfigNode("NODE2");
ConfigNode expectNode = new TestConfigNode("MMTEST_EXPECT")
{
new TestConfigNode("NODE1")
{
{ "key1", "value1" },
},
}.CreateCopy();
UrlBuilder.CreateConfig(testNode1, file1);
UrlBuilder.CreateConfig(testNode2, file1);
UrlBuilder.CreateConfig(expectNode, file1);
testRunner.RunTestCases(databaseRoot);
Received.InOrder(delegate
{
logger.AssertInfo("Running tests...");
logger.AssertError($"Test blah1 failed as expected number of nodes differs expected: 1 found: 2");
logger.AssertInfo(testNode1.ToString());
logger.AssertInfo(testNode2.ToString());
logger.AssertInfo(expectNode.ToString());
logger.AssertInfo("tests complete.");
});
Assert.Equal(3, file1.configs.Count);
Assert.Equal(testNode1, file1.configs[0].config);
Assert.Equal(testNode2, file1.configs[1].config);
Assert.Equal(expectNode, file1.configs[2].config);
}
[Fact]
public void TestRunTestCases__AllPassing()
{
UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/blah1.cfg", databaseRoot);
UrlDir.UrlFile file2 = UrlBuilder.CreateFile("abc/blah2.cfg", databaseRoot);
ConfigNode testNode1 = new TestConfigNode("NODE1")
{
{ "key1", "value1" },
{ "key2", "value2" },
new TestConfigNode("NODE2")
{
{ "key3", "value3" },
},
};
ConfigNode testNode2 = new TestConfigNode("NODE3")
{
{ "key4", "value4" },
};
ConfigNode testNode3 = new TestConfigNode("NODE4")
{
{ "key5", "value5" },
};
UrlBuilder.CreateConfig(testNode1, file1);
UrlBuilder.CreateConfig(testNode2, file1);
UrlBuilder.CreateConfig(new TestConfigNode("MMTEST_EXPECT")
{
testNode1.CreateCopy(),
testNode2.CreateCopy(),
}, file1);
UrlBuilder.CreateConfig(testNode3, file2);
UrlBuilder.CreateConfig(new TestConfigNode("MMTEST_EXPECT")
{
testNode3.CreateCopy(),
}, file2);
testRunner.RunTestCases(databaseRoot);
Received.InOrder(delegate
{
logger.AssertInfo("Running tests...");
logger.AssertInfo("tests complete.");
});
logger.AssertNoError();
Assert.Empty(file1.configs);
Assert.Empty(file2.configs);
}
[Fact]
public void TestRunTestCases__Failure()
{
UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/blah1.cfg", databaseRoot);
ConfigNode testNode1 = new TestConfigNode("NODE1")
{
{ "key1", "value1" },
{ "key2", "value2" },
new TestConfigNode("NODE2")
{
{ "key3", "value3" },
},
};
ConfigNode expectNode1 = new TestConfigNode("NODE1")
{
{ "key1", "value1" },
{ "key2", "value2" },
new TestConfigNode("NODE2")
{
{ "key4", "value3" },
},
};
UrlBuilder.CreateConfig(testNode1, file1);
UrlBuilder.CreateConfig(new TestConfigNode("MMTEST_EXPECT")
{
expectNode1,
}, file1);
testRunner.RunTestCases(databaseRoot);
Received.InOrder(delegate
{
logger.AssertInfo("Running tests...");
logger.AssertError($"Test blah1[0] failed as expected output and actual output differ.\nexpected:\n{expectNode1}\nActually got:\n{testNode1}");
logger.AssertInfo("tests complete.");
});
Assert.Empty(file1.configs);
}
}
}