From 17218ea2919b7c249503c0321e74d5306c5cbeb4 Mon Sep 17 00:00:00 2001 From: "Shkar T. Noori" Date: Sat, 18 Jun 2022 12:52:59 +0300 Subject: [PATCH] Use KeyNotFound exception --- .../DefaultWorkflowFactory.cs | 2 +- .../DependencyInjectionTests.cs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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")); + } + }