Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix testing with DI in Workflow #757

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/WorkflowCore.IntegrationTests/Scenarios/DiScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public abstract class DiScenario : WorkflowTest<DiWorkflow, DiData>
{
protected void ConfigureHost(IServiceProvider serviceProvider)
{
Workflow = serviceProvider.GetService<DiWorkflow>();

PersistenceProvider = serviceProvider.GetService<IPersistenceProvider>();
Host = serviceProvider.GetService<IWorkflowHost>();
Host.RegisterWorkflow<DiWorkflow, DiData>();
Expand All @@ -111,6 +113,7 @@ public DiMsTransientScenario()
services.AddTransient<Dependency1>();
services.AddTransient<Dependency2>();
services.AddTransient<DiStep1>();
services.AddTransient<DiWorkflow>();
services.AddLogging();
ConfigureServices(services);

Expand Down Expand Up @@ -149,6 +152,7 @@ public DiMsScopedScenario()
services.AddScoped<Dependency2>();
services.AddTransient<DiStep1>();
services.AddLogging();
services.AddTransient<DiWorkflow>();
ConfigureServices(services);

var serviceProvider = services.BuildServiceProvider();
Expand Down Expand Up @@ -191,6 +195,7 @@ public DiAutoFacTransientScenario()
builder.RegisterType<Dependency1>().InstancePerDependency();
builder.RegisterType<Dependency2>().InstancePerDependency();
builder.RegisterType<DiStep1>().InstancePerDependency();
builder.RegisterType<DiWorkflow>().InstancePerDependency();
var container = builder.Build();

var serviceProvider = new AutofacServiceProvider(container);
Expand Down Expand Up @@ -233,6 +238,7 @@ public DiAutoFacScopedScenario()
builder.RegisterType<Dependency1>().InstancePerLifetimeScope();
builder.RegisterType<Dependency2>().InstancePerLifetimeScope();
builder.RegisterType<DiStep1>().InstancePerLifetimeScope();
builder.RegisterType<DiWorkflow>().InstancePerLifetimeScope();
var container = builder.Build();

var serviceProvider = new AutofacServiceProvider(container);
Expand Down
6 changes: 3 additions & 3 deletions test/WorkflowCore.Testing/WorkflowCore.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.3.0</Version>
<AssemblyVersion>2.3.0.0</AssemblyVersion>
<FileVersion>2.3.0.0</FileVersion>
<Version>2.3.1</Version>
<AssemblyVersion>2.3.1.0</AssemblyVersion>
<FileVersion>2.3.1.0</FileVersion>
<Description>Facilitates testing of workflows built on Workflow-Core</Description>
</PropertyGroup>

Expand Down
15 changes: 8 additions & 7 deletions test/WorkflowCore.Testing/WorkflowTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -13,18 +11,21 @@
namespace WorkflowCore.Testing
{
public abstract class WorkflowTest<TWorkflow, TData> : IDisposable
where TWorkflow : IWorkflow<TData>, new()
where TWorkflow : class, IWorkflow<TData>
where TData : class, new()
{
protected IWorkflowHost Host;
protected IPersistenceProvider PersistenceProvider;
protected List<StepError> UnhandledStepErrors = new List<StepError>();
protected TWorkflow Workflow;

protected virtual void Setup()
{
//setup dependency injection
IServiceCollection services = new ServiceCollection();
services.AddLogging();
services.AddTransient<TWorkflow>();

ConfigureServices(services);

var serviceProvider = services.BuildServiceProvider();
Expand All @@ -33,6 +34,8 @@ protected virtual void Setup()
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
//loggerFactory.AddConsole(LogLevel.Debug);

Workflow = serviceProvider.GetService<TWorkflow>();

PersistenceProvider = serviceProvider.GetService<IPersistenceProvider>();
Host = serviceProvider.GetService<IWorkflowHost>();
Host.RegisterWorkflow<TWorkflow, TData>();
Expand All @@ -57,15 +60,13 @@ protected virtual void ConfigureServices(IServiceCollection services)

public string StartWorkflow(TData data)
{
var def = new TWorkflow();
var workflowId = Host.StartWorkflow<TData>(def.Id, data).Result;
var workflowId = Host.StartWorkflow<TData>(Workflow.Id, data).Result;
return workflowId;
}

public async Task<string> StartWorkflowAsync(TData data)
{
var def = new TWorkflow();
var workflowId = await Host.StartWorkflow(def.Id, data);
var workflowId = await Host.StartWorkflow(Workflow.Id, data);
return workflowId;
}

Expand Down