
using KBX.Shared.Workflow;
using Xunit;
namespace KBX.Shared.Workflow.Tests;
public sealed class WorkflowGuardTests
{
    private static readonly WorkflowTransition[] Transitions = [
        new("confirm", new HashSet<string>{"DRAFT"}, "CONFIRMED"),
        new("cancel", new HashSet<string>{"DRAFT","CONFIRMED"}, "CANCELLED", ReasonRequired:true)
    ];
    [Fact] public void Allows_declared_transition() => Assert.Equal("CONFIRMED", WorkflowGuard.RequireTransition(Transitions,"confirm","DRAFT").To);
    [Fact] public void Rejects_transition_from_wrong_state() => Assert.Throws<InvalidOperationException>(() => WorkflowGuard.RequireTransition(Transitions,"confirm","CONFIRMED"));
    [Fact] public void Requires_reason_when_declared() => Assert.Throws<InvalidOperationException>(() => WorkflowGuard.RequireTransition(Transitions,"cancel","DRAFT"));
}
