workflow-core
workflow-core copied to clipboard
Unit test does not execute step
I have a unit test like this:
public class WorkflowUnitTests: WorkflowTest<MyWorkflow, CaseChanged>
{
private Mock<IServices> _servicesMock;
public MyWorkflowUnitTests()
{
_servicesMock = new Mock<IServices>();
// Set up mock methods
// ...
Setup();
}
[Fact]
public async Task Workflow_Sample_Test()
{
var workflowId = await StartWorkflowAsync(new CaseChanged()
{
Data = new CaseData()
{
CaseRecordId = 123
}
}) ;
await WaitForWorkflowToCompleteAsync(workflowId, TimeSpan.FromSeconds(10));
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
UnhandledStepErrors.Count.Should().Be(0);
}
}
And the workflow:
public void Build(IWorkflowBuilder<CaseChanged> builder)
{
builder
.StartWith(context =>
{
Log.Information($"Starting workflow '{Id}'"); // => **this is called**
return ExecutionResult.Next();
})
.Then<UpdateStep>() // => **this step not**
.Input(step => step.CaseChanged, caseChanged => caseChanged)
.Then(context => Log.Information($"Workflow '{Id}' complete"));
}
And the step
public class UpdateStep : StepBodyAsync
{
public CaseChanged? CaseChanged { get; set; }
private IServices Services { get; }
public UpdateStep(IServices services)
{
Services = services;
}
public override async Task<ExecutionResult> RunAsync(IStepExecutionContext context)
{
// ....
return ExecutionResult.Next();
}
}
The ctor of the step is also never called.
What can be the issue?
Hi,
You should register your UpdateStep service by overriding ConfigureServices method in your WorkflowUnitTests. For exemple :
protected override void ConfigureServices(IServiceCollection services) {
base.ConfigureServices( services );
services.AddLogging( builder => {
builder.SetMinimumLevel( LogLevel.Information );
builder.AddSimpleConsole( options => {
options.IncludeScopes = true;
options.SingleLine = true;
});
} );
services.AddTransient< UpdateStep >( );
}