Fix tests

This commit is contained in:
Sipke Schoorstra 2021-04-02 12:42:46 +02:00
parent 1dfa36b9c8
commit 881f0acb7a
8 changed files with 51 additions and 36 deletions

View file

@ -11,6 +11,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Autofixture/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Configurer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Interruptor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Materializer/@EntryIndexedValue">True</s:Boolean>

View file

@ -8,17 +8,20 @@ namespace Elsa
public static class ElsaOptionsExtensions
{
/// <summary>
/// Adds temporal (time-based) activities to Elsa, using the Quartz implementation.
/// Adds temporal (time-based) activities to Elsa using the Quartz implementation. Also registers Quartz services itself.
/// </summary>
/// <param name="options">Elsa options</param>
/// <param name="configure">An optional Quartz configuration callback</param>
/// <param name="configureQuartzOptions"></param>
/// <param name="configureQuartz">An optional service collection Quartz configuration callback</param>
/// <param name="configureQuartzHostedService">Use this callback to further configure the Quartz hosted service</param>
/// <returns>The Elsa options, enabling method chaining</returns>
public static ElsaOptions AddQuartzTemporalActivities(this ElsaOptions options,
Action<QuartzOptions>? configure = default,
Action<IServiceCollectionQuartzConfigurator>? configureQuartz = default)
public static ElsaOptions AddQuartzTemporalActivities(
this ElsaOptions options,
Action<QuartzOptions>? configureQuartzOptions = default,
Action<IServiceCollectionQuartzConfigurator>? configureQuartz = default,
Action<QuartzHostedServiceOptions>? configureQuartzHostedService = default)
{
CommonTemporalActivityServices.AddCommonTemporalActivities(options, timer => timer.UseQuartzProvider(configure, configureQuartz));
CommonTemporalActivityServices.AddCommonTemporalActivities(options, timer => timer.UseQuartzProvider(true, configureQuartzOptions, configureQuartz, configureQuartzHostedService));
return options;
}
}

View file

@ -12,34 +12,34 @@ namespace Elsa
public static class TimersOptionsExtensions
{
/// <summary>
/// Add Elsa Quartz services.
/// Add Elsa Quartz services and Quartz services.
/// </summary>
public static void UseQuartzProvider(this TimersOptions timersOptions)
/// <param name="timersOptions">The timer options being configured.</param>
/// <param name="registerQuartz">True to automatically register Quartz services. When false, make sure to register Quartz yourself.</param>
/// <param name="configureQuartzOptions">When <see cref="registerQuartz"/> is true, you can use this callback to further configure Quartz options.</param>
/// <param name="configureQuartz">When <see cref="registerQuartz"/> is true, you can use this callback to further configure Quartz.</param>
/// <param name="configureQuartzHostedService">When <see cref="registerQuartz"/> is true, you can use this callback to further configure the Quartz hosted service.</param>
public static void UseQuartzProvider(
this TimersOptions timersOptions,
bool registerQuartz = true,
Action<QuartzOptions>? configureQuartzOptions = default,
Action<IServiceCollectionQuartzConfigurator>? configureQuartz = default,
Action<QuartzHostedServiceOptions>? configureQuartzHostedService = default)
{
timersOptions.Services
.AddSingleton<IWorkflowScheduler, QuartzWorkflowScheduler>()
.AddSingleton<ICrontabParser, QuartzCrontabParser>()
.AddTransient<RunQuartzWorkflowJob>();
}
/// <summary>
/// Add Elsa Hangfire Services and Quartz services.
/// </summary>
/// <remarks>
/// Use only if Quartz is not already registered in DI.
/// </remarks>
public static void UseQuartzProvider(
this TimersOptions timersOptions,
Action<QuartzOptions> configureOptions,
Action<IServiceCollectionQuartzConfigurator>? configureQuartz = default,
Action<QuartzHostedServiceOptions>? configureQuartzHostedService = default)
{
timersOptions.UseQuartzProvider();
timersOptions.Services.Configure(configureOptions);
timersOptions.Services
.AddQuartz(configure => ConfigureQuartz(configure, configureQuartz))
.AddQuartzHostedService(options => ConfigureQuartzHostedService(options, configureQuartzHostedService));
if (registerQuartz)
{
if (configureQuartzOptions != null)
timersOptions.Services.Configure(configureQuartzOptions);
timersOptions.Services
.AddQuartz(configure => ConfigureQuartz(configure, configureQuartz))
.AddQuartzHostedService(options => ConfigureQuartzHostedService(options, configureQuartzHostedService));
}
}
private static void ConfigureQuartzHostedService(QuartzHostedServiceOptions options, Action<QuartzHostedServiceOptions>? configureQuartzHostedService)
@ -54,7 +54,7 @@ namespace Elsa
quartz.AddJob<RunQuartzWorkflowJob>(job => job.StoreDurably().WithIdentity(nameof(RunQuartzWorkflowJob)));
quartz.UseSimpleTypeLoader();
quartz.UseInMemoryStore();
configureQuartz?.Invoke(quartz);
}
}

