-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
342 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Cleipnir.ResilientFunctions.Domain; | ||
using Cleipnir.ResilientFunctions.Storage; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Shouldly; | ||
|
||
namespace Cleipnir.Flows.Tests.Flows; | ||
|
||
[TestClass] | ||
public class FlowsWithStateTests | ||
{ | ||
[TestMethod] | ||
public async Task ActionFlowWithStateCanBeFetchedAfterExecution() | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddTransient<ActionFlowWithState>(); | ||
|
||
var flowStore = new InMemoryFunctionStore(); | ||
var flowsContainer = new FlowsContainer( | ||
flowStore, | ||
serviceCollection.BuildServiceProvider() | ||
); | ||
|
||
var flows = new ActionFlowWithStates(flowsContainer); | ||
await flows.Run("someInstanceId", "someParameter"); | ||
|
||
var state = await flows.GetState("someInstanceId"); | ||
state.ShouldNotBeNull(); | ||
state.Value.ShouldBe("someParameter"); | ||
|
||
var controlPanel = await flows.ControlPanel(instanceId: "someInstanceId"); | ||
controlPanel.ShouldNotBeNull(); | ||
controlPanel.Status.ShouldBe(Status.Succeeded); | ||
} | ||
|
||
public class ActionFlowWithState : Flow<string>, IHaveState<ActionFlowWithState.FlowState> | ||
{ | ||
public required FlowState State { get; init; } | ||
|
||
public override Task Run(string param) | ||
{ | ||
State.Value = param; | ||
return Task.CompletedTask; | ||
} | ||
|
||
public class FlowState : WorkflowState | ||
{ | ||
public string Value { get; set; } = ""; | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task FuncFlowWithStateCanBeFetchedAfterExecution() | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddTransient<FuncFlowWithState>(); | ||
|
||
var flowStore = new InMemoryFunctionStore(); | ||
var flowsContainer = new FlowsContainer( | ||
flowStore, | ||
serviceCollection.BuildServiceProvider() | ||
); | ||
|
||
var flows = new FuncFlowWithStates(flowsContainer); | ||
await flows.Run("someInstanceId", "someParameter"); | ||
|
||
var state = await flows.GetState("someInstanceId"); | ||
state.ShouldNotBeNull(); | ||
state.Value.ShouldBe("someParameter"); | ||
|
||
var controlPanel = await flows.ControlPanel(instanceId: "someInstanceId"); | ||
controlPanel.ShouldNotBeNull(); | ||
controlPanel.Result.ShouldBe("someParameter"); | ||
controlPanel.Status.ShouldBe(Status.Succeeded); | ||
} | ||
|
||
public class FuncFlowWithState : Flow<string, string>, IHaveState<FuncFlowWithState.FlowState> | ||
{ | ||
public required FlowState State { get; init; } | ||
|
||
public override Task<string> Run(string param) | ||
{ | ||
State.Value = param; | ||
return Task.FromResult(param); | ||
} | ||
|
||
public class FlowState : WorkflowState | ||
{ | ||
public string Value { get; set; } = ""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Cleipnir.ResilientFunctions.Domain; | ||
|
||
namespace Cleipnir.Flows; | ||
|
||
public interface IHaveState<TState> where TState : WorkflowState, new() | ||
{ | ||
public TState State { get; init; } | ||
} |
Oops, something went wrong.