mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-27 15:36:57 +00:00
feat: emit native types instead of Newtonsoft JObject/JArray in public APIs
Replace all Newtonsoft.Json.Linq types (JObject, JArray, JToken) exposed in public service methods, model properties, and cmdlet OutputTypes with native .NET types (Dictionary<string, object?>, List<Dictionary<string, object?>>, PSObject). New utilities: - JsonHelper: ToNative, ToDictionary, ToListOfDictionaries for recursive JToken→native conversion - NativeListConverter / NativeDictionaryConverter: JsonConverters for model properties that deserialize JArray/JObject to native types Services updated (8 methods): - NodeService: GetNodeConfig, GetNodeDns → Dictionary<string, object?> - BackupService: GetNotBackedUp → List<Dictionary<string, object?>> - ClusterConfigService: GetClusterConfig, GetTotem, GetQdevice → Dictionary - HaService: GetManagerStatus → Dictionary<string, object?> - VmService: GetGuestExecStatus → Dictionary<string, object?> Models updated (2 properties): - PvePool.Members: JArray → List<Dictionary<string, object?>> - PveHaRule.Properties: JObject → Dictionary<string, object?> Cmdlets updated (5): - GetPveClusterConfigCmdlet: OutputType JToken → Dictionary<string, object> - GetPveNodeConfigCmdlet: iteration updated for Dictionary - GetPveNodeDnsCmdlet: iteration updated for Dictionary - GetPveBackupInfoCmdlet: iteration updated for List<Dictionary> - InvokePveVmGuestExecCmdlet: polling updated for Dictionary Added D013 to DECISIONS.md: cmdlets must emit only native or module-defined types. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -360,7 +360,7 @@ namespace PSProxmoxVE.Core.Tests.Services
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
[Fact]
|
||||
public void GetNotBackedUp_ReturnsJArray()
|
||||
public void GetNotBackedUp_ReturnsListOfDictionaries()
|
||||
{
|
||||
// Arrange
|
||||
var json = @"{
|
||||
@@ -379,14 +379,14 @@ namespace PSProxmoxVE.Core.Tests.Services
|
||||
var result = service.GetNotBackedUp(CreateSession());
|
||||
|
||||
// Assert
|
||||
Assert.IsType<JArray>(result);
|
||||
Assert.IsType<List<Dictionary<string, object?>>>(result);
|
||||
Assert.Equal(2, result.Count);
|
||||
Assert.Equal(100, result[0]["vmid"]!.Value<int>());
|
||||
Assert.Equal("webserver", result[0]["name"]!.Value<string>());
|
||||
Assert.Equal(100L, result[0]["vmid"]);
|
||||
Assert.Equal("webserver", result[0]["name"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetNotBackedUp_EmptyData_ReturnsEmptyJArray()
|
||||
public void GetNotBackedUp_EmptyData_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange
|
||||
var json = @"{""data"": []}";
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace PSProxmoxVE.Core.Tests.Services
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetNodeConfig_ReturnsJObject()
|
||||
public void GetNodeConfig_ReturnsDictionary()
|
||||
{
|
||||
// Arrange
|
||||
var json = @"{""data"": {""description"": ""Primary node"", ""wakeonlan"": ""AA:BB:CC:DD:EE:FF""}}";
|
||||
@@ -84,6 +84,7 @@ namespace PSProxmoxVE.Core.Tests.Services
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(config);
|
||||
Assert.IsType<Dictionary<string, object?>>(config);
|
||||
Assert.Equal("Primary node", config["description"]?.ToString());
|
||||
Assert.Equal("AA:BB:CC:DD:EE:FF", config["wakeonlan"]?.ToString());
|
||||
mockClient.Verify(c => c.GetAsync("nodes/pve1/config"), Times.Once);
|
||||
@@ -116,7 +117,7 @@ namespace PSProxmoxVE.Core.Tests.Services
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetNodeDns_ReturnsJObject()
|
||||
public void GetNodeDns_ReturnsDictionary()
|
||||
{
|
||||
// Arrange
|
||||
var json = @"{""data"": {""dns1"": ""8.8.8.8"", ""dns2"": ""8.8.4.4"", ""search"": ""example.com""}}";
|
||||
@@ -129,6 +130,7 @@ namespace PSProxmoxVE.Core.Tests.Services
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(dns);
|
||||
Assert.IsType<Dictionary<string, object?>>(dns);
|
||||
Assert.Equal("8.8.8.8", dns["dns1"]?.ToString());
|
||||
Assert.Equal("8.8.4.4", dns["dns2"]?.ToString());
|
||||
Assert.Equal("example.com", dns["search"]?.ToString());
|
||||
|
||||
Reference in New Issue
Block a user