View file

@ -4,7 +4,7 @@ using AutoFixture.Xunit2;
using Elsa.Testing.Shared.AutoFixture.Customizations;
using Microsoft.Extensions.DependencyInjection;
namespace Elsa.Core.IntegrationTests.Extensions
namespace Elsa.Core.IntegrationTests.Autofixture
{
public class HostBuilderWithElsaAndQuartzAttribute : CustomizeAttribute
{

View file

@ -3,6 +3,7 @@ using Microsoft.Extensions.Hosting;
using Xunit;
using System.Threading.Tasks;
using System.Threading;
using Elsa.Core.IntegrationTests.Autofixture;
using Elsa.Core.IntegrationTests.Extensions;
namespace Elsa.UnitTests.Extensions

View file

@ -9,10 +9,11 @@ namespace Elsa.Services
public class ActivityExecutionContextForActivityBlueprintFactoryTests
{
[Theory(DisplayName = "The CreateActivityExecutionContext method should create a context using the activity blueprint, the workflow execution context, cancellation token and injected service provider."), AutoMoqData]
public void CreateActivityExecutionContextCreatesContextUsingBlueprintExecutionContextCancellationTokenAndServiceProvider([AutofixtureServiceProvider] IServiceProvider serviceProvider,
IActivityBlueprint activityBlueprint,
[OmitOnRecursion] WorkflowExecutionContext workflowExecutionContext,
CancellationToken cancellationToken)
public void CreateActivityExecutionContextCreatesContextUsingBlueprintExecutionContextCancellationTokenAndServiceProvider(
[AutofixtureServiceProvider] IServiceProvider serviceProvider,
IActivityBlueprint activityBlueprint,
[OmitOnRecursion] WorkflowExecutionContext workflowExecutionContext,
CancellationToken cancellationToken)
{
var sut = new ActivityExecutionContextForActivityBlueprintFactory(serviceProvider);

View file

@ -2,6 +2,7 @@ using Xunit;
using Elsa.Testing.Shared.AutoFixture.Attributes;
using AutoFixture.Xunit2;
using System;
using System.Threading;
namespace Elsa.Services.Models
{
@ -9,12 +10,15 @@ namespace Elsa.Services.Models
{
[Theory(DisplayName = "The PurgeVariables method should clear the Variables instance associated with the WorkflowInstance associated with the Workflow Execution Context"), AutoMoqData]
public void PurgeVariables_clears_workflow_execution_context_workflow_instance_variables(
[OmitOnRecursion, NoAutoProperties] ActivityExecutionContext sut,
[AutofixtureServiceProvider] IServiceProvider serviceProvider,
[OmitOnRecursion] WorkflowExecutionContext workflowExecutionContext,
IActivityBlueprint activityBlueprint,
CancellationToken cancellationToken,
string variableName,
object variableValue)
{
var sut = new ActivityExecutionContext(serviceProvider, workflowExecutionContext, activityBlueprint, null, false, cancellationToken);
sut.WorkflowExecutionContext.WorkflowInstance.Variables.Set(variableName, variableValue);
sut.PurgeVariables();
Assert.Empty(sut.WorkflowExecutionContext.WorkflowInstance.Variables.Data);

View file

@ -2,6 +2,7 @@ using Xunit;
using Elsa.Testing.Shared.AutoFixture.Attributes;
using AutoFixture.Xunit2;
using System;
using System.Threading;
namespace Elsa.Services.Models
{
@ -9,10 +10,14 @@ namespace Elsa.Services.Models
{
[Theory(DisplayName = "The PurgeVariables method should clear the Variables instance associated with the WorkflowInstance"), AutoMoqData]
public void PurgeVariables_clears_workflow_execution_context_workflow_instance_variables(
[OmitOnRecursion, NoAutoProperties] WorkflowExecutionContext sut,
[AutofixtureServiceProvider] IServiceProvider serviceProvider,
[OmitOnRecursion] WorkflowExecutionContext workflowExecutionContext,
IActivityBlueprint activityBlueprint,
CancellationToken cancellationToken,
string variableName,
object variableValue)
{
var sut = new ActivityExecutionContext(serviceProvider, workflowExecutionContext, activityBlueprint, null, false, cancellationToken);
sut.WorkflowInstance.Variables.Set(variableName, variableValue);
sut.PurgeVariables();