elsa-core/test/shared/Elsa.Testing.Shared/AutoFixture/SpecimenBuilders/StubActivityExecutionContextSpecimenBuilder.cs
Craig Fowler 282c90f80f Further fixup & refactoring of Autofixture attribs
This now also includes reworking the attribute which activates
Autofixture-style resolution upon an IServiceProvider.
This has now been renamed to WithAutofixtureResolutionAttribute.

The new/reworked attribute is composable with other Autofixture
attributes.
2021-04-02 13:28:27 +01:00

33 lines
1.4 KiB
C#

using System;
using AutoFixture.Kernel;
using Elsa.Models;
using Elsa.Services.Models;
using Moq;
namespace Elsa.Testing.Shared.AutoFixture.SpecimenBuilders
{
public class StubActivityExecutionContextSpecimenBuilder : ISpecimenBuilder
{
public object Create(object request, ISpecimenContext context)
{
if(!request.IsAnAutofixtureRequestForType<ActivityExecutionContext>())
return new NoSpecimen();
var serviceProvider = GetServiceProvider(context);
var workflowExecutionContext = GetWorkflowExecutionContext(context, serviceProvider);
return new ActivityExecutionContext(serviceProvider,
workflowExecutionContext,
Mock.Of<IActivityBlueprint>(),
default,
default,
default);
}
static IServiceProvider GetServiceProvider(ISpecimenContext context)
=> (IServiceProvider) new AutofixtureResolutionServiceProviderSpecimenBuilder().Create(typeof(IServiceProvider), context);
static WorkflowExecutionContext GetWorkflowExecutionContext(ISpecimenContext context, IServiceProvider serviceProvider)
=> new WorkflowExecutionContext(serviceProvider, Mock.Of<IWorkflowBlueprint>(), new WorkflowInstance());
}
}