Skip to content

Commit 94400cd

Browse files
CopilotJusterZhu
andcommitted
Add Velopack-inspired factory method and improve documentation
- Added ConfiginfoBuilder.Create() factory method for more fluent API - Updated documentation to mention Velopack zero-configuration inspiration - Added tests for factory method (34/34 tests passing) - Enhanced XML documentation with references to zero-configuration patterns Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
1 parent 7fd3405 commit 94400cd

5 files changed

Lines changed: 69 additions & 9 deletions

File tree

src/c#/CoreTest/Shared/ConfiginfoBuilderTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,37 @@ public void Constructor_WithValidParameters_CreatesInstance()
3131
Assert.NotNull(builder);
3232
}
3333

34+
/// <summary>
35+
/// Tests that the Create factory method properly initializes with valid parameters.
36+
/// </summary>
37+
[Fact]
38+
public void Create_WithValidParameters_CreatesInstance()
39+
{
40+
// Act
41+
var builder = ConfiginfoBuilder.Create(TestUpdateUrl, TestToken, TestScheme);
42+
43+
// Assert
44+
Assert.NotNull(builder);
45+
}
46+
47+
/// <summary>
48+
/// Tests that Create factory method produces same result as constructor.
49+
/// </summary>
50+
[Fact]
51+
public void Create_ProducesSameResultAsConstructor()
52+
{
53+
// Act
54+
var config1 = new ConfiginfoBuilder(TestUpdateUrl, TestToken, TestScheme).Build();
55+
var config2 = ConfiginfoBuilder.Create(TestUpdateUrl, TestToken, TestScheme).Build();
56+
57+
// Assert
58+
Assert.Equal(config1.UpdateUrl, config2.UpdateUrl);
59+
Assert.Equal(config1.Token, config2.Token);
60+
Assert.Equal(config1.Scheme, config2.Scheme);
61+
Assert.Equal(config1.InstallPath, config2.InstallPath);
62+
Assert.Equal(config1.AppName, config2.AppName);
63+
}
64+
3465
/// <summary>
3566
/// Tests that the constructor throws ArgumentException when UpdateUrl is null.
3667
/// </summary>

src/c#/GeneralUpdate.Common/Shared/Object/ConfiginfoBuilder-Example.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ static void Main(string[] args)
1414
Console.WriteLine("=== ConfiginfoBuilder Usage Examples ===\n");
1515

1616
// Example 1: Minimal configuration (recommended for most cases)
17-
Console.WriteLine("Example 1: Minimal Configuration");
18-
var minimalConfig = new ConfiginfoBuilder(
19-
updateUrl: "https://api.example.com/updates",
20-
token: "your-auth-token",
21-
scheme: "https"
22-
).Build();
17+
Console.WriteLine("Example 1: Minimal Configuration - Using Factory Method");
18+
var minimalConfig = ConfiginfoBuilder
19+
.Create("https://api.example.com/updates", "your-auth-token", "https")
20+
.Build();
2321

2422
Console.WriteLine($" UpdateUrl: {minimalConfig.UpdateUrl}");
2523
Console.WriteLine($" Token: {minimalConfig.Token}");
@@ -30,7 +28,7 @@ static void Main(string[] args)
3028
Console.WriteLine();
3129

