forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatchApplierTest.cs
More file actions
135 lines (119 loc) · 5.28 KB
/
Copy pathPatchApplierTest.cs
File metadata and controls
135 lines (119 loc) · 5.28 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
using System;
using Xunit;
using NSubstitute;
using UnityEngine;
using TestUtils;
using ModuleManager;
using ModuleManager.Collections;
using ModuleManager.Logging;
using ModuleManager.Patches;
using ModuleManager.Progress;
namespace ModuleManagerTests
{
public class PatchApplierTest
{
[Fact]
public void TestConstructor__ProgressNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new PatchApplier(null, Substitute.For<IBasicLogger>());
});
Assert.Equal("progress", ex.ParamName);
}
[Fact]
public void TestConstructor__LoggerNull()
{
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
new PatchApplier(Substitute.For<IPatchProgress>(), null);
});
Assert.Equal("logger", ex.ParamName);
}
[Fact]
public void TestApplyPatches__UrlFilesNull()
{
PatchApplier applier = new PatchApplier(Substitute.For<IPatchProgress>(), Substitute.For<IBasicLogger>());
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
applier.ApplyPatches(null, new IPass[0]);
});
Assert.Equal("configFiles", ex.ParamName);
}
[Fact]
public void TestApplyPatches__PatchesNull()
{
PatchApplier applier = new PatchApplier(Substitute.For<IPatchProgress>(), Substitute.For<IBasicLogger>());
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate
{
applier.ApplyPatches(new UrlDir.UrlFile[0], null);
});
Assert.Equal("patches", ex.ParamName);
}
[Fact]
public void TestApplyPatches()
{
IBasicLogger logger = Substitute.For<IBasicLogger>();
IPatchProgress progress = Substitute.For<IPatchProgress>();
PatchApplier patchApplier = new PatchApplier(progress, logger);
UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/def.cfg");
UrlDir.UrlFile file2 = UrlBuilder.CreateFile("ghi/jkl.cfg");
IPass pass1 = Substitute.For<IPass>();
IPass pass2 = Substitute.For<IPass>();
IPass pass3 = Substitute.For<IPass>();
pass1.Name.Returns(":PASS1");
pass2.Name.Returns(":PASS2");
pass3.Name.Returns(":PASS3");
UrlDir.UrlConfig[] patchUrlConfigs = new UrlDir.UrlConfig[9];
IPatch[] patches = new IPatch[9];
for (int i = 0; i < patches.Length; i++)
{
patches[i] = Substitute.For<IPatch>();
}
pass1.GetEnumerator().Returns(new ArrayEnumerator<IPatch>(patches[0], patches[1], patches[2]));
pass2.GetEnumerator().Returns(new ArrayEnumerator<IPatch>(patches[3], patches[4], patches[5]));
pass3.GetEnumerator().Returns(new ArrayEnumerator<IPatch>(patches[6], patches[7], patches[8]));
IPass[] patchList = new IPass[] { pass1, pass2, pass3 };
patchApplier.ApplyPatches(new[] { file1, file2 }, new[] { pass1, pass2, pass3 });
progress.DidNotReceiveWithAnyArgs().Error(null, null);
progress.DidNotReceiveWithAnyArgs().Exception(null, null);
progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
logger.DidNotReceive().Log(LogType.Warning, Arg.Any<string>());
logger.DidNotReceive().Log(LogType.Error, Arg.Any<string>());
logger.DidNotReceiveWithAnyArgs().Exception(null, null);
Received.InOrder(delegate
{
logger.Log(LogType.Log, ":PASS1 pass");
patches[0].Apply(file1, progress, logger);
patches[0].Apply(file2, progress, logger);
progress.PatchApplied();
patches[1].Apply(file1, progress, logger);
patches[1].Apply(file2, progress, logger);
progress.PatchApplied();
patches[2].Apply(file1, progress, logger);
patches[2].Apply(file2, progress, logger);
progress.PatchApplied();
logger.Log(LogType.Log, ":PASS2 pass");
patches[3].Apply(file1, progress, logger);
patches[3].Apply(file2, progress, logger);
progress.PatchApplied();
patches[4].Apply(file1, progress, logger);
patches[4].Apply(file2, progress, logger);
progress.PatchApplied();
patches[5].Apply(file1, progress, logger);
patches[5].Apply(file2, progress, logger);
progress.PatchApplied();
logger.Log(LogType.Log, ":PASS3 pass");
patches[6].Apply(file1, progress, logger);
patches[6].Apply(file2, progress, logger);
progress.PatchApplied();
patches[7].Apply(file1, progress, logger);
patches[7].Apply(file2, progress, logger);
progress.PatchApplied();
patches[8].Apply(file1, progress, logger);
patches[8].Apply(file2, progress, logger);
progress.PatchApplied();
});
}
}
}