diff --git a/src/DIT.Workflower.DependencyInjection/DefaultWorkflowFactory.cs b/src/DIT.Workflower.DependencyInjection/DefaultWorkflowFactory.cs index 65a338c..0711781 100644 --- a/src/DIT.Workflower.DependencyInjection/DefaultWorkflowFactory.cs +++ b/src/DIT.Workflower.DependencyInjection/DefaultWorkflowFactory.cs @@ -25,7 +25,7 @@ public class DefaultWorkflowFactory : IWorkflowFacto .FirstOrDefault(x => x.Reference == reference); if (service is null) - throw new ArgumentOutOfRangeException(nameof(version), $"Workflow reference {id}.v{version} does not exist"); + throw new KeyNotFoundException($"Workflow reference {id}.v{version} does not exist"); return service; } diff --git a/tests/DIT.Workflower.Tests/DependencyInjection/DependencyInjectionTests.cs b/tests/DIT.Workflower.Tests/DependencyInjection/DependencyInjectionTests.cs index b5649c8..f06cd4b 100644 --- a/tests/DIT.Workflower.Tests/DependencyInjection/DependencyInjectionTests.cs +++ b/tests/DIT.Workflower.Tests/DependencyInjection/DependencyInjectionTests.cs @@ -75,4 +75,19 @@ public class DependencyInjectionTests Assert.Equal("PhoneState_PhoneCommand_PhoneCall", workflow.Id); } + [Fact] + public void UnknownWorkflowReferenceThrows() + { + var sc = new ServiceCollection(); + + sc.AddWorkflowDefinition(version: 1) + .From(PhoneState.Idle) + .On(PhoneCommand.IncomingCall) + .To(PhoneState.Ringing); + + var sp = sc.BuildServiceProvider(); + var workflowFactory = sp.GetRequiredService>(); + Assert.Throws(() => workflowFactory.CreateWorkflow("unknown")); + } + }