39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System.Text.Json;
|
|
using VolcanicCore.Api.Registries;
|
|
using VolcanicCore.Core;
|
|
|
|
namespace VolcanicCore.Tests;
|
|
|
|
public class NodeRegistryTests
|
|
{
|
|
private sealed class FakeAction : IActionNode
|
|
{
|
|
public string Id => "test.echo";
|
|
public string DisplayName => "Echo";
|
|
public NodeCategory Category => NodeCategory.Action;
|
|
public int InputCount => 1;
|
|
public int OutputCount => 1;
|
|
public string? ConnectionProviderId => null;
|
|
public JsonSchema ConfigSchema => new(JsonDocument.Parse("{}").RootElement);
|
|
public Task<IReadOnlyList<IReadOnlyList<Item>>> ExecuteAsync(
|
|
INodeContext ctx, IReadOnlyList<IReadOnlyList<Item>> inputsByPort, CancellationToken ct)
|
|
=> Task.FromResult<IReadOnlyList<IReadOnlyList<Item>>>(new[] { inputsByPort[0] });
|
|
}
|
|
|
|
[Fact]
|
|
public void Registers_instances_and_looks_them_up_by_id()
|
|
{
|
|
var reg = new NodeRegistry(new INodeType[] { new FakeAction() });
|
|
Assert.Single(reg.All);
|
|
Assert.Same(reg.All[0], reg.Get("test.echo"));
|
|
Assert.Throws<KeyNotFoundException>(() => reg.Get("does.not.exist"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Duplicate_ids_throw()
|
|
{
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
new NodeRegistry(new INodeType[] { new FakeAction(), new FakeAction() }));
|
|
}
|
|
}
|