45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using w4c_workflows.Models;
|
|
using w4c_workflows.Models.Nodes;
|
|
using w4c_workflows.Services.Nodes;
|
|
using YamlDotNet.Serialization;
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
|
|
namespace w4c_workflows.Tests;
|
|
|
|
/// <summary>Shared helpers for node graph tests: YAML parsing and small catalogs.</summary>
|
|
internal static class NodeTestData
|
|
{
|
|
private static readonly IDeserializer Yaml = new DeserializerBuilder()
|
|
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
|
.WithAttemptingUnquotedStringTypeDeserialization()
|
|
.IgnoreUnmatchedProperties()
|
|
.Build();
|
|
|
|
public static WorkflowDefinition Parse(string yaml) => Yaml.Deserialize<WorkflowDefinition>(yaml) ?? new();
|
|
|
|
public static NodeBlueprintCatalog CoreCatalog() => new(NodeBlueprintCatalog.LoadEmbedded());
|
|
|
|
public static NodeBlueprint NodeBlueprint(
|
|
string type,
|
|
double version = 1,
|
|
IReadOnlyList<NodePort>? outputs = null,
|
|
IReadOnlyList<NodeParameter>? parameters = null,
|
|
string runMode = NodeRunMode.EachItem)
|
|
=> new()
|
|
{
|
|
Type = type,
|
|
Version = version,
|
|
DisplayName = type,
|
|
Outputs = outputs?.ToList() ?? new List<NodePort> { NodePort.Main },
|
|
Parameters = parameters?.ToList() ?? new List<NodeParameter>(),
|
|
RunMode = runMode,
|
|
};
|
|
|
|
public static NodeBlueprintCatalog Catalog(params NodeBlueprint[] extra)
|
|
{
|
|
var blueprints = NodeBlueprintCatalog.LoadEmbedded().ToList();
|
|
blueprints.AddRange(extra);
|
|
return new NodeBlueprintCatalog(blueprints);
|
|
}
|
|
}
|