-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathAllurePlugin.cs
96 lines (85 loc) · 3.16 KB
/
AllurePlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System.Collections.Generic;
using Allure.ReqnrollPlugin.Configuration;
using Allure.ReqnrollPlugin.Events;
using Allure.ReqnrollPlugin.SelectiveRun;
using Allure.ReqnrollPlugin.State;
using Reqnroll;
using Reqnroll.BoDi;
using Reqnroll.Events;
using Reqnroll.Infrastructure;
using Reqnroll.Plugins;
using Reqnroll.UnitTestProvider;
[assembly: RuntimePlugin(typeof(Allure.ReqnrollPlugin.AllurePlugin))]
namespace Allure.ReqnrollPlugin;
public class AllurePlugin : IRuntimePlugin
{
public void Initialize(
RuntimePluginEvents runtimePluginEvents,
RuntimePluginParameters runtimePluginParameters,
UnitTestProviderConfiguration unitTestProviderConfiguration
)
{
runtimePluginEvents.CustomizeTestThreadDependencies += SetupAllure;
}
static void SetupAllure(
object _,
CustomizeTestThreadDependenciesEventArgs args
)
{
var container = args.ObjectContainer;
SetUpTestPlanSupport(container);
RegisterEventHandlers(container);
}
static void RegisterEventHandlers(IObjectContainer container)
{
if (!container.IsRegistered<ITestThreadExecutionEventPublisher>())
{
return;
}
var publisher = container.Resolve<ITestThreadExecutionEventPublisher>();
foreach (var handler in CreateHandlers(container))
{
handler.Register(publisher);
}
}
static void SetUpTestPlanSupport(ObjectContainer container)
{
var type = AllureReqnrollConfiguration.CurrentConfig.RunnerType;
container.RegisterFactoryAs<ITestRunner>(
() => new TestPlanAwareTestRunner(
container.Resolve<IUnitTestRuntimeProvider>(),
container.Resolve<ITestRunnerManager>(),
container.Resolve<ITestRunner>(type.FullName)
)
);
container.RegisterTypeAs<ITestRunner>(type, type.FullName);
}
static IEnumerable<AllureReqnrollEventHandler> CreateHandlers(
IObjectContainer container
)
{
yield return new TestRunStartedEventHandler(stateTransportFactory);
yield return new HookStartedEventHandler(
stateTransportFactory,
runnerManagerFactory,
contextFactory
);
yield return new HookBindingStartedEventHandler(stateTransportFactory);
yield return new HookBindingFinishedEventHandler(stateTransportFactory);
yield return new HookFinishedEventHandler(
stateTransportFactory,
runnerManagerFactory
);
yield return new StepStartedEventHandler(stateTransportFactory);
yield return new StepFinishedEventHandler(stateTransportFactory);
yield return new ScenarioFinishedEventHandle(stateTransportFactory);
yield return new FeatureFinishedEventHandler(stateTransportFactory);
CrossBindingContextTransport stateTransportFactory() => new(
container.Resolve<IContextManager>()
);
ITestRunnerManager runnerManagerFactory() =>
container.Resolve<ITestRunnerManager>();
IContextManager contextFactory() =>
container.Resolve<IContextManager>();
}
}