Add project files.
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
using Elsa.Expressions.Models;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Models;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.CanExecute.Activities;
|
||||
|
||||
public class CustomActivity : CodeActivity
|
||||
{
|
||||
public CustomActivity(int magicNumber)
|
||||
{
|
||||
MagicNumber = new (magicNumber);
|
||||
}
|
||||
|
||||
public CustomActivity(Func<ExpressionExecutionContext, int> magicNumber)
|
||||
{
|
||||
MagicNumber = new (magicNumber);
|
||||
}
|
||||
|
||||
public Input<int> MagicNumber { get; set; }
|
||||
|
||||
protected override bool CanExecute(ActivityExecutionContext context)
|
||||
{
|
||||
var magicNumber = MagicNumber.Get(context);
|
||||
return magicNumber == 42;
|
||||
}
|
||||
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
{
|
||||
var provider = context.GetService<IStandardOutStreamProvider>() ?? new StandardOutStreamProvider(Console.Out);
|
||||
var textWriter = provider.GetTextWriter();
|
||||
textWriter.WriteLine("Welcome to the world of Might and Magic!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Elsa.Testing.Shared;
|
||||
using Elsa.Workflows.IntegrationTests.Scenarios.CanExecute.Activities;
|
||||
using Elsa.Workflows.IntegrationTests.Scenarios.CanExecute.Workflows;
|
||||
using Elsa.Workflows.Options;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.CanExecute;
|
||||
|
||||
public class CanExecuteTests
|
||||
{
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
|
||||
public CanExecuteTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
_services = new TestApplicationBuilder(testOutputHelper)
|
||||
.WithCapturingTextWriter(_capturingTextWriter)
|
||||
.AddActivitiesFrom<CustomActivity>()
|
||||
.Build();
|
||||
|
||||
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[Theory(DisplayName = "Activities are executed only when they report that they can execute.")]
|
||||
[InlineData(12, "Magic number is 12")]
|
||||
[InlineData(42, "Magic number is 42\nWelcome to the world of Might and Magic!\nDone")]
|
||||
public async Task Test1(int magicNumber, string expectedLines)
|
||||
{
|
||||
await _services.PopulateRegistriesAsync();
|
||||
var runOptions = new RunWorkflowOptions
|
||||
{
|
||||
Input = new Dictionary<string, object>
|
||||
{
|
||||
["MagicNumber"] = magicNumber
|
||||
}
|
||||
};
|
||||
await _workflowRunner.RunAsync<MagicWorkflow>(runOptions);
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal(expectedLines.Split('\n', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries), lines);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Activities;
|
||||
using Elsa.Workflows.IntegrationTests.Scenarios.CanExecute.Activities;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.CanExecute.Workflows;
|
||||
|
||||
public class MagicWorkflow : WorkflowBase
|
||||
{
|
||||
protected override void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
var magicNumberVariable = builder.WithVariable<int>();
|
||||
|
||||
builder.Root = new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new SetVariable<int>(magicNumberVariable, context => context.GetInput<int>("MagicNumber")),
|
||||
new WriteLine(context => $"Magic number is {magicNumberVariable.Get(context)}"),
|
||||
new CustomActivity(context => magicNumberVariable.Get(context)),
|
||||
new WriteLine("Done")
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user