3230
// Example 2: Custom configuration with method chaining
33-
Console.WriteLine("Example 2: Custom Configuration");
31+
Console.WriteLine("Example 2: Custom Configuration - Using Constructor");
3432
var customConfig = new ConfiginfoBuilder(
3533
"https://api.example.com/updates",
3634
"Bearer abc123xyz",

src/c#/GeneralUpdate.Common/Shared/Object/ConfiginfoBuilder-Usage.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The `ConfiginfoBuilder` class provides a simple and convenient way to create `Configinfo` objects for the GeneralUpdate system. It only requires three essential parameters while automatically generating platform-appropriate defaults for all other configuration items.
44

5+
**Design Philosophy**: Inspired by zero-configuration patterns from projects like [Velopack](https://github.com/velopack/velopack), this builder minimizes required configuration while maintaining flexibility through optional fluent setters.
6+
57
## Basic Usage
68

79
### Minimal Configuration
@@ -11,13 +13,18 @@ The simplest way to create a `Configinfo` object is to provide just the three re
1113
```csharp
1214
using GeneralUpdate.Common.Shared.Object;
1315

14-
// Create a builder with required parameters only
16+
// Method 1: Direct constructor (traditional)
1517
var config = new ConfiginfoBuilder(
1618
updateUrl: "https://api.example.com/updates",
1719
token: "your-auth-token",
1820
scheme: "https"
1921
).Build();
2022

23+
// Method 2: Factory method (recommended, more fluent)
24+
var config2 = ConfiginfoBuilder
25+
.Create("https://api.example.com/updates", "your-auth-token", "https")
26+
.Build();
27+
2128
// The config object now has all necessary defaults set based on the platform
2229
```
2330

src/c#/GeneralUpdate.Common/Shared/Object/ConfiginfoBuilder.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace GeneralUpdate.Common.Shared.Object
99
/// Universal ConfigInfo builder class that simplifies creation of update configurations.
1010
/// Only requires three essential parameters (UpdateUrl, Token, Scheme) while automatically
1111
/// generating platform-appropriate defaults for all other configuration items.
12+
/// Inspired by zero-configuration design patterns from projects like Velopack.
1213
/// </summary>
1314
public class ConfiginfoBuilder
1415
{
@@ -38,8 +39,24 @@ public class ConfiginfoBuilder
3839
private List<string> _blackFormats;
3940
private List<string> _skipDirectorys;
4041

42+
/// <summary>
43+
/// Creates a new ConfiginfoBuilder instance using the specified update URL, authentication token, and scheme.
44+
/// This is the primary factory method for creating a builder with zero-configuration defaults.
45+
/// All other configuration properties will be automatically initialized with platform-appropriate defaults.
46+
/// </summary>
47+
/// <param name="updateUrl">The API endpoint URL for checking available updates. Must be a valid absolute URI.</param>
48+
/// <param name="token">The authentication token used for API requests.</param>
49+
/// <param name="scheme">The URL scheme used for update requests (e.g., "http" or "https").</param>
50+
/// <returns>A new ConfiginfoBuilder instance with all defaults initialized.</returns>
51+
/// <exception cref="ArgumentException">Thrown when any required parameter is null, empty, or invalid.</exception>
52+
public static ConfiginfoBuilder Create(string updateUrl, string token, string scheme)
53+
{
54+
return new ConfiginfoBuilder(updateUrl, token, scheme);
55+
}
56+
4157
/// <summary>
4258
/// Initializes a new instance of the ConfiginfoBuilder with required parameters.
59+
/// Consider using <see cref="Create(string, string, string)"/> for a more fluent API.
4360
/// </summary>
4461
/// <param name="updateUrl">The API endpoint URL for checking available updates. Must be a valid absolute URI.</param>
4562
/// <param name="token">The authentication token used for API requests.</param>

src/c#/GeneralUpdate.Common/Shared/Object/README-ConfiginfoBuilder.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@
44

55
The `ConfiginfoBuilder` class provides a simple, fluent API for creating `Configinfo` objects with minimal effort. It automatically handles platform-specific defaults and only requires three essential parameters.
66

7+
**Design Inspiration**: The zero-configuration approach is inspired by projects like [Velopack](https://github.com/velopack/velopack), focusing on sensible defaults extracted from the running application with minimal user input required.
8+
79
## Quick Start
810

911
```csharp
1012
using GeneralUpdate.Common.Shared.Object;
1113

12-
// Create a configuration with just 3 parameters
14+
// Method 1: Direct constructor
1315
var config = new ConfiginfoBuilder(
1416
updateUrl: "https://api.example.com/updates",
1517
token: "your-auth-token",
1618
scheme: "https"
1719
).Build();
1820

21+
// Method 2: Factory method (recommended)
22+
var config2 = ConfiginfoBuilder
23+
.Create("https://api.example.com/updates", "your-auth-token", "https")
24+
.Build();
25+
1926
// That's it! All defaults are set automatically based on your platform.
2027
```
2128

0 commit comments

Comments
 (0)