Skip to content

Commit 0720a12

Browse files
committed
test: add 538 AAA pattern unit tests across 9 modules (Configuration, FileSystem, Event, Pipeline, Download, Security, IPC, GracefulExit, Compress)
- Configuration: 53 tests (Configinfo.Validate, ConfiginfoBuilder Set/Build, ConfigurationMapper, UpdateOption singleton/equals, ProcessInfo constructor validation, Environments AES round-trip) - FileSystem: 45 tests (FileNode Add/Search/SearchParent/Equals/GetHashCode, FileTree DelNode all cases, DefaultBlackListMatcher exact/glob/format/dir matching) - Event: 13 tests (EventManager AddListener/Dispatch/RemoveListener/Clear/fault isolation/singleton) - Pipeline: 15 tests (PipelineContext Add/Get/Remove/ContainsKey edge cases, PipelineBuilder Build/UseMiddlewareIf) - Download: 30 tests (DownloadPlanBuilder 14 branches, DefaultRetryPolicy 9 exception types + exponential backoff) - Security: 11 tests (BearerTokenAuthProvider, ApiKeyAuthProvider, NoOpAuthProvider, HmacAuthProvider, HttpAuthProviderFactory 5 paths) - IPC: 6 tests (IpcEncryption encrypt/decrypt/delete, EncryptedFileProcessInfoProvider Send/Receive round-trip) - GracefulExit: 1 test - HashAlgorithms: stub All 538 tests pass. Closes #423
1 parent 100cf3f commit 0720a12

17 files changed

