Use KeyNotFound exception

This commit is contained in:
Shkar T. Noori 2022-06-18 12:52:59 +03:00
parent ab80dad816
commit 17218ea291
No known key found for this signature in database
GPG Key ID: C5E1A00F3BB78732
2 changed files with 16 additions and 1 deletions

View File

@ -25,7 +25,7 @@ public class DefaultWorkflowFactory<TState, TCommand, TContext> : IWorkflowFacto
.FirstOrDefault(x => x.Reference == reference); .FirstOrDefault(x => x.Reference == reference);
if (service is null) 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; return service;
} }

View File

@ -75,4 +75,19 @@ public class DependencyInjectionTests
Assert.Equal("PhoneState_PhoneCommand_PhoneCall", workflow.Id); Assert.Equal("PhoneState_PhoneCommand_PhoneCall", workflow.Id);
} }
[Fact]
public void UnknownWorkflowReferenceThrows()
{
var sc = new ServiceCollection();
sc.AddWorkflowDefinition<PhoneState, PhoneCommand, PhoneCall>(version: 1)
.From(PhoneState.Idle)
.On(PhoneCommand.IncomingCall)
.To(PhoneState.Ringing);
var sp = sc.BuildServiceProvider();
var workflowFactory = sp.GetRequiredService<IWorkflowFactory<PhoneState, PhoneCommand, PhoneCall>>();
Assert.Throws<KeyNotFoundException>(() => workflowFactory.CreateWorkflow("unknown"));
}
} }