2022-04-12 13:55:35 +00:00
|
|
|
using System;
|
|
|
|
|
using Elsa.Extensions;
|
2022-06-04 18:01:20 +00:00
|
|
|
using Elsa.Workflows.Core;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Workflows.Core.Implementations;
|
|
|
|
|
using Elsa.Workflows.Core.Services;
|
2022-04-12 13:55:35 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Testing.Shared;
|
|
|
|
|
|
2022-04-18 13:48:21 +00:00
|
|
|
public class TestApplicationBuilder
|
2022-04-12 13:55:35 +00:00
|
|
|
{
|
2022-04-12 15:08:31 +00:00
|
|
|
private readonly ITestOutputHelper _testOutputHelper;
|
|
|
|
|
private readonly ServiceCollection _services;
|
|
|
|
|
|
2022-04-18 13:48:21 +00:00
|
|
|
public TestApplicationBuilder(ITestOutputHelper testOutputHelper)
|
2022-04-12 13:55:35 +00:00
|
|
|
{
|
2022-04-12 15:08:31 +00:00
|
|
|
_testOutputHelper = testOutputHelper;
|
|
|
|
|
_services = new ServiceCollection();
|
2022-06-04 18:01:20 +00:00
|
|
|
|
|
|
|
|
_services.AddElsa(elsa => elsa
|
|
|
|
|
.UseWorkflows(workflows => workflows
|
|
|
|
|
.WithStandardOutStreamProvider(_ => new StandardOutStreamProvider(new XunitConsoleTextWriter(testOutputHelper)))
|
|
|
|
|
)
|
|
|
|
|
);
|
2022-04-12 13:55:35 +00:00
|
|
|
|
2022-04-12 15:08:31 +00:00
|
|
|
_services
|
|
|
|
|
.AddSingleton(testOutputHelper)
|
2022-04-12 13:55:35 +00:00
|
|
|
.AddLogging(logging => logging.AddProvider(new XunitLoggerProvider(testOutputHelper)).SetMinimumLevel(LogLevel.Debug));
|
2022-04-12 15:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IServiceProvider Build() => _services.BuildServiceProvider();
|
2022-04-12 13:55:35 +00:00
|
|
|
|
2022-04-18 13:48:21 +00:00
|
|
|
public TestApplicationBuilder Configure(Action<IServiceCollection> configure)
|
2022-04-12 15:08:31 +00:00
|
|
|
{
|
|
|
|
|
configure(_services);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2022-04-12 13:55:35 +00:00
|
|
|
|
2022-04-18 13:48:21 +00:00
|
|
|
public TestApplicationBuilder WithCapturingTextWriter(CapturingTextWriter capturingTextWriter)
|
2022-04-12 15:08:31 +00:00
|
|
|
{
|
|
|
|
|
var combinedTextWriter = new CombinedTextWriter(capturingTextWriter, new XunitConsoleTextWriter(_testOutputHelper));
|
|
|
|
|
_services.AddSingleton<IStandardOutStreamProvider>(new StandardOutStreamProvider(combinedTextWriter));
|
|
|
|
|
return this;
|
2022-04-12 13:55:35 +00:00
|
|
|
}
|
|
|
|
|
}
|