Lines changed: 2171 additions & 48 deletions
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
using GeneralUpdate.Core.Configuration;
2+
3+
namespace CoreTest.Configuration;
4+
5+
public class ConfiginfoBuilderTests
6+
{
7+
#region SetXxx — Null/Empty Validation
8+
9+
[Theory]
10+
[InlineData(null)]
11+
[InlineData("")]
12+
[InlineData(" ")]
13+
public void SetUpdateUrl_InvalidValue_ThrowsArgumentException(string value)
14+
{
15+
var builder = new ConfiginfoBuilder();
16+
var ex = Assert.Throws<ArgumentException>(() => builder.SetUpdateUrl(value));
17+
Assert.Contains("updateUrl", ex.Message);
18+
}
19+
20+
[Fact]
21+
public void SetUpdateUrl_ValidValue_ReturnsBuilder()
22+
{
23+
var builder = new ConfiginfoBuilder();
24+
var result = builder.SetUpdateUrl("https://api.example.com");
25+
Assert.Same(builder, result);
26+
}
27+
28+
[Theory]
29+
[InlineData(null)]
30+
[InlineData("")]
31+
[InlineData(" ")]
32+
public void SetToken_InvalidValue_ThrowsArgumentException(string value)
33+
{
34+
var builder = new ConfiginfoBuilder();
35+
var ex = Assert.Throws<ArgumentException>(() => builder.SetToken(value));
36+
Assert.Contains("token", ex.Message);
37+
}
38+
39+
[Theory]
40+
[InlineData(null)]
41+
[InlineData("")]
42+
[InlineData(" ")]
43+
public void SetScheme_InvalidValue_ThrowsArgumentException(string value)
44+
{
45+
var builder = new ConfiginfoBuilder();
46+
var ex = Assert.Throws<ArgumentException>(() => builder.SetScheme(value));
47+
Assert.Contains("scheme", ex.Message);
48+
}
49+
50+
[Theory]
51+
[InlineData(null)]
52+
[InlineData("")]
53+
[InlineData(" ")]
54+
public void SetAppName_InvalidValue_ThrowsArgumentException(string value)
55+
{
56+
var builder = new ConfiginfoBuilder();
57+
var ex = Assert.Throws<ArgumentException>(() => builder.SetAppName(value));
58+
Assert.Contains("AppName", ex.Message);
59+
}
60+
61+
[Theory]
62+
[InlineData(null)]
63+
[InlineData("")]
64+
[InlineData(" ")]
65+
public void SetMainAppName_InvalidValue_ThrowsArgumentException(string value)
66+
{
67+
var builder = new ConfiginfoBuilder();
68+
var ex = Assert.Throws<ArgumentException>(() => builder.SetMainAppName(value));
69+
Assert.Contains("MainAppName", ex.Message);
70+
}
71+
72+
[Theory]
73+
[InlineData(null)]
74+
[InlineData("")]
75+
[InlineData(" ")]
76+
public void SetClientVersion_InvalidValue_ThrowsArgumentException(string value)
77+
{
78+
var builder = new ConfiginfoBuilder();
79+
var ex = Assert.Throws<ArgumentException>(() => builder.SetClientVersion(value));
80+
Assert.Contains("ClientVersion", ex.Message);
81+
}
82+
83+
[Theory]
84+
[InlineData(null)]
85+
[InlineData("")]
86+
[InlineData(" ")]
87+
public void SetUpgradeClientVersion_InvalidValue_ThrowsArgumentException(string value)
88+
{
89+
var builder = new ConfiginfoBuilder();
90+
var ex = Assert.Throws<ArgumentException>(() => builder.SetUpgradeClientVersion(value));
91+
Assert.Contains("UpgradeClientVersion", ex.Message);
92+
}
93+
94+
[Theory]
95+
[InlineData(null)]
96+
[InlineData("")]
97+
[InlineData(" ")]
98+
public void SetAppSecretKey_InvalidValue_ThrowsArgumentException(string value)
99+
{
100+
var builder = new ConfiginfoBuilder();
101+
var ex = Assert.Throws<ArgumentException>(() => builder.SetAppSecretKey(value));
102+
Assert.Contains("AppSecretKey", ex.Message);
103+
}
104+
105+
[Theory]
106+
[InlineData(null)]
107+
[InlineData("")]
108+
[InlineData(" ")]
109+
public void SetProductId_InvalidValue_ThrowsArgumentException(string value)
110+
{
111+
var builder = new ConfiginfoBuilder();
112+
var ex = Assert.Throws<ArgumentException>(() => builder.SetProductId(value));
113+
Assert.Contains("ProductId", ex.Message);
114+
}
115+
116+
[Theory]
117+
[InlineData(null)]
118+
[InlineData("")]
119+
[InlineData(" ")]
120+
public void SetInstallPath_InvalidValue_ThrowsArgumentException(string value)
121+
{
122+
var builder = new ConfiginfoBuilder();
123+
var ex = Assert.Throws<ArgumentException>(() => builder.SetInstallPath(value));
124+
Assert.Contains("InstallPath", ex.Message);
125+
}
126+
127+
#endregion
128+
129+
#region Null-Allowed Setters (Bowl, DriverDirectory, BlackFile collections)
130+
131+
[Fact]
132+
public void SetBowl_Null_Allowed()
133+
{
134+
var builder = new ConfiginfoBuilder();
135+
var result = builder.SetBowl(null);
136+
Assert.Same(builder, result);
137+
}
138+
139+
[Fact]
140+
public void SetDriverDirectory_Null_Allowed()
141+
{
142+
var builder = new ConfiginfoBuilder();
143+
var result = builder.SetDriverDirectory(null);
144+
Assert.Same(builder, result);
145+
}
146+
147+
[Fact]
148+
public void SetBlackFiles_Null_InitializesEmptyList()
149+
{
150+
var builder = new ConfiginfoBuilder();
151+
var result = builder.SetBlackFiles(null);
152+
Assert.Same(builder, result);
153+
}
154+
155+
[Fact]
156+
public void SetBlackFiles_ValidList_Stored()
157+
{
158+
var builder = new ConfiginfoBuilder();
159+
var files = new List<string> { "file1.dll", "file2.dll" };
160+
builder.SetBlackFiles(files);
161+
// Can only verify through Build()
162+
}
163+
164+
[Fact]
165+
public void SetBlackFormats_Null_InitializesEmptyList()
166+
{
167+
var builder = new ConfiginfoBuilder();
168+
var result = builder.SetBlackFormats(null);
169+
Assert.Same(builder, result);
170+
}
171+
172+
[Fact]
173+
public void SetSkipDirectorys_Null_InitializesEmptyList()
174+
{
175+
var builder = new ConfiginfoBuilder();
176+
var result = builder.SetSkipDirectorys(null);
177+
Assert.Same(builder, result);
178+
}
179+
180+
#endregion
181+
182+
#region Fluent Chaining
183+
184+
[Fact]
185+
public void SetMethods_ReturnsSameBuilder_ForChaining()
186+
{
187+
var builder = new ConfiginfoBuilder();
188+
var result = builder
189+
.SetUpdateUrl("https://api.example.com")
190+
.SetToken("token")
191+
.SetScheme("https")
192+
.SetAppName("MyApp")
193+
.SetMainAppName("MainApp")
194+
.SetClientVersion("1.0.0");
195+
Assert.Same(builder, result);
196+
}
197+
198+
#endregion
199+
200+
#region Build — Success / Validation Failure
201+
202+
[Fact]
203+
public void Build_WithRequiredFields_ReturnsConfiginfo()
204+
{
205+
var config = new ConfiginfoBuilder()
206+
.SetUpdateUrl("https://api.example.com")
207+
.SetToken("token123")
208+
.SetScheme("https")
209+
.SetAppName("MyApp.exe")
210+
.SetMainAppName("MyApp")
211+
.SetClientVersion("1.0.0")
212+
.SetAppSecretKey("secret")
213+
.SetInstallPath("C:\\app")
214+
.Build();
215+
216+
Assert.NotNull(config);
217+
Assert.Equal("https://api.example.com", config.UpdateUrl);
218+
Assert.Equal("token123", config.Token);
219+
Assert.Equal("https", config.Scheme);
220+
Assert.Equal("MyApp.exe", config.AppName);
221+
Assert.Equal("MyApp", config.MainAppName);
222+
Assert.Equal("1.0.0", config.ClientVersion);
223+
Assert.Equal("secret", config.AppSecretKey);
224+
Assert.Equal("C:\\app", config.InstallPath);
225+
}
226+
227+
[Fact]
228+
public void Build_MissingRequiredFields_ThrowsInvalidOperationException()
229+
{
230+
var builder = new ConfiginfoBuilder()
231+
.SetUpdateUrl("https://api.example.com")
232+
.SetToken("token")
233+
.SetScheme("https");
234+
// Missing AppName, MainAppName, AppSecretKey, ClientVersion, InstallPath
235+
var ex = Assert.Throws<InvalidOperationException>(() => builder.Build());
236+
Assert.Contains("Failed to build valid Configinfo", ex.Message);
237+
Assert.IsType<ArgumentException>(ex.InnerException);
238+
}
239+
240+
[Fact]
241+
public void Build_EmptyBlackLists_ReturnsEmptyListNotNll()
242+
{
243+
var config = new ConfiginfoBuilder()
244+
.SetUpdateUrl("https://api.example.com")
245+
.SetToken("token123")
246+
.SetScheme("https")
247+
.SetAppName("MyApp.exe")
248+
.SetMainAppName("MyApp")
249+
.SetClientVersion("1.0.0")
250+
.SetAppSecretKey("secret")
251+
.SetInstallPath("C:\\app")
252+
.Build();
253+
254+
Assert.NotNull(config.BlackFiles);
255+
Assert.NotNull(config.BlackFormats);
256+
Assert.NotNull(config.SkipDirectorys);
257+
}
258+
259+
[Fact]
260+
public void Build_WithOptionalFields_IncludesThem()
261+
{
262+
var config = new ConfiginfoBuilder()
263+
.SetUpdateUrl("https://api.example.com")
264+
.SetToken("token123")
265+
.SetScheme("https")
266+
.SetAppName("MyApp.exe")
267+
.SetMainAppName("MyApp")
268+
.SetClientVersion("1.0.0")
269+
.SetAppSecretKey("secret")
270+
.SetInstallPath("C:\\app")
271+
.SetUpdateLogUrl("https://api.example.com/log")
272+
.SetProductId("product-001")
273+
.SetUpgradeClientVersion("2.0.0")
274+
.SetBowl("BowlApp")
275+
.SetDriverDirectory("C:\\drivers")
276+
.Build();
277+
278+
Assert.Equal("https://api.example.com/log", config.UpdateLogUrl);
279+
Assert.Equal("product-001", config.ProductId);
280+
Assert.Equal("2.0.0", config.UpgradeClientVersion);
281+
Assert.Equal("BowlApp", config.Bowl);
282+
Assert.Equal("C:\\drivers", config.DriverDirectory);
283+
}
284+
285+
#endregion
286+
}

0 commit comments

Comments
 (0)