WIP #552 - Add unit test to repro
Actually, this unit test does not repro the issue. Frustratingly I can't get it to save the executed workflow into MongoDB at all. I see workflow execution logs being saved, but the instance doesn't go in. I'm not sure if this is a mistake I'm making or whether I have found a different bug of some sort.
This commit is contained in:
parent
cbc7c2d461
commit
672e32a7ca
|
|
@ -13,6 +13,9 @@ environment:
|
|||
|
||||
version: 2.0.0-preview7.{build}
|
||||
|
||||
services:
|
||||
- mongodb
|
||||
|
||||
init:
|
||||
- cmd: git config --global core.autocrlf true
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
using System.Reflection;
|
||||
using AutoFixture;
|
||||
using AutoFixture.Xunit2;
|
||||
using Elsa.Activities.UserTask.Activities;
|
||||
using Elsa.Core.IntegrationTests.Workflows;
|
||||
using Elsa.Persistence.MongoDb.Extensions;
|
||||
using Elsa.Testing.Shared.AutoFixture.Customizations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Elsa.Core.IntegrationTests.Autofixture
|
||||
{
|
||||
public class HostBuilderWithElsaSampleWorkflowAndMongoDbAttribute : CustomizeAttribute
|
||||
{
|
||||
public override ICustomization GetCustomization(ParameterInfo parameter)
|
||||
{
|
||||
return new HostBubilderUsingServicesCustomization(services => {
|
||||
services
|
||||
.AddElsa(elsa => {
|
||||
elsa.UseMongoDbPersistence(opts => {
|
||||
opts.ConnectionString = "mongodb://localhost:27017";
|
||||
opts.Db = "IntegrationTests";
|
||||
});
|
||||
elsa.AddActivity<UserTask>();
|
||||
elsa.AddWorkflow<SampleWorkflow>();
|
||||
})
|
||||
;
|
||||
}, parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
<ProjectReference Include="..\..\..\src\activities\Elsa.Activities.Temporal.Common\Elsa.Activities.Temporal.Common.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\activities\Elsa.Activities.Temporal.Hangfire\Elsa.Activities.Temporal.Hangfire.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\activities\Elsa.Activities.Temporal.Quartz\Elsa.Activities.Temporal.Quartz.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\persistence\Elsa.Persistence.MongoDb\Elsa.Persistence.MongoDb.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
using Xunit;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Core.IntegrationTests.Autofixture;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading;
|
||||
using Elsa.Services;
|
||||
using Elsa.Core.IntegrationTests.Workflows;
|
||||
using Elsa.Persistence;
|
||||
using System;
|
||||
|
||||
namespace Elsa.Core.IntegrationTests.Persistence.MongoDb
|
||||
{
|
||||
public class MongoDbIntegrationTests
|
||||
{
|
||||
[Theory(DisplayName = "A saved workflow instance should be round-trippable without error"), AutoMoqData]
|
||||
public async Task ASavedWorkflowInstanceShouldBeRoundTrippableWithoutError([HostBuilderWithElsaSampleWorkflowAndMongoDbAttribute] IHostBuilder hostBuilder)
|
||||
{
|
||||
hostBuilder.ConfigureServices((ctx, services) => services.AddHostedService<HostedWorkflowRunner>());
|
||||
var host = await hostBuilder.StartAsync();
|
||||
}
|
||||
|
||||
class HostedWorkflowRunner : IHostedService
|
||||
{
|
||||
readonly IWorkflowRunner workflowRunner;
|
||||
readonly IWorkflowInstanceStore instanceStore;
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var instance = await workflowRunner.RunWorkflowAsync<SampleWorkflow>();
|
||||
var retrievedInstance = await instanceStore.FindByIdAsync(instance.Id);
|
||||
|
||||
Assert.NotNull(retrievedInstance);
|
||||
Assert.NotSame(instance, retrievedInstance);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
public HostedWorkflowRunner(IWorkflowRunner workflowRunner, IWorkflowInstanceStore instanceStore)
|
||||
{
|
||||
this.workflowRunner = workflowRunner ?? throw new System.ArgumentNullException(nameof(workflowRunner));
|
||||
this.instanceStore = instanceStore ?? throw new System.ArgumentNullException(nameof(instanceStore));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using Elsa.Activities.UserTask.Activities;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Activities.ControlFlow;
|
||||
|
||||
namespace Elsa.Core.IntegrationTests.Workflows
|
||||
{
|
||||
public class SampleWorkflow : IWorkflow
|
||||
{
|
||||
public static readonly object Result = new object();
|
||||
|
||||
public void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
builder
|
||||
.StartWith<UserTask>(setup: s => {
|
||||
s.Set(x => x.Actions, c => new [] { "Foo", "Bar" });
|
||||
})
|
||||
.Finish(x => x.WithOutput(Result));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue