feat(core): add PluginManifest json parsing
This commit is contained in:
parent
caf57cca3e
commit
c082ecf36a
3 changed files with 135 additions and 3 deletions
62
tests/AcDream.Core.Tests/Plugins/PluginManifestTests.cs
Normal file
62
tests/AcDream.Core.Tests/Plugins/PluginManifestTests.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
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.Contains("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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue