@@ -44,8 +44,14 @@ public WorkflowExecutorFixture()
4444
4545 Options = new WorkflowOptions ( A . Fake < IServiceCollection > ( ) ) ;
4646
47+ var stepExecutionScope = A . Fake < IServiceScope > ( ) ;
48+ A . CallTo ( ( ) => ScopeProvider . CreateScope ( A < IStepExecutionContext > . _ ) ) . Returns ( stepExecutionScope ) ;
49+ A . CallTo ( ( ) => stepExecutionScope . ServiceProvider ) . Returns ( ServiceProvider ) ;
50+
4751 var scope = A . Fake < IServiceScope > ( ) ;
48- A . CallTo ( ( ) => ScopeProvider . CreateScope ( A < IStepExecutionContext > . _ ) ) . Returns ( scope ) ;
52+ var scopeFactory = A . Fake < IServiceScopeFactory > ( ) ;
53+ A . CallTo ( ( ) => ServiceProvider . GetService ( typeof ( IServiceScopeFactory ) ) ) . Returns ( scopeFactory ) ;
54+ A . CallTo ( ( ) => scopeFactory . CreateScope ( ) ) . Returns ( scope ) ;
4955 A . CallTo ( ( ) => scope . ServiceProvider ) . Returns ( ServiceProvider ) ;
5056
5157 A . CallTo ( ( ) => DateTimeProvider . Now ) . Returns ( DateTime . Now ) ;
@@ -63,6 +69,10 @@ public WorkflowExecutorFixture()
6369 . RunPostMiddleware ( A < WorkflowInstance > . _ , A < WorkflowDefinition > . _ ) )
6470 . Returns ( Task . CompletedTask ) ;
6571
72+ A . CallTo ( ( ) => MiddlewareRunner
73+ . RunExecuteMiddleware ( A < WorkflowInstance > . _ , A < WorkflowDefinition > . _ ) )
74+ . Returns ( Task . CompletedTask ) ;
75+
6676 A . CallTo ( ( ) => StepExecutor . ExecuteStep ( A < IStepExecutionContext > . _ , A < IStepBody > . _ ) )
6777 . ReturnsLazily ( call =>
6878 call . Arguments [ 1 ] . As < IStepBody > ( ) . RunAsync (
@@ -105,6 +115,64 @@ public void should_execute_active_step()
105115 A . CallTo ( ( ) => ResultProcesser . ProcessExecutionResult ( instance , A < WorkflowDefinition > . Ignored , A < ExecutionPointer > . Ignored , step1 , A < ExecutionResult > . Ignored , A < WorkflowExecutorResult > . Ignored ) ) . MustHaveHappened ( ) ;
106116 }
107117
118+ [ Fact ( DisplayName = "Should call execute middleware when not completed" ) ]
119+ public void should_call_execute_middleware_when_not_completed ( )
120+ {
121+ //arrange
122+ var step1Body = A . Fake < IStepBody > ( ) ;
123+ A . CallTo ( ( ) => step1Body . RunAsync ( A < IStepExecutionContext > . Ignored ) ) . Returns ( ExecutionResult . Next ( ) ) ;
124+ WorkflowStep step1 = BuildFakeStep ( step1Body ) ;
125+ Given1StepWorkflow ( step1 , "Workflow" , 1 ) ;
126+
127+ var instance = new WorkflowInstance
128+ {
129+ WorkflowDefinitionId = "Workflow" ,
130+ Version = 1 ,
131+ Status = WorkflowStatus . Runnable ,
132+ NextExecution = 0 ,
133+ Id = "001" ,
134+ ExecutionPointers = new ExecutionPointerCollection ( new List < ExecutionPointer >
135+ {
136+ new ExecutionPointer { Id = "1" , Active = true , StepId = 0 }
137+ } )
138+ } ;
139+
140+ //act
141+ Subject . Execute ( instance ) ;
142+
143+ //assert
144+ A . CallTo ( ( ) => MiddlewareRunner . RunExecuteMiddleware ( instance , A < WorkflowDefinition > . Ignored ) ) . MustHaveHappened ( ) ;
145+ }
146+
147+ [ Fact ( DisplayName = "Should not call post middleware when not completed" ) ]
148+ public void should_not_call_post_middleware_when_not_completed ( )
149+ {
150+ //arrange
151+ var step1Body = A . Fake < IStepBody > ( ) ;
152+ A . CallTo ( ( ) => step1Body . RunAsync ( A < IStepExecutionContext > . Ignored ) ) . Returns ( ExecutionResult . Next ( ) ) ;
153+ WorkflowStep step1 = BuildFakeStep ( step1Body ) ;
154+ Given1StepWorkflow ( step1 , "Workflow" , 1 ) ;
155+
156+ var instance = new WorkflowInstance
157+ {
158+ WorkflowDefinitionId = "Workflow" ,
159+ Version = 1 ,
160+ Status = WorkflowStatus . Runnable ,
161+ NextExecution = 0 ,
162+ Id = "001" ,
163+ ExecutionPointers = new ExecutionPointerCollection ( new List < ExecutionPointer >
164+ {
165+ new ExecutionPointer { Id = "1" , Active = true , StepId = 0 }
166+ } )
167+ } ;
168+
169+ //act
170+ Subject . Execute ( instance ) ;
171+
172+ //assert
173+ A . CallTo ( ( ) => MiddlewareRunner . RunPostMiddleware ( instance , A < WorkflowDefinition > . Ignored ) ) . MustNotHaveHappened ( ) ;
174+ }
175+
108176 [ Fact ( DisplayName = "Should trigger step hooks" ) ]
109177 public void should_trigger_step_hooks ( )
110178 {
0 commit comments