acdream/tests/AcDream.Core.Tests/Plugins/PluginManifestTests.cs
Erik 99d2702c13 refactor(core): harden PluginManifest error model
Addresses code quality review of c082ecf:
- Require takes a literal JSON field name, no more fragile PascalCase->camelCase transform
- Parse_MissingRequiredField_Throws asserts exact message, not substring
- Remove unused using System.Text.Json.Serialization
2026-04-10 09:33:00 +02:00

62 lines
1.6 KiB
C#

using AcDream.Core.Plugins;
namespace AcDream.Core.Tests.Plugins;
public class PluginManifestTests
{
[Fact]
public void Parse_ValidManifest_ReturnsManifest()
{
const string json = """
{
"id": "acdream.smoke",
"displayName": "Smoke Test",
"version": "0.1.0",
"entryDll": "AcDream.Plugins.Smoke.dll",
"apiVersion": 1
}
""";
var manifest = PluginManifest.Parse(json);
Assert.Equal("acdream.smoke", manifest.Id);
Assert.Equal("Smoke Test", manifest.DisplayName);
Assert.Equal("0.1.0", manifest.Version);
Assert.Equal("AcDream.Plugins.Smoke.dll", manifest.EntryDll);
Assert.Equal(1, manifest.ApiVersion);
}
[Fact]
public void Parse_MissingRequiredField_Throws()
{
const string json = """
{ "id": "x", "version": "0.1.0", "entryDll": "x.dll", "apiVersion": 1 }
""";
var ex = Assert.Throws<PluginManifestException>(() => PluginManifest.Parse(json));
Assert.Equal("missing required field: displayName", ex.Message);
}
[Fact]
public void Parse_MalformedJson_Throws()
{
Assert.Throws<PluginManifestException>(() => PluginManifest.Parse("{ not json"));
}
[Fact]
public void Parse_EmptyDependencies_DefaultsToEmptyList()
{
const string json = """
{
"id": "x",
"displayName": "X",
"version": "0.1.0",
"entryDll": "x.dll",
"apiVersion": 1
}
""";
var manifest = PluginManifest.Parse(json);
Assert.Empty(manifest.Dependencies);
}
}