acdream/tests/AcDream.Core.Tests/Plugins/PluginManifestTests.cs

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.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);
}
}