From 3dfede96d3073de4f32572f44526cf54b1ed2a31 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Tue, 20 Dec 2022 12:13:53 +0100 Subject: [PATCH] Move shared test utility to common folder + various incremental changes --- Elsa.sln | 21 ++++-- README.md | 73 +++++++++++++++++-- src/bundles/Elsa.AllInOne.Web/Program.cs | 5 +- .../Elsa.WorkflowServer.Web/Program.cs | 2 +- .../CapturingTextWriter.cs | 0 .../Elsa.Testing.Shared/CombinedTextWriter.cs | 0 .../Elsa.Testing.Shared.csproj | 9 +-- .../Elsa.Testing.Shared/FodyWeavers.xml | 0 .../TestApplicationBuilder.cs | 0 .../XunitConsoleTextWriter.cs | 0 .../Elsa.Testing.Shared/XunitLogger.cs | 0 .../XunitLoggerProvider.cs | 0 src/modules/Elsa.Http/Features/HttpFeature.cs | 2 +- .../Features/WorkflowsApiFeature.cs | 6 ++ .../Elsa.Samples.HelloWorld.csproj | 25 +++++++ .../aspnet/Elsa.Samples.HelloWorld/Program.cs | 27 +++++++ .../Elsa.IntegrationTests.csproj | 2 +- 17 files changed, 149 insertions(+), 23 deletions(-) rename {test => src/common}/Elsa.Testing.Shared/CapturingTextWriter.cs (100%) rename {test => src/common}/Elsa.Testing.Shared/CombinedTextWriter.cs (100%) rename {test => src/common}/Elsa.Testing.Shared/Elsa.Testing.Shared.csproj (63%) rename {test => src/common}/Elsa.Testing.Shared/FodyWeavers.xml (100%) rename {test => src/common}/Elsa.Testing.Shared/TestApplicationBuilder.cs (100%) rename {test => src/common}/Elsa.Testing.Shared/XunitConsoleTextWriter.cs (100%) rename {test => src/common}/Elsa.Testing.Shared/XunitLogger.cs (100%) rename {test => src/common}/Elsa.Testing.Shared/XunitLoggerProvider.cs (100%) create mode 100644 src/samples/aspnet/Elsa.Samples.HelloWorld/Elsa.Samples.HelloWorld.csproj create mode 100644 src/samples/aspnet/Elsa.Samples.HelloWorld/Program.cs diff --git a/Elsa.sln b/Elsa.sln index c35b8d4a8..8c4ea6dfa 100644 --- a/Elsa.sln +++ b/Elsa.sln @@ -46,8 +46,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.IntegrationTests", "te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.UnitTests", "test\Elsa.UnitTests\Elsa.UnitTests.csproj", "{85A6862B-E523-45FA-A26B-BF98BE140E89}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Testing.Shared", "test\Elsa.Testing.Shared\Elsa.Testing.Shared.csproj", "{6B80C8AC-E9E7-43FD-B514-C0D801D15792}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Labels", "src\modules\Elsa.Labels\Elsa.Labels.csproj", "{80FF5821-E831-450D-AA0C-C76D07D878F4}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "bundles", "bundles", "{F06B9573-DF68-4606-866C-A7546A10A05A}" @@ -120,6 +118,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Email", "src\modules\E EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Workflows.Designer", "src\modules\Elsa.Workflows.Designer\Elsa.Workflows.Designer.csproj", "{B191F11D-583D-44D9-8A08-F5B0DC58B822}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Samples.HelloWorld", "src\samples\aspnet\Elsa.Samples.HelloWorld\Elsa.Samples.HelloWorld.csproj", "{DF8CCA17-6B00-42C6-B4EC-61B42AA91EE0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elsa.Testing.Shared", "src\common\Elsa.Testing.Shared\Elsa.Testing.Shared.csproj", "{AD8C4BB0-C78F-496C-B326-1D82C02C7568}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -166,10 +168,6 @@ Global {85A6862B-E523-45FA-A26B-BF98BE140E89}.Debug|Any CPU.Build.0 = Debug|Any CPU {85A6862B-E523-45FA-A26B-BF98BE140E89}.Release|Any CPU.ActiveCfg = Release|Any CPU {85A6862B-E523-45FA-A26B-BF98BE140E89}.Release|Any CPU.Build.0 = Release|Any CPU - {6B80C8AC-E9E7-43FD-B514-C0D801D15792}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6B80C8AC-E9E7-43FD-B514-C0D801D15792}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6B80C8AC-E9E7-43FD-B514-C0D801D15792}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6B80C8AC-E9E7-43FD-B514-C0D801D15792}.Release|Any CPU.Build.0 = Release|Any CPU {80FF5821-E831-450D-AA0C-C76D07D878F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {80FF5821-E831-450D-AA0C-C76D07D878F4}.Debug|Any CPU.Build.0 = Debug|Any CPU {80FF5821-E831-450D-AA0C-C76D07D878F4}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -306,6 +304,14 @@ Global {B191F11D-583D-44D9-8A08-F5B0DC58B822}.Debug|Any CPU.Build.0 = Debug|Any CPU {B191F11D-583D-44D9-8A08-F5B0DC58B822}.Release|Any CPU.ActiveCfg = Release|Any CPU {B191F11D-583D-44D9-8A08-F5B0DC58B822}.Release|Any CPU.Build.0 = Release|Any CPU + {DF8CCA17-6B00-42C6-B4EC-61B42AA91EE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF8CCA17-6B00-42C6-B4EC-61B42AA91EE0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF8CCA17-6B00-42C6-B4EC-61B42AA91EE0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF8CCA17-6B00-42C6-B4EC-61B42AA91EE0}.Release|Any CPU.Build.0 = Release|Any CPU + {AD8C4BB0-C78F-496C-B326-1D82C02C7568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AD8C4BB0-C78F-496C-B326-1D82C02C7568}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD8C4BB0-C78F-496C-B326-1D82C02C7568}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AD8C4BB0-C78F-496C-B326-1D82C02C7568}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {155227F0-A33B-40AA-A4B4-06F813EB921B} = {61017E64-6D00-49CB-9E81-5002DC8F7D5F} @@ -315,7 +321,6 @@ Global {5BA4A8FA-F7F4-45B3-AEC8-8886D35AAC79} = {61017E64-6D00-49CB-9E81-5002DC8F7D5F} {B066ED0A-86E0-4025-85C2-7E8F7139D8A4} = {90031D64-CA0F-46D0-9AF4-8DC023A5FFCD} {85A6862B-E523-45FA-A26B-BF98BE140E89} = {90031D64-CA0F-46D0-9AF4-8DC023A5FFCD} - {6B80C8AC-E9E7-43FD-B514-C0D801D15792} = {90031D64-CA0F-46D0-9AF4-8DC023A5FFCD} {F06B9573-DF68-4606-866C-A7546A10A05A} = {61017E64-6D00-49CB-9E81-5002DC8F7D5F} {448FCDE6-DE44-4E44-A1CC-B9AA51471121} = {C6658DE0-2B2F-47F0-BB61-2CA66D435C09} {B2049499-D384-46DF-8837-F1180107DD54} = {5BA4A8FA-F7F4-45B3-AEC8-8886D35AAC79} @@ -360,5 +365,7 @@ Global {555A4306-3BAB-409E-8BB8-3171A5867B2C} = {5BA4A8FA-F7F4-45B3-AEC8-8886D35AAC79} {1E5BD8D9-55BE-41E2-B389-6AB9F26C22AF} = {5BA4A8FA-F7F4-45B3-AEC8-8886D35AAC79} {B191F11D-583D-44D9-8A08-F5B0DC58B822} = {5BA4A8FA-F7F4-45B3-AEC8-8886D35AAC79} + {DF8CCA17-6B00-42C6-B4EC-61B42AA91EE0} = {56C2FFB8-EA54-45B5-A095-4A78142EB4B5} + {AD8C4BB0-C78F-496C-B326-1D82C02C7568} = {C6658DE0-2B2F-47F0-BB61-2CA66D435C09} EndGlobalSection EndGlobal diff --git a/README.md b/README.md index 38492f895..0868a7686 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,14 @@ Here are some of the more important features offered by Elsa: - Execute workflows in any .NET app. - Supports both short-running and long-running workflows. -- Programming model loosely inspired on WF4 (composable activities) -- Support for complex activities such as Sequence and Flowchart. +- Programming model loosely inspired on WF4 (composable activities). +- Support for complex activities such as Sequence, Flowchart and custom composite activities (which are like mini-workflows that can be used as activities). - Ships with a workflows designer web component (currently supports Flowchart diagrams only). -## Examples +## Console Examples + +### Hello World -### Hello World: Console The following is a simple Hello World workflow created as a console application. The workflow is created using C#. ```csharp @@ -60,4 +61,66 @@ Outputs: ```shell Hello World! -``` \ No newline at end of file +``` + +### Sequential workflows + +To build workflows that execute more than one step, choose an activity that can do so. For example, the `Sequence` activity lets us add multiple activities to execute in sequence (plumbing code left out for brevity): + +```csharp +// Create a workflow. +var workflow = new Sequence +{ + Activities = + { + new WriteLine("Hello World!"), + new WriteLine("Goodbye cruel world...") + } +}; +``` + +Outputs: + +```shell +Hello World! +Goodbye cruel world... +``` + +### Conditions + +The following demonstrates a workflow where it asks the user to enter their age, and based on this, offers a beer or a soda: + +```csharp +// Declare a workflow variable for use in the workflow. +var ageVariable = new Variable(); + +// Declare a workflow. +var workflow = new Sequence +{ + // Register the variable. + Variables = { ageVariable }, + + // Setup the sequence of activities to run. + Activities = + { + new WriteLine("Please tell me your age:"), + new ReadLine(ageVariable), // Stores user input into the provided variable., + new If + { + // If aged 18 or up, beer is provided, soda otherwise. + Condition = new Input(context => ageVariable.Get(context) < 18), + Then = new WriteLine("Enjoy your soda!"), + Else = new WriteLine("Enjoy your beer!") + }, + new WriteLine("Come again!") + } +}; +``` + +Notice that: + +- To capture activity output, a workflow variable (ageVariable) is used. +- Depending on the result of the condition of the `If` activity, either the `Then` or the `Else` activity is executed. +- After the If activity completes, the final WriteLine activity is executed. + + ## ASP.NET Examples \ No newline at end of file diff --git a/src/bundles/Elsa.AllInOne.Web/Program.cs b/src/bundles/Elsa.AllInOne.Web/Program.cs index 021121133..aba5d9d47 100644 --- a/src/bundles/Elsa.AllInOne.Web/Program.cs +++ b/src/bundles/Elsa.AllInOne.Web/Program.cs @@ -63,9 +63,7 @@ services .UseLiquid() .UseHttp() .UseActivityDefinitions() - ) - // Register FastEndpoints using collected assemblies from features. - .AddFastEndpointsFromModule(); + ); services.AddHealthChecks(); @@ -105,4 +103,5 @@ app.UseEndpoints(endpoints => endpoints.MapFallbackToPage("/Index"); }); +app.MapRazorPages(); app.Run(); \ No newline at end of file diff --git a/src/bundles/Elsa.WorkflowServer.Web/Program.cs b/src/bundles/Elsa.WorkflowServer.Web/Program.cs index b464719b1..5a108c60e 100644 --- a/src/bundles/Elsa.WorkflowServer.Web/Program.cs +++ b/src/bundles/Elsa.WorkflowServer.Web/Program.cs @@ -77,7 +77,7 @@ services .UseJavaScript() .UseLiquid() .UseHttp() - ).AddFastEndpointsFromModule(); + ); services.AddHealthChecks(); services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin())); diff --git a/test/Elsa.Testing.Shared/CapturingTextWriter.cs b/src/common/Elsa.Testing.Shared/CapturingTextWriter.cs similarity index 100% rename from test/Elsa.Testing.Shared/CapturingTextWriter.cs rename to src/common/Elsa.Testing.Shared/CapturingTextWriter.cs diff --git a/test/Elsa.Testing.Shared/CombinedTextWriter.cs b/src/common/Elsa.Testing.Shared/CombinedTextWriter.cs similarity index 100% rename from test/Elsa.Testing.Shared/CombinedTextWriter.cs rename to src/common/Elsa.Testing.Shared/CombinedTextWriter.cs diff --git a/test/Elsa.Testing.Shared/Elsa.Testing.Shared.csproj b/src/common/Elsa.Testing.Shared/Elsa.Testing.Shared.csproj similarity index 63% rename from test/Elsa.Testing.Shared/Elsa.Testing.Shared.csproj rename to src/common/Elsa.Testing.Shared/Elsa.Testing.Shared.csproj index 4e958a5c9..7539b5666 100644 --- a/test/Elsa.Testing.Shared/Elsa.Testing.Shared.csproj +++ b/src/common/Elsa.Testing.Shared/Elsa.Testing.Shared.csproj @@ -1,7 +1,7 @@ - - + + net6.0 @@ -12,12 +12,11 @@ - + - - + diff --git a/test/Elsa.Testing.Shared/FodyWeavers.xml b/src/common/Elsa.Testing.Shared/FodyWeavers.xml similarity index 100% rename from test/Elsa.Testing.Shared/FodyWeavers.xml rename to src/common/Elsa.Testing.Shared/FodyWeavers.xml diff --git a/test/Elsa.Testing.Shared/TestApplicationBuilder.cs b/src/common/Elsa.Testing.Shared/TestApplicationBuilder.cs similarity index 100% rename from test/Elsa.Testing.Shared/TestApplicationBuilder.cs rename to src/common/Elsa.Testing.Shared/TestApplicationBuilder.cs diff --git a/test/Elsa.Testing.Shared/XunitConsoleTextWriter.cs b/src/common/Elsa.Testing.Shared/XunitConsoleTextWriter.cs similarity index 100% rename from test/Elsa.Testing.Shared/XunitConsoleTextWriter.cs rename to src/common/Elsa.Testing.Shared/XunitConsoleTextWriter.cs diff --git a/test/Elsa.Testing.Shared/XunitLogger.cs b/src/common/Elsa.Testing.Shared/XunitLogger.cs similarity index 100% rename from test/Elsa.Testing.Shared/XunitLogger.cs rename to src/common/Elsa.Testing.Shared/XunitLogger.cs diff --git a/test/Elsa.Testing.Shared/XunitLoggerProvider.cs b/src/common/Elsa.Testing.Shared/XunitLoggerProvider.cs similarity index 100% rename from test/Elsa.Testing.Shared/XunitLoggerProvider.cs rename to src/common/Elsa.Testing.Shared/XunitLoggerProvider.cs diff --git a/src/modules/Elsa.Http/Features/HttpFeature.cs b/src/modules/Elsa.Http/Features/HttpFeature.cs index d14b5cc41..5dfd23ec0 100644 --- a/src/modules/Elsa.Http/Features/HttpFeature.cs +++ b/src/modules/Elsa.Http/Features/HttpFeature.cs @@ -34,7 +34,7 @@ public class HttpFeature : FeatureBase typeof(HttpRequestHeaders), typeof(HttpRequestModel), typeof(HttpResponseModel) - }, "HTTP")); + }, "HTTP").AddActivitiesFrom()); } /// diff --git a/src/modules/Elsa.Workflows.Api/Features/WorkflowsApiFeature.cs b/src/modules/Elsa.Workflows.Api/Features/WorkflowsApiFeature.cs index 9e0e432cc..feeec1385 100644 --- a/src/modules/Elsa.Workflows.Api/Features/WorkflowsApiFeature.cs +++ b/src/modules/Elsa.Workflows.Api/Features/WorkflowsApiFeature.cs @@ -19,4 +19,10 @@ public class WorkflowsApiFeature : FeatureBase { Module.AddFastEndpointsAssembly(GetType()); } + + /// + public override void Apply() + { + Module.AddFastEndpointsFromModule(); + } } \ No newline at end of file diff --git a/src/samples/aspnet/Elsa.Samples.HelloWorld/Elsa.Samples.HelloWorld.csproj b/src/samples/aspnet/Elsa.Samples.HelloWorld/Elsa.Samples.HelloWorld.csproj new file mode 100644 index 000000000..9b0eff4b6 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.HelloWorld/Elsa.Samples.HelloWorld.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + + diff --git a/src/samples/aspnet/Elsa.Samples.HelloWorld/Program.cs b/src/samples/aspnet/Elsa.Samples.HelloWorld/Program.cs new file mode 100644 index 000000000..03c164d90 --- /dev/null +++ b/src/samples/aspnet/Elsa.Samples.HelloWorld/Program.cs @@ -0,0 +1,27 @@ +using Elsa.Extensions; +using Elsa.Http.Extensions; +using Elsa.Workflows.Management.Extensions; + +var builder = WebApplication.CreateBuilder(args); +var services = builder.Services; + +// Add Elsa services. +services.AddElsa(elsa => elsa + + .UseWorkflowManagement() + + // Enable Elsa HTTP module (for HTTP related activities). + .UseHttp() +); + +// Configure middleware pipeline. +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) + app.UseDeveloperExceptionPage(); + +// Add Elsa HTTP middleware (to handle requests mapped to HTTP Endpoint activities) +app.UseHttpActivities(); + +// Run. +app.Run(); \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Elsa.IntegrationTests.csproj b/test/Elsa.IntegrationTests/Elsa.IntegrationTests.csproj index d27083351..89aee739e 100644 --- a/test/Elsa.IntegrationTests/Elsa.IntegrationTests.csproj +++ b/test/Elsa.IntegrationTests/Elsa.IntegrationTests.csproj @@ -21,8 +21,8 @@ + -