From 833c668e72c15ef1044fd23f89f17a2934983c95 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 13:38:46 +0700 Subject: [PATCH 01/14] feat(sdk): simplify generic registration types --- .../AllureInProcessEndpointRegistration.cs | 17 +- .../AllureRuntimeRegistrationSnapshot.cs | 12 +- .../PreparedRuntimeRegistration.cs | 37 +-- .../AllureInProcessRouteBuilder.cs | 84 +++--- .../AllureRegistrationDefaults.cs | 29 +- .../Registration/AllureRouteBuilderArgs.cs | 5 +- .../Registration/AllureRuntimeBuilder.cs | 184 +++++-------- .../AllureRuntimeIntegrationSnapshot.cs | 40 +-- .../AllureRuntimeRegistrationSession.cs | 260 +++++------------- .../Hooks/IAllureEndpointRegistrationHook.cs | 20 -- ...AllureInProcessEndpointRegistrationHook.cs | 40 --- .../Hooks/IAllureRegistrationHook.cs | 14 + .../Hooks/IAllureRuntimeRegistrationHook.cs | 28 -- .../IAllureEndpointIntegrationContext.cs | 14 +- ...lureInProcessEndpointIntegrationContext.cs | 50 +--- ...ureInProcessEndpointRegistrationContext.cs | 26 +- .../IAllureRuntimeIntegrationContext.cs | 75 ++--- .../IAllureRuntimeIntegrationSnapshot.cs | 52 +--- .../IAllureRuntimeRegistrationContext.cs | 7 - .../IPreparedInProcessRouteBuilder.cs | 8 + .../Infrastructure/RuntimeTestEnvironment.cs | 96 ++----- .../AllureRuntimeRegistrationTests.cs | 54 +--- .../InProcessEndpointRegistrationTests.cs | 60 +--- .../Registration/RegistrationHookTests.cs | 37 +-- .../Serialization/SerializerSelectionTests.cs | 8 +- 25 files changed, 346 insertions(+), 911 deletions(-) delete mode 100644 src/Allure.Net.Sdk/Registration/Hooks/IAllureEndpointRegistrationHook.cs delete mode 100644 src/Allure.Net.Sdk/Registration/Hooks/IAllureInProcessEndpointRegistrationHook.cs create mode 100644 src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs delete mode 100644 src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs create mode 100644 src/Allure.Net.Sdk/Registration/IPreparedInProcessRouteBuilder.cs diff --git a/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessEndpointRegistration.cs b/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessEndpointRegistration.cs index ee55ffa3..9b950c23 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessEndpointRegistration.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessEndpointRegistration.cs @@ -1,29 +1,16 @@ using System; using Allure.Sdk.Configuration; using Allure.Sdk.Registration; -using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Runtime; namespace Allure.Sdk.Internal.Registration; -internal record class AllureInProcessEndpointRegistration< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime ->( +internal record class AllureInProcessEndpointRegistration( string Id, Action< TRuntime, - IAllureInProcessEndpointIntegrationContext< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > + IAllureInProcessEndpointIntegrationContext > Registration ) where TConfiguration : AllureConfiguration - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext - where TEndpointHook : IAllureInProcessEndpointRegistrationHook where TRuntime : IAllureRuntime; diff --git a/src/Allure.Net.Sdk/Internal/Registration/AllureRuntimeRegistrationSnapshot.cs b/src/Allure.Net.Sdk/Internal/Registration/AllureRuntimeRegistrationSnapshot.cs index b8e4d17d..8eef062d 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/AllureRuntimeRegistrationSnapshot.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/AllureRuntimeRegistrationSnapshot.cs @@ -3,18 +3,12 @@ using Allure.Abstractions; using Allure.Sdk.Configuration; using Allure.Sdk.Registration; -using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Results; using Allure.Sdk.Runtime; namespace Allure.Sdk.Internal.Registration; -internal sealed record AllureRuntimeRegistrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime ->( +internal sealed record AllureRuntimeRegistrationSnapshot( Func, IAllureExecutionContext> ContextFactory, Func, IAllureLifecycleApi> LifecycleApiFactory, Func, IAllureModelApi> ModelApiFactory, @@ -22,9 +16,7 @@ internal sealed record AllureRuntimeRegistrationSnapshot< Func SerializerFactory, Func DestinationFactory, ImmutableArray> RuleBasedSerializerRegistrations, - AllureInProcessEndpointRegistration? EndpointRegistration + AllureInProcessEndpointRegistration? EndpointRegistration ) where TConfiguration : AllureConfiguration - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext - where TEndpointHook : IAllureInProcessEndpointRegistrationHook where TRuntime : IAllureRuntime; diff --git a/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs b/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs index 294e472c..c6836cae 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs @@ -8,41 +8,15 @@ namespace Allure.Sdk.Internal.Registration; -internal class PreparedRuntimeRegistration< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime, - TIntegrationSnapshot ->( +internal class PreparedRuntimeRegistration( string runtimeName, TConfiguration configuration, - AllureRuntimeRegistrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > commonSnapshot, - TIntegrationSnapshot integrationSnapshot + AllureRuntimeRegistrationSnapshot commonSnapshot, + IAllureRuntimeIntegrationSnapshot integrationSnapshot ) : IPreparedRuntimeRegistration where TConfiguration : AllureConfiguration - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext< - TConfiguration, - TRuntime - > - where TEndpointHook : IAllureInProcessEndpointRegistrationHook< - TConfiguration, - TEndpointRegistrationContext, - TRuntime - > - where TIntegrationSnapshot : IAllureRuntimeIntegrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > where TRuntime : IAllureRuntime { public TConfiguration Configuration => configuration; @@ -89,12 +63,11 @@ public IAllureRuntimeRegistration Build() routeId, runtime, commonSnapshot.UseRuleBasedSerializer, - commonSnapshot.RuleBasedSerializerRegistrations + commonSnapshot.RuleBasedSerializerRegistrations, + routeRegistration ); var endpointRouteBuilder = integrationSnapshot.CreateRouteBuilder(endpointBuildArgs); - routeRegistration(runtime, endpointRouteBuilder); - var route = endpointRouteBuilder.Build(); endpointRegistration = AllureRuntimeRouter.Install(route); } diff --git a/src/Allure.Net.Sdk/Registration/AllureInProcessRouteBuilder.cs b/src/Allure.Net.Sdk/Registration/AllureInProcessRouteBuilder.cs index 06d81c96..d5bdcba2 100644 --- a/src/Allure.Net.Sdk/Registration/AllureInProcessRouteBuilder.cs +++ b/src/Allure.Net.Sdk/Registration/AllureInProcessRouteBuilder.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Allure.Abstractions; using Allure.Sdk.Configuration; using Allure.Sdk.Internal.Runtime; @@ -13,22 +14,19 @@ namespace Allure.Sdk.Registration; /// endpoint route with an integration-specific registration context and hook. /// /// The runtime configuration type. -/// The endpoint registration context type. -/// The endpoint registration hook type. /// The runtime type. -public abstract class AllureInProcessRouteBuilder : - IAllureInProcessEndpointIntegrationContext +public class AllureInProcessRouteBuilder : + IAllureInProcessEndpointIntegrationContext, + IPreparedInProcessRouteBuilder where TConfiguration : AllureConfiguration - where TContext : IAllureInProcessEndpointRegistrationContext - where THook : IAllureInProcessEndpointRegistrationHook where TRuntime : IAllureRuntime { readonly string runtimeName; readonly string routeId; - Func> currentHooksFactory = + Func>?>> currentHooksFactory = (_) => []; Func availabilityPredicate = (_) => true; @@ -49,7 +47,9 @@ public abstract class AllureInProcessRouteBuilder currentSerializerFactory; - readonly List> currentRuleBasedSerializerRegistrations; + readonly List> currentRuleBasedSerializerRegistrations; + + readonly Action> registration; /// /// Gets the integration-specific runtime associated with this route. @@ -67,19 +67,27 @@ public AllureInProcessRouteBuilder(AllureRouteBuilderArgs + (Action)( + (runtime, context) => registration(runtime.Configuration, context) + ) + ) + ]; this.currentSerializerFactory = useRuleBasedSerializer ? (runtime) => - AllureRegistrationDefaults.ParameterSerializer( + AllureRegistrationDefaults.EndpointParameterSerializer( currentRuleBasedSerializerRegistrations - )(runtime.Configuration) + )(runtime) : (_) => this.Runtime.ParameterSerializer; + this.registration = args.Registration; } /// public void UseRegistrationHooks( - Func> hooksFactory + Func>?>> hooksFactory ) { this.currentHooksFactory = hooksFactory; @@ -140,13 +148,13 @@ public void UseParameterSerializer(Func serializerFa this.UseParameterSerializer((_) => serializerFactory()); /// - public void ConfigureSerialization(Action registration) + public void ConfigureSerialization(Action registration) { if (!this.useRuleBasedSerializer) { - this.currentSerializerFactory = (runtime) => AllureRegistrationDefaults.ParameterSerializer( + this.currentSerializerFactory = (runtime) => AllureRegistrationDefaults.EndpointParameterSerializer( currentRuleBasedSerializerRegistrations - )(runtime.Configuration); + )(runtime); this.useRuleBasedSerializer = true; } @@ -165,6 +173,7 @@ public void ConfigureSerialization(Action r /// The constructed in-process runtime route. public IAllureRuntimeRoute Build() { + this.registration(this.Runtime, this); this.RunHooks(); return new AllureRuntimeRoute( routeId, @@ -180,55 +189,24 @@ [.. this.currentSuppressedRouteIdsFactory(this.Runtime)], ); } - /// - /// Gets the integration-specific context passed to endpoint registration - /// hooks. - /// - protected abstract TContext RegistrationContext { get; } - void RunHooks() { - foreach (var hook in this.currentHooksFactory(this.Runtime.Configuration)) + foreach (var hook in this.currentHooksFactory(this.Runtime)) { - hook?.SetUp(this.RegistrationContext); + hook?.SetUp(this); } } } -/// -/// Provides the base implementation for builders that construct an in-process -/// endpoint route for a standard Allure runtime with an integration-specific -/// registration context and hook. -/// -/// The runtime configuration type. -/// The endpoint registration context type. -/// The endpoint registration hook type. -/// The resolved route builder arguments. -public abstract class AllureInProcessRouteBuilder( +public class AllureInProcessRouteBuilder( AllureRouteBuilderArgs> args ) : - AllureInProcessRouteBuilder< - TConfiguration, - TContext, - THook, - IAllureRuntime - >(args), - IAllureInProcessEndpointIntegrationContext + AllureInProcessRouteBuilder>(args) - where TConfiguration : AllureConfiguration - where TContext : IAllureInProcessEndpointRegistrationContext - where THook : IAllureInProcessEndpointRegistrationHook; + where TConfiguration : AllureConfiguration; class AllureInProcessRouteBuilder( AllureRouteBuilderArgs> args ) : - AllureInProcessRouteBuilder< - AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - IAllureInProcessEndpointRegistrationHook - >(args), - IAllureInProcessEndpointIntegrationContext -{ - /// - protected override IAllureInProcessEndpointRegistrationContext RegistrationContext => this; -} + AllureInProcessRouteBuilder(args), + IAllureInProcessEndpointIntegrationContext; diff --git a/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs b/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs index 4e192f50..543f0e0a 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs @@ -5,6 +5,7 @@ using Allure.Sdk.Internal.Registration; using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Results; +using Allure.Sdk.Runtime; namespace Allure.Sdk.Registration; @@ -36,11 +37,31 @@ public static Func Destination - /// Creates a rule-based parameter-serializer factory from rule registrations. + /// Creates an endpoint rule-based parameter-serializer factory from rule registrations. /// - public static Func ParameterSerializer( + public static Func EndpointParameterSerializer( + IEnumerable> registrations + ) + where TRuntime : IAllureRuntime + => + (configuration) => + { + var builder = new RuleBasedParameterSerializerBuilder(); + foreach (var registration in registrations) + { + registration(configuration, builder); + } + return builder.Build(); + }; + + /// + /// Creates a runtime rule-based parameter-serializer factory from rule registrations. + /// + public static Func RuntimeParameterSerializer( IEnumerable> registrations - ) => + ) + where TConfiguration : AllureConfiguration + => (configuration) => { var builder = new RuleBasedParameterSerializerBuilder(); @@ -60,7 +81,7 @@ IEnumerable> registr public static Func> RuntimeHookProviders() where TConfiguration : AllureConfiguration, new() where TContext : IAllureRuntimeRegistrationContext - where THook : IAllureRuntimeRegistrationHook + where THook : IAllureRegistrationHook => static (configuration) => [ ReflectionHooks.FromEnvironmentVariable("ALLURE_RUNTIME_REGISTRATION_HOOK"), diff --git a/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs b/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs index 7e667890..8dcc51dc 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs @@ -24,13 +24,15 @@ public class AllureRouteBuilderArgs internal TRuntime Runtime { get; } internal bool UseRuleBasedSerializer { get; } internal IEnumerable> RuleBasedSerializerRegistrations { get; } + internal Action> Registration { get; } internal AllureRouteBuilderArgs( string runtimeName, string routeId, TRuntime runtime, bool useRuleBasedSerializer, - IEnumerable> ruleBasedSerializerRegistrations + IEnumerable> ruleBasedSerializerRegistrations, + Action> registration ) { this.RuntimeName = runtimeName; @@ -38,5 +40,6 @@ IEnumerable> ruleBas this.Runtime = runtime; this.UseRuleBasedSerializer = useRuleBasedSerializer; this.RuleBasedSerializerRegistrations = ruleBasedSerializerRegistrations; + this.Registration = registration; } } diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs index cb107c5e..7f480f74 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs @@ -11,58 +11,23 @@ namespace Allure.Sdk.Registration; /// Prepares registration of a custom Allure runtime and its optional in-process endpoint. /// /// The runtime configuration type. -/// The runtime registration context type. -/// The runtime registration hook type. -/// The endpoint registration context type. -/// The endpoint registration hook type. -/// The integration context type. -/// The integration snapshot type. /// The type of runtime constructed by the builder. +/// The registration context type. +/// The integration context type. /// The runtime name used to identify its in-process route. /// /// A factory that creates the single-use registration session configured by /// . /// -public class AllureRuntimeBuilder< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntimeIntegrationContext, - TIntegrationSnapshot, - TRuntime ->( +public class AllureRuntimeBuilder( string runtimeName, - Func< - AllureRuntimeRegistrationSession< - TConfiguration, - TRuntimeIntegrationContext, - TRuntime - > - > sessionFactory + Func> sessionFactory ) where TConfiguration : AllureConfiguration, new() - where TRuntimeRegistrationContext : IAllureRuntimeRegistrationContext - where TRuntimeHook : IAllureRuntimeRegistrationHook - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext - where TEndpointHook : IAllureInProcessEndpointRegistrationHook - where TRuntimeIntegrationContext : IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > - where TIntegrationSnapshot : IAllureRuntimeIntegrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > where TRuntime : IAllureRuntime + where TRegistrationContext : IAllureRuntimeRegistrationContext + where TIntegrationContext : IAllureRuntimeIntegrationContext { int state = 0; @@ -89,7 +54,7 @@ public class AllureRuntimeBuilder< /// This builder has already been used. /// public IAllureRuntimeRegistrationPlan Prepare( - Action registration + Action registration ) { if (Interlocked.CompareExchange(ref this.state, STAGE_CONSUMED, STAGE_CREATED) != STAGE_CREATED) @@ -112,84 +77,83 @@ Action registration const int STAGE_CONSUMED = 1; } -/// -/// Prepares registrations for a standard Allure runtime with custom configuration, -/// registration, and endpoint types. -/// -/// The runtime configuration type. -/// The runtime registration context type. -/// The runtime registration hook type. -/// The endpoint registration context type. -/// The endpoint registration hook type. -/// The integration context type. -/// The integration snapshot type. -/// The runtime name used to identify its in-process route. -/// A factory that creates a registration session. -public class AllureRuntimeBuilder< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntimeIntegrationContext, - TIntegrationSnapshot ->( +public class AllureRuntimeBuilder( + string runtimeName, + Func< + AllureRuntimeRegistrationSession< + TConfiguration, + TRuntime, + TRegistrationContext, + IAllureRuntimeIntegrationContext + > + > sessionFactory +) : + AllureRuntimeBuilder>( + runtimeName, + sessionFactory + ) + + where TConfiguration : AllureConfiguration, new() + where TRuntime : IAllureRuntime + where TRegistrationContext : IAllureRuntimeRegistrationContext; + +public class AllureRuntimeBuilder( string runtimeName, Func< AllureRuntimeRegistrationSession< TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntimeIntegrationContext, - TIntegrationSnapshot + TRuntime, + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext > > sessionFactory ) : AllureRuntimeBuilder< TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntimeIntegrationContext, - TIntegrationSnapshot, - IAllureRuntime - >(runtimeName, sessionFactory) + TRuntime, + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext< + TConfiguration, + TRuntime + > + >( + runtimeName, + sessionFactory + ) where TConfiguration : AllureConfiguration, new() - where TRuntimeRegistrationContext : IAllureRuntimeRegistrationContext - where TRuntimeHook : IAllureRuntimeRegistrationHook - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext - where TEndpointHook : IAllureInProcessEndpointRegistrationHook - where TRuntimeIntegrationContext : IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook - > - where TIntegrationSnapshot : IAllureRuntimeIntegrationSnapshot< + where TRuntime : IAllureRuntime; + +public class AllureRuntimeBuilder( + string runtimeName, + Func< + AllureRuntimeRegistrationSession< + TConfiguration, + IAllureRuntime, + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext + > + > sessionFactory +) : + AllureRuntimeBuilder< TConfiguration, - TEndpointRegistrationContext, - TEndpointHook - >; + IAllureRuntime, + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext + >( + runtimeName, + sessionFactory + ) -/// -/// Prepares registrations for a standard Allure runtime and its optional in-process -/// endpoint. -/// -/// The runtime name used to identify its in-process route. -public class AllureRuntimeBuilder(string runtimeName) : AllureRuntimeBuilder< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - IAllureRuntimeRegistrationHook, - IAllureInProcessEndpointRegistrationContext, - IAllureInProcessEndpointRegistrationHook, - IAllureRuntimeIntegrationContext, - IAllureRuntimeIntegrationSnapshot ->( - runtimeName, - () => new AllureRuntimeRegistrationSession() -); + where TConfiguration : AllureConfiguration, new(); + +public class AllureRuntimeBuilder(string runtimeName) : + AllureRuntimeBuilder< + AllureConfiguration, + IAllureRuntime, + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext + >( + runtimeName, + () => new AllureRuntimeRegistrationSession() + ); diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeIntegrationSnapshot.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeIntegrationSnapshot.cs index ec7cb0a4..0eeca29d 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeIntegrationSnapshot.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeIntegrationSnapshot.cs @@ -1,5 +1,4 @@ using Allure.Sdk.Configuration; -using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Runtime; namespace Allure.Sdk.Registration; @@ -9,33 +8,13 @@ namespace Allure.Sdk.Registration; /// builder factory. /// /// The runtime configuration type. -/// The endpoint registration context type. -/// The endpoint registration hook type. -public abstract class AllureRuntimeIntegrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook ->() : - IAllureRuntimeIntegrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook - > +public abstract class AllureRuntimeIntegrationSnapshot() : + IAllureRuntimeIntegrationSnapshot where TConfiguration : AllureConfiguration - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext - where TEndpointHook : IAllureInProcessEndpointRegistrationHook< - TConfiguration, - TEndpointRegistrationContext - > { /// - public abstract AllureInProcessRouteBuilder< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - IAllureRuntime - > CreateRouteBuilder( + public abstract IPreparedInProcessRouteBuilder CreateRouteBuilder( AllureRouteBuilderArgs> args ); @@ -58,20 +37,11 @@ RuntimeCreationArguments args /// in-process route builder. /// public class AllureRuntimeIntegrationSnapshot() : - AllureRuntimeIntegrationSnapshot< - AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - IAllureInProcessEndpointRegistrationHook - >, + AllureRuntimeIntegrationSnapshot, IAllureRuntimeIntegrationSnapshot { /// - public override AllureInProcessRouteBuilder< - AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - IAllureInProcessEndpointRegistrationHook, - IAllureRuntime - > CreateRouteBuilder( + public override IPreparedInProcessRouteBuilder CreateRouteBuilder( AllureRouteBuilderArgs> args ) => new AllureInProcessRouteBuilder(args); diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index f979a68f..c4f8e3b8 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -11,88 +11,21 @@ namespace Allure.Sdk.Registration; -/// -/// Defines the base contract for a single-use runtime registration session. -/// -/// The runtime configuration type. -/// The integration context type. -/// The runtime type. -public abstract class AllureRuntimeRegistrationSession< - TConfiguration, - TRuntimeIntegrationContext, - TRuntime -> - where TConfiguration : AllureConfiguration - where TRuntime : IAllureRuntime -{ - internal abstract IPreparedRuntimeRegistration Prepare( - string runtimeName, - Action registration - ); -} - /// /// Provides a single-use registration session for a custom Allure runtime and its /// optional in-process endpoint. /// /// The runtime configuration type. -/// The runtime registration context type. -/// The runtime registration hook type. -/// The endpoint registration context type. -/// The endpoint registration hook type. -/// The integration context type. -/// The integration snapshot type. /// The runtime type. -public abstract class AllureRuntimeRegistrationSession< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntimeIntegrationContext, - TIntegrationSnapshot, - TRuntime -> : - AllureRuntimeRegistrationSession, - IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > +/// The runtime registration context type. +/// The runtime integration context type. +public abstract class AllureRuntimeRegistrationSession : + IAllureRuntimeIntegrationContext where TConfiguration : AllureConfiguration, new() - where TRuntimeRegistrationContext : IAllureRuntimeRegistrationContext - where TRuntimeHook : IAllureRuntimeRegistrationHook< - TConfiguration, - TRuntimeRegistrationContext - > - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext< - TConfiguration, - TRuntime - > - where TEndpointHook : IAllureInProcessEndpointRegistrationHook< - TConfiguration, - TEndpointRegistrationContext, - TRuntime - > - where TRuntimeIntegrationContext : IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > - where TIntegrationSnapshot : IAllureRuntimeIntegrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > where TRuntime : IAllureRuntime + where TRegistrationContext : IAllureRuntimeRegistrationContext + where TIntegrationContext : IAllureRuntimeIntegrationContext { readonly object gate = new(); @@ -108,11 +41,11 @@ readonly List< > > configurationTransformations = []; - Func> currentHooksFactory = + Func?>> currentHooksFactory = AllureRegistrationDefaults.RuntimeHookProviders< TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook + TRegistrationContext, + IAllureRegistrationHook >(); Func< @@ -147,25 +80,22 @@ readonly List< > > currentRuleBasedSerializerRegistrations = []; - AllureInProcessEndpointRegistration< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - >? currentEndpointRegistration = null; + AllureInProcessEndpointRegistration? currentEndpointRegistration = null; /// /// Initializes a runtime registration session with the default component factories. /// public AllureRuntimeRegistrationSession() : base() { - this.currentSerializerFactory = AllureRegistrationDefaults.ParameterSerializer( + this.currentSerializerFactory = AllureRegistrationDefaults.RuntimeParameterSerializer( this.currentRuleBasedSerializerRegistrations ); } /// - public void UseRegistrationHooks(Func> hooksFactory) => + public void UseRegistrationHooks( + Func?>> hooksFactory + ) => this.Modify(() => this.currentHooksFactory = hooksFactory); /// @@ -183,15 +113,7 @@ public void UseModelApi(Func modelApiFactory) = /// public void RegisterInProcessEndpoint( string endpointId, - Action< - TRuntime, - IAllureInProcessEndpointIntegrationContext< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > - > endpointRegistration + Action> endpointRegistration ) => this.Modify(() => this.currentEndpointRegistration = new(endpointId, endpointRegistration)); @@ -211,7 +133,7 @@ public void ConfigureSerialization(Action - /// Gets the integration context passed to the registration action. + /// Gets the integration-specific context passed to runtime registration + /// hooks. /// - protected abstract TRuntimeIntegrationContext IntegrationContext { get; } + protected abstract TIntegrationContext IntegrationContext { get; } /// - /// Gets the integration-specific context passed to runtime registration + /// Gets the integration-specific context passed to hooks /// hooks. /// - protected abstract TRuntimeRegistrationContext RegistrationContext { get; } + protected abstract TRegistrationContext RegistrationContext { get; } /// /// Captures the integration-specific factories required after the session closes. /// /// The immutable integration snapshot. - protected abstract TIntegrationSnapshot CaptureIntegrationSnapshot(); + protected abstract IAllureRuntimeIntegrationSnapshot CaptureIntegrationSnapshot(); - internal override IPreparedRuntimeRegistration Prepare( + internal IPreparedRuntimeRegistration Prepare( string runtimeName, - Action registration + Action registration ) { lock (this.gate) @@ -306,13 +229,7 @@ Action registration var integrationSnapshot = this.CaptureIntegrationSnapshot(); - return new PreparedRuntimeRegistration< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime, - TIntegrationSnapshot - >( + return new PreparedRuntimeRegistration( runtimeName, finalConfiguration.Configuration, commonSnapshot, @@ -327,12 +244,7 @@ Action registration } } - AllureRuntimeRegistrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > CaptureCommonSnapshot() => new( + AllureRuntimeRegistrationSnapshot CaptureCommonSnapshot() => new( ContextFactory: this.currentContextFactory, LifecycleApiFactory: this.currentLifecycleApiFactory, ModelApiFactory: this.currentModelApiFactory, @@ -454,93 +366,73 @@ enum RegistrationState } } -/// -/// Provides a single-use registration session for a standard Allure runtime with -/// custom configuration, registration, and endpoint types. -/// -/// The runtime configuration type. -/// The runtime registration context type. -/// The runtime registration hook type. -/// The endpoint registration context type. -/// The endpoint registration hook type. -/// The integration context type. -/// The integration snapshot type. public abstract class AllureRuntimeRegistrationSession< TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntimeIntegrationContext, - TIntegrationSnapshot + TRuntime, + TRegistrationContext > : AllureRuntimeRegistrationSession< TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntimeIntegrationContext, - TIntegrationSnapshot, - IAllureRuntime - >, - IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook + TRuntime, + TRegistrationContext, + IAllureRuntimeIntegrationContext > where TConfiguration : AllureConfiguration, new() - where TRuntimeRegistrationContext : IAllureRuntimeRegistrationContext - where TRuntimeHook : IAllureRuntimeRegistrationHook< - TConfiguration, - TRuntimeRegistrationContext - > - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext< - TConfiguration - > - where TEndpointHook : IAllureInProcessEndpointRegistrationHook< - TConfiguration, - TEndpointRegistrationContext - > - where TRuntimeIntegrationContext : IAllureRuntimeIntegrationContext< + where TRuntime : IAllureRuntime + where TRegistrationContext : IAllureRuntimeRegistrationContext +{ + protected override IAllureRuntimeIntegrationContext IntegrationContext => this; +} + +public abstract class AllureRuntimeRegistrationSession : + AllureRuntimeRegistrationSession< TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook - > - where TIntegrationSnapshot : IAllureRuntimeIntegrationSnapshot< + TRuntime, + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext + >, + IAllureRuntimeIntegrationContext + + where TConfiguration : AllureConfiguration, new() + where TRuntime : IAllureRuntime +{ + protected override IAllureRuntimeRegistrationContext RegistrationContext => this; + + protected override IAllureRuntimeIntegrationContext IntegrationContext => this; +} + +public abstract class AllureRuntimeRegistrationSession : + AllureRuntimeRegistrationSession< TConfiguration, - TEndpointRegistrationContext, - TEndpointHook - >; + IAllureRuntime, + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext + >, + IAllureRuntimeIntegrationContext + + where TConfiguration : AllureConfiguration, new() +{ + protected override IAllureRuntimeIntegrationContext IntegrationContext => this; + + protected override IAllureRuntimeRegistrationContext RegistrationContext => this; +} -/// -/// Provides a single-use registration session for a standard Allure runtime and its -/// optional in-process endpoint. -/// public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< AllureConfiguration, - IAllureRuntimeRegistrationContext, - IAllureRuntimeRegistrationHook, - IAllureInProcessEndpointRegistrationContext, - IAllureInProcessEndpointRegistrationHook, - IAllureRuntimeIntegrationContext, - IAllureRuntimeIntegrationSnapshot + IAllureRuntime, + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext >, IAllureRuntimeIntegrationContext { - /// - protected override IAllureRuntimeIntegrationContext IntegrationContext => this; + protected override IAllureRuntimeIntegrationSnapshot> CaptureIntegrationSnapshot() + { + return new AllureRuntimeIntegrationSnapshot(); + } - /// - protected override IAllureRuntimeRegistrationContext RegistrationContext => this; + protected override IAllureRuntimeIntegrationContext IntegrationContext => this; - /// - protected override IAllureRuntimeIntegrationSnapshot CaptureIntegrationSnapshot() => - new AllureRuntimeIntegrationSnapshot(); + protected override IAllureRuntimeRegistrationContext RegistrationContext => this; } diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureEndpointRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureEndpointRegistrationHook.cs deleted file mode 100644 index e7087241..00000000 --- a/src/Allure.Net.Sdk/Registration/Hooks/IAllureEndpointRegistrationHook.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Allure.Sdk.Registration.Hooks; - -/// -/// Customizes an Allure endpoint during registration. -/// -/// The registration context type. -public interface IAllureEndpointRegistrationHook - where TContext : IAllureEndpointRegistrationContext -{ - /// - /// Applies custom endpoint configuration. - /// - void SetUp(TContext context); -} - -/// -/// Customizes an Allure endpoint through the standard registration context. -/// -public interface IAllureEndpointRegistrationHook : - IAllureEndpointRegistrationHook; diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureInProcessEndpointRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureInProcessEndpointRegistrationHook.cs deleted file mode 100644 index d6c6cc0d..00000000 --- a/src/Allure.Net.Sdk/Registration/Hooks/IAllureInProcessEndpointRegistrationHook.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Allure.Sdk.Configuration; -using Allure.Sdk.Runtime; - -namespace Allure.Sdk.Registration.Hooks; - -/// -/// Customizes an in-process Allure endpoint during registration. -/// -/// The runtime configuration type. -/// The registration context type. -/// The runtime type. -public interface IAllureInProcessEndpointRegistrationHook - where TConfiguration : AllureConfiguration - where TRuntime : IAllureRuntime - where TContext : IAllureInProcessEndpointRegistrationContext -{ - /// - /// Applies custom endpoint configuration. - /// - void SetUp(TContext context); -} - -/// -/// Customizes an in-process Allure endpoint for a standard runtime during -/// registration. -/// -/// The runtime configuration type. -/// The registration context type. -public interface IAllureInProcessEndpointRegistrationHook : - IAllureInProcessEndpointRegistrationHook> - - where TConfiguration : AllureConfiguration - where TContext : IAllureInProcessEndpointRegistrationContext; - -/// -/// Customizes an in-process Allure endpoint that uses the standard -/// during registration. -/// -public interface IAllureInProcessEndpointRegistrationHook : - IAllureInProcessEndpointRegistrationHook; diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs new file mode 100644 index 00000000..1abf2b2b --- /dev/null +++ b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs @@ -0,0 +1,14 @@ +namespace Allure.Sdk.Registration.Hooks; + +/// +/// Customizes an Allure runtime during registration. +/// +/// The registration context type. +public interface IAllureRegistrationHook + where TContext : IAllureRegistrationContext +{ + /// + /// Applies custom runtime configuration. + /// + void SetUp(TContext context); +} diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs deleted file mode 100644 index baff67fa..00000000 --- a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Allure.Sdk.Configuration; - -namespace Allure.Sdk.Registration.Hooks; - -/// -/// Customizes an Allure runtime during registration. -/// -/// The runtime configuration type. -/// The registration context type. -public interface IAllureRuntimeRegistrationHook - where TConfiguration : AllureConfiguration - where TContext : IAllureRuntimeRegistrationContext -{ - /// - /// Applies custom runtime configuration. - /// - void SetUp(TContext context); -} - -/// -/// Customizes an Allure runtime that uses the standard -/// during registration. -/// -public interface IAllureRuntimeRegistrationHook : - IAllureRuntimeRegistrationHook< - AllureConfiguration, - IAllureRuntimeRegistrationContext - >; diff --git a/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs index 47720895..664a220a 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs @@ -6,19 +6,17 @@ namespace Allure.Sdk.Registration; /// -/// Configures an external Allure runtime endpoint and its integration hooks. +/// Configures an external Allure runtime endpoint. /// /// The registration context type. -/// The endpoint registration hook type. -public interface IAllureEndpointIntegrationContext : IAllureEndpointRegistrationContext +public interface IAllureEndpointIntegrationContext : IAllureEndpointRegistrationContext where TContext : IAllureEndpointRegistrationContext - where THook : IAllureEndpointRegistrationHook { /// /// Configures the hooks invoked during endpoint registration. /// void UseRegistrationHooks( - Func> hooksFactory + Func?>> hooksFactory ); /// @@ -37,9 +35,5 @@ void UseRegistrationHooks( void UseOperations(Func operationsFactory); } -/// -/// Configures an external Allure runtime endpoint and its integration hooks -/// through the standard endpoint registration context. -/// public interface IAllureEndpointIntegrationContext : - IAllureEndpointIntegrationContext; + IAllureEndpointIntegrationContext; diff --git a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs index 8bcd77c2..65a3832d 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs @@ -10,23 +10,19 @@ namespace Allure.Sdk.Registration; /// /// Configures an in-process Allure endpoint and its integration hooks. /// -/// The runtime configuration type. -/// The registration context type. -/// The endpoint registration hook type. /// The runtime type. -public interface IAllureInProcessEndpointIntegrationContext : - IAllureInProcessEndpointRegistrationContext +/// The endpoint registration context type. +public interface IAllureInProcessEndpointIntegrationContext : + IAllureInProcessEndpointRegistrationContext - where TConfiguration : AllureConfiguration - where TRuntime : IAllureRuntime - where TContext : IAllureInProcessEndpointRegistrationContext - where THook : IAllureInProcessEndpointRegistrationHook + where TRuntime : IAllureRuntime + where TContext : IAllureInProcessEndpointRegistrationContext { /// /// Configures the hooks invoked during endpoint registration. /// void UseRegistrationHooks( - Func> hooksFactory + Func?>> hooksFactory ); /// @@ -45,35 +41,13 @@ void UseRegistrationHooks( void UseOperations(Func operationsFactory); } -/// -/// Configures an in-process endpoint and its integration hooks for a standard -/// Allure runtime. -/// -/// The runtime configuration type. -/// The registration context type. -/// The endpoint registration hook type. -public interface IAllureInProcessEndpointIntegrationContext : +public interface IAllureInProcessEndpointIntegrationContext : IAllureInProcessEndpointIntegrationContext< - TConfiguration, - TContext, - THook, - IAllureRuntime - >, - IAllureInProcessEndpointRegistrationContext + TRuntime, + IAllureInProcessEndpointRegistrationContext + > - where TConfiguration : AllureConfiguration - where TContext : IAllureInProcessEndpointRegistrationContext - where THook : IAllureInProcessEndpointRegistrationHook; + where TRuntime : IAllureRuntime; -/// -/// Configures an in-process endpoint and its integration hooks for an Allure -/// runtime that uses the standard . -/// public interface IAllureInProcessEndpointIntegrationContext : - IAllureInProcessEndpointIntegrationContext< - AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - IAllureInProcessEndpointRegistrationHook, - IAllureRuntime - >, - IAllureInProcessEndpointRegistrationContext; + IAllureInProcessEndpointIntegrationContext>; diff --git a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs index 8c10e581..9a6ac624 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs @@ -9,13 +9,11 @@ namespace Allure.Sdk.Registration; /// /// Configures an in-process endpoint for an Allure runtime. /// -/// The runtime configuration type. /// The runtime type. -public interface IAllureInProcessEndpointRegistrationContext : +public interface IAllureInProcessEndpointRegistrationContext : IAllureEndpointRegistrationContext - where TConfiguration : AllureConfiguration - where TRuntime : IAllureRuntime + where TRuntime : IAllureRuntime { /// /// Configures the parameter serializer used by the endpoint. @@ -25,9 +23,9 @@ Func serializerFactory ); /// - /// Configures parameter serialization rules using the resolved runtime configuration. + /// Configures endpoint availability using the constructed runtime. /// - void ConfigureSerialization(Action registration); + void ConfigureSerialization(Action registration); /// /// Configures endpoint availability using the constructed runtime. @@ -39,19 +37,3 @@ Func serializerFactory /// void SuppressRoutes(Func> routeIdsFactory); } - -/// -/// Configures an in-process endpoint for a standard Allure runtime. -/// -/// The runtime configuration type. -public interface IAllureInProcessEndpointRegistrationContext : - IAllureInProcessEndpointRegistrationContext> - - where TConfiguration : AllureConfiguration; - -/// -/// Configures an in-process endpoint for an Allure runtime that uses the -/// standard . -/// -public interface IAllureInProcessEndpointRegistrationContext : - IAllureInProcessEndpointRegistrationContext; diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs index b42ea57a..f186793b 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs @@ -10,27 +10,14 @@ namespace Allure.Sdk.Registration; /// Configures an Allure runtime and its in-process endpoint integration. /// /// The runtime configuration type. -/// The runtime registration context type. -/// The runtime registration hook type. -/// The endpoint registration context type. -/// The endpoint registration hook type. /// The type of runtime constructed by the integration. -public interface IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime -> : +/// The type of runtime integration context. +public interface IAllureRuntimeIntegrationContext : IAllureRuntimeRegistrationContext where TConfiguration : AllureConfiguration, new() - where TRuntimeRegistrationContext : IAllureRuntimeRegistrationContext - where TRuntimeHook : IAllureRuntimeRegistrationHook - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext - where TEndpointHook : IAllureInProcessEndpointRegistrationHook where TRuntime : IAllureRuntime + where TContext : IAllureRuntimeRegistrationContext { /// /// Configures the hooks invoked during runtime registration. @@ -39,7 +26,7 @@ public interface IAllureRuntimeIntegrationContext< /// A factory that creates the hooks from the initially resolved configuration. /// void UseRegistrationHooks( - Func> hooksFactory + Func?>> hooksFactory ); /// @@ -81,58 +68,34 @@ Func modelApiFactory /// public void RegisterInProcessEndpoint( string endpointId, - Action< - TRuntime, - IAllureInProcessEndpointIntegrationContext< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > - > endpointRegistration + Action> endpointRegistration ); } +public interface IAllureRuntimeIntegrationContext : + IAllureRuntimeIntegrationContext< + TConfiguration, + TRuntime, + IAllureRuntimeRegistrationContext + > + + where TConfiguration : AllureConfiguration, new() + where TRuntime : IAllureRuntime; + /// -/// Configures a standard Allure runtime with a custom configuration type, -/// custom registration hook types, and its in-process endpoint integration. +/// Configures a standard Allure runtime with a custom configuration type. /// /// The runtime configuration type. -/// The runtime registration context type. -/// The runtime registration hook type. -/// The endpoint registration context type. -/// The endpoint registration hook type. -public interface IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook -> : +public interface IAllureRuntimeIntegrationContext : IAllureRuntimeIntegrationContext< TConfiguration, - TRuntimeRegistrationContext, - TRuntimeHook, - TEndpointRegistrationContext, - TEndpointHook, IAllureRuntime > - where TConfiguration : AllureConfiguration, new() - where TRuntimeRegistrationContext : IAllureRuntimeRegistrationContext - where TRuntimeHook : IAllureRuntimeRegistrationHook - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext - where TEndpointHook : IAllureInProcessEndpointRegistrationHook; + where TConfiguration : AllureConfiguration, new(); /// /// Configures a standard Allure runtime and its in-process endpoint integration. /// public interface IAllureRuntimeIntegrationContext : - IAllureRuntimeIntegrationContext< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - IAllureRuntimeRegistrationHook, - IAllureInProcessEndpointRegistrationContext, - IAllureInProcessEndpointRegistrationHook - >, - IAllureRuntimeRegistrationContext; + IAllureRuntimeIntegrationContext; diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationSnapshot.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationSnapshot.cs index 2e0aef16..8e35fa8a 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationSnapshot.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationSnapshot.cs @@ -9,25 +9,9 @@ namespace Allure.Sdk.Registration; /// its in-process route builder. /// /// The runtime configuration type. -/// The endpoint registration context type. -/// The endpoint registration hook type. /// The runtime type. -public interface IAllureRuntimeIntegrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime -> +public interface IAllureRuntimeIntegrationSnapshot where TConfiguration : AllureConfiguration - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext< - TConfiguration, - TRuntime - > - where TEndpointHook : IAllureInProcessEndpointRegistrationHook< - TConfiguration, - TEndpointRegistrationContext, - TRuntime - > where TRuntime : IAllureRuntime { /// @@ -42,47 +26,27 @@ public interface IAllureRuntimeIntegrationSnapshot< /// /// The resolved route builder arguments. /// The in-process route builder. - AllureInProcessRouteBuilder< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, - TRuntime - > CreateRouteBuilder(AllureRouteBuilderArgs args); + IPreparedInProcessRouteBuilder CreateRouteBuilder( + AllureRouteBuilderArgs args + ); } /// /// Captures the integration-specific factories used to construct a standard runtime -/// with custom configuration and endpoint types. +/// with custom configuration. /// /// The runtime configuration type. -/// The endpoint registration context type. -/// The endpoint registration hook type. -public interface IAllureRuntimeIntegrationSnapshot< - TConfiguration, - TEndpointRegistrationContext, - TEndpointHook -> : +public interface IAllureRuntimeIntegrationSnapshot : IAllureRuntimeIntegrationSnapshot< TConfiguration, - TEndpointRegistrationContext, - TEndpointHook, IAllureRuntime > - where TConfiguration : AllureConfiguration - where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext - where TEndpointHook : IAllureInProcessEndpointRegistrationHook< - TConfiguration, - TEndpointRegistrationContext - >; + where TConfiguration : AllureConfiguration; /// /// Captures the factories used to construct a standard Allure runtime and its /// in-process route builder. /// public interface IAllureRuntimeIntegrationSnapshot : - IAllureRuntimeIntegrationSnapshot< - AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - IAllureInProcessEndpointRegistrationHook - >; + IAllureRuntimeIntegrationSnapshot; diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs index e32bee45..3ba27112 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs @@ -65,10 +65,3 @@ Func serializerFactory /// void UseDestination(Func destinationFactory); } - -/// -/// Configures an Allure runtime that uses the standard -/// before it is constructed. -/// -public interface IAllureRuntimeRegistrationContext : - IAllureRuntimeRegistrationContext; diff --git a/src/Allure.Net.Sdk/Registration/IPreparedInProcessRouteBuilder.cs b/src/Allure.Net.Sdk/Registration/IPreparedInProcessRouteBuilder.cs new file mode 100644 index 00000000..aa18b0c3 --- /dev/null +++ b/src/Allure.Net.Sdk/Registration/IPreparedInProcessRouteBuilder.cs @@ -0,0 +1,8 @@ +using Allure.Abstractions; + +namespace Allure.Sdk.Registration; + +public interface IPreparedInProcessRouteBuilder +{ + IAllureRuntimeRoute Build(); +} diff --git a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs index b15393c8..92235856 100644 --- a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs +++ b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs @@ -26,13 +26,7 @@ InMemoryResultsDestination destination public static RuntimeTestEnvironment Create( TConfiguration? configuration = null, Action< - IAllureRuntimeIntegrationContext< - TConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook - > + IAllureRuntimeIntegrationContext >? configure = null ) { @@ -55,62 +49,30 @@ public void Dispose() } sealed class TestRuntimeRegistrationSnapshot : - AllureRuntimeIntegrationSnapshot< - TConfiguration, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook - > + AllureRuntimeIntegrationSnapshot where TConfiguration : AllureConfiguration { - public override AllureInProcessRouteBuilder, RecordingEndpointHook, IAllureRuntime> CreateRouteBuilder(AllureRouteBuilderArgs> args) + public override IPreparedInProcessRouteBuilder CreateRouteBuilder(AllureRouteBuilderArgs> args) { return new TestEndpointRouteBuilder(args); } } -sealed class TestRuntimeRegistrationSession : AllureRuntimeRegistrationSession< - TConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - IAllureRuntimeIntegrationContext< - TConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook - >, - TestRuntimeRegistrationSnapshot -> +sealed class TestRuntimeRegistrationSession : + AllureRuntimeRegistrationSession + where TConfiguration : AllureConfiguration, new() { - protected override IAllureRuntimeIntegrationContext, RecordingRuntimeHook, IAllureInProcessEndpointRegistrationContext, RecordingEndpointHook> IntegrationContext => this; - - protected override IAllureRuntimeRegistrationContext RegistrationContext => this; - - protected override TestRuntimeRegistrationSnapshot CaptureIntegrationSnapshot() + protected override IAllureRuntimeIntegrationSnapshot> CaptureIntegrationSnapshot() { return new TestRuntimeRegistrationSnapshot(); } } -sealed class TestRuntimeBuilder(string runtimeName) : AllureRuntimeBuilder< - TConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - IAllureRuntimeIntegrationContext< - TConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook - >, - TestRuntimeRegistrationSnapshot ->(runtimeName, () => new TestRuntimeRegistrationSession()) +sealed class TestRuntimeBuilder(string runtimeName) : + AllureRuntimeBuilder(runtimeName, () => new TestRuntimeRegistrationSession()) + where TConfiguration : AllureConfiguration, new(); sealed class TestEndpointRouteBuilder( @@ -119,37 +81,22 @@ sealed class TestEndpointRouteBuilder( IAllureRuntime > args ) : - AllureInProcessRouteBuilder< - TConfiguration, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook - >(args) + AllureInProcessRouteBuilder(args) - where TConfiguration : AllureConfiguration -{ - protected override IAllureInProcessEndpointRegistrationContext RegistrationContext => this; -} + where TConfiguration : AllureConfiguration; sealed class RuntimeTestEnvironment { public static RuntimeTestEnvironment Create( AllureConfiguration? configuration = null, - Action< - IAllureRuntimeIntegrationContext< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook - > - >? configure = null + Action>? configure = null ) => RuntimeTestEnvironment.Create(configuration, configure); } sealed class RecordingRuntimeHook( Action>? setUp = null -) : IAllureRuntimeRegistrationHook> +) : IAllureRegistrationHook> where TConfiguration : AllureConfiguration, new() { public int CallCount { get; private set; } @@ -164,15 +111,15 @@ IAllureRuntimeRegistrationContext context } sealed class RecordingEndpointHook( - Action>? setUp = null -) : IAllureInProcessEndpointRegistrationHook, TRuntime> + Action>? setUp = null +) : IAllureRegistrationHook> where TConfiguration : AllureConfiguration where TRuntime : IAllureRuntime { public int CallCount { get; private set; } public void SetUp( - IAllureInProcessEndpointRegistrationContext context + IAllureInProcessEndpointRegistrationContext context ) { this.CallCount++; @@ -180,15 +127,14 @@ IAllureInProcessEndpointRegistrationContext context } } -sealed class RecordingEndpointHook( - Action>? setUp = null -) : IAllureInProcessEndpointRegistrationHook> - where TConfiguration : AllureConfiguration +sealed class RecordingEndpointHook( + Action>>? setUp = null +) : IAllureRegistrationHook>> { public int CallCount { get; private set; } public void SetUp( - IAllureInProcessEndpointRegistrationContext context + IAllureInProcessEndpointRegistrationContext> context ) { this.CallCount++; diff --git a/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs index 5cabb8cc..24f18594 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs @@ -216,16 +216,11 @@ public ValueTask DisposeAsync() sealed class RegistrationTestRuntimeRegistrationSnapshot( RuntimeFactory runtimeFactory ) : - IAllureRuntimeIntegrationSnapshot< - AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - TRuntime - > + IAllureRuntimeIntegrationSnapshot where TRuntime : IAllureRuntime { - public AllureInProcessRouteBuilder, RecordingEndpointHook, TRuntime> CreateRouteBuilder(AllureRouteBuilderArgs args) + public IPreparedInProcessRouteBuilder CreateRouteBuilder(AllureRouteBuilderArgs args) { return new RegistrationTestRouteBuilder(args); } @@ -246,30 +241,10 @@ public TRuntime CreateRuntime(RuntimeCreationArguments args sealed class RegistrationTestRuntimeRegistrationSession( RuntimeFactory runtimeFactory ) : - AllureRuntimeRegistrationSession< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - IAllureRuntimeIntegrationContext< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - TRuntime - >, - RegistrationTestRuntimeRegistrationSnapshot, - TRuntime - > + AllureRuntimeRegistrationSession where TRuntime : IAllureRuntime { - protected override IAllureRuntimeIntegrationContext, RecordingRuntimeHook, IAllureInProcessEndpointRegistrationContext, RecordingEndpointHook, TRuntime> IntegrationContext => this; - - protected override IAllureRuntimeRegistrationContext RegistrationContext => this; - protected override RegistrationTestRuntimeRegistrationSnapshot CaptureIntegrationSnapshot() => new( runtimeFactory ); @@ -280,19 +255,6 @@ RuntimeFactory runtimeFactory ) : AllureRuntimeBuilder< AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - IAllureRuntimeIntegrationContext< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - TRuntime - >, - RegistrationTestRuntimeRegistrationSnapshot, TRuntime >("registration-tests", () => new RegistrationTestRuntimeRegistrationSession(runtimeFactory)) @@ -303,18 +265,10 @@ AllureRouteBuilderArgs args ) : AllureInProcessRouteBuilder< AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, TRuntime >(args) - where TRuntime : IAllureRuntime - { - protected override IAllureInProcessEndpointRegistrationContext< - AllureConfiguration, - TRuntime - > RegistrationContext => this; - } + where TRuntime : IAllureRuntime; sealed class TestException : Exception; } diff --git a/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs index e370efc1..d3f3882c 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs @@ -187,12 +187,10 @@ object service sealed class RuntimeWithServiceRegistrationSnapshot(object service, Action notifyRouteBuilderService) : IAllureRuntimeIntegrationSnapshot< AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, RuntimeWithService > { - public AllureInProcessRouteBuilder, RecordingEndpointHook, RuntimeWithService> CreateRouteBuilder(AllureRouteBuilderArgs args) + public IPreparedInProcessRouteBuilder CreateRouteBuilder(AllureRouteBuilderArgs args) { var builder = new RuntimeWithServiceRouteBuilder(args); notifyRouteBuilderService(service); @@ -208,28 +206,9 @@ public RuntimeWithService CreateRuntime(RuntimeCreationArguments notifyRouteBuilderService - ) : AllureRuntimeRegistrationSession< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - IAllureRuntimeIntegrationContext< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - RuntimeWithService - >, - RuntimeWithServiceRegistrationSnapshot, - RuntimeWithService - > + ) : + AllureRuntimeRegistrationSession { - protected override IAllureRuntimeIntegrationContext, RecordingRuntimeHook, IAllureInProcessEndpointRegistrationContext, RecordingEndpointHook, RuntimeWithService> IntegrationContext => this; - - protected override IAllureRuntimeRegistrationContext RegistrationContext => this; - protected override RuntimeWithServiceRegistrationSnapshot CaptureIntegrationSnapshot() { return new(service, notifyRouteBuilderService); @@ -241,23 +220,10 @@ sealed class RuntimeWithServiceBuilder( object service, RuntimeWithServiceBuilder.ObjectBox observedServiceBox ) : - AllureRuntimeBuilder< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - IAllureRuntimeIntegrationContext< - AllureConfiguration, - IAllureRuntimeRegistrationContext, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - RuntimeWithService - >, - RuntimeWithServiceRegistrationSnapshot, - RuntimeWithService - >(runtimeName, () => new RuntimeWithServiceRegistrationSession(service, observedServiceBox.SetValue)) + AllureRuntimeBuilder( + runtimeName, + () => new RuntimeWithServiceRegistrationSession(service, observedServiceBox.SetValue) + ) { public RuntimeWithServiceBuilder(string runtimeName, object service) : this(runtimeName, service, new()) { @@ -280,18 +246,8 @@ sealed class RuntimeWithServiceRouteBuilder( RuntimeWithService > args ) : - AllureInProcessRouteBuilder< - AllureConfiguration, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook, - RuntimeWithService - >(args) + AllureInProcessRouteBuilder(args) { public object Service => this.Runtime.Service; - - protected override IAllureInProcessEndpointRegistrationContext< - AllureConfiguration, - RuntimeWithService - > RegistrationContext => this; } } diff --git a/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs index 5ea4a425..3524b3e2 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs @@ -3,6 +3,7 @@ using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Results; using Allure.Net.Sdk.Tests.Infrastructure; +using Allure.Sdk.Runtime; namespace Allure.Net.Sdk.Tests.Registration; @@ -218,8 +219,8 @@ public async Task ShouldRunEndpointHooksInOrderWithFinalConfiguration() var original = new TestConfiguration { Value = "original" }; var final = new TestConfiguration { Value = "final" }; var calls = new List(); - var first = new RecordingEndpointHook(_ => calls.Add("first")); - var second = new RecordingEndpointHook(_ => calls.Add("second")); + var first = new RecordingEndpointHook>(_ => calls.Add("first")); + var second = new RecordingEndpointHook>(_ => calls.Add("second")); var builder = CreateBuilder(); var plan = builder.Prepare((ctx) => { @@ -234,9 +235,9 @@ public async Task ShouldRunEndpointHooksInOrderWithFinalConfiguration() { context.UseCurrentScopePredicate(_ => false); context.UseGlobalScopePredicate(_ => false); - context.UseRegistrationHooks(received => + context.UseRegistrationHooks(runtime => { - calls.Add(ReferenceEquals(received, final) ? "configuration" : "unexpected"); + calls.Add(ReferenceEquals(runtime.Configuration, final) ? "configuration" : "unexpected"); return [first, null, second]; }); } @@ -257,7 +258,7 @@ public async Task ShouldRunEndpointHooksInOrderWithFinalConfiguration() [Test] public async Task ShouldPropagateEndpointHookExceptions() { - var laterHook = new RecordingEndpointHook(); + var laterHook = new RecordingEndpointHook>(); var builder = CreateBuilder(); var plan = builder.Prepare((ctx) => { @@ -266,7 +267,7 @@ public async Task ShouldPropagateEndpointHookExceptions() $"endpoint-hook-failure-{Guid.NewGuid():N}", (_, context) => context.UseRegistrationHooks(_ => [ - new RecordingEndpointHook(_ => + new RecordingEndpointHook>(_ => throw new InvalidOperationException("endpoint hook failed") ), laterHook, @@ -343,34 +344,34 @@ public async Task ShouldResolveReflectionHooksAndIgnoreMissingValues() { var typeName = typeof(ReflectionRuntimeHook).AssemblyQualifiedName!; var fromConfiguration = ReflectionHooks - .FromConfiguration( + .FromConfiguration>>( new() { RuntimeRegistrationHook = typeName } ); var variableName = $"ALLURE_SDK_TEST_HOOK_{Guid.NewGuid():N}"; Environment.SetEnvironmentVariable(variableName, null); var fromEnvironment = ReflectionHooks - .FromEnvironmentVariable(variableName); + .FromEnvironmentVariable>>(variableName); await Assert.That(fromConfiguration).IsTypeOf(); await Assert.That(fromEnvironment).IsNull(); await Assert.That( - ReflectionHooks.FromConfiguration(new()) + ReflectionHooks.FromConfiguration>>(new()) ).IsNull(); } [Test] public async Task ShouldRejectInvalidReflectionHooks() { - await Assert.That(() => ReflectionHooks.FromConfiguration( + await Assert.That(() => ReflectionHooks.FromConfiguration>>( new() { RuntimeRegistrationHook = typeof(NotARegistrationHook).AssemblyQualifiedName } )).Throws().WithMessageContaining("must implement"); - await Assert.That(() => ReflectionHooks.FromConfiguration( + await Assert.That(() => ReflectionHooks.FromConfiguration>>( new() { RuntimeRegistrationHook = typeof(PrivateConstructorRuntimeHook).AssemblyQualifiedName } )).Throws().WithMessageContaining("public parameterless constructor"); - await Assert.That(() => ReflectionHooks.FromConfiguration( + await Assert.That(() => ReflectionHooks.FromConfiguration>>( new() { RuntimeRegistrationHook = "No.Such.Hook, No.Such.Assembly" } )).Throws(); } @@ -385,26 +386,26 @@ sealed record class TestConfiguration : AllureConfiguration public string? Value { get; init; } } - public class ReflectionRuntimeHook : IAllureRuntimeRegistrationHook + public class ReflectionRuntimeHook : IAllureRegistrationHook> { public static System.Collections.Concurrent.ConcurrentQueue Calls { get; } = []; - public void SetUp(IAllureRuntimeRegistrationContext context) + public void SetUp(IAllureRuntimeRegistrationContext context) => Calls.Enqueue("configuration"); } - public sealed class EnvironmentReflectionRuntimeHook : IAllureRuntimeRegistrationHook + public sealed class EnvironmentReflectionRuntimeHook : IAllureRegistrationHook> { - public void SetUp(IAllureRuntimeRegistrationContext context) => + public void SetUp(IAllureRuntimeRegistrationContext context) => ReflectionRuntimeHook.Calls.Enqueue("environment"); } public sealed class NotARegistrationHook; - public sealed class PrivateConstructorRuntimeHook : IAllureRuntimeRegistrationHook + public sealed class PrivateConstructorRuntimeHook : IAllureRegistrationHook> { PrivateConstructorRuntimeHook() { } - public void SetUp(IAllureRuntimeRegistrationContext context) { } + public void SetUp(IAllureRuntimeRegistrationContext context) { } } } diff --git a/tests/Allure.Net.Sdk.Tests/Serialization/SerializerSelectionTests.cs b/tests/Allure.Net.Sdk.Tests/Serialization/SerializerSelectionTests.cs index fadc843b..f4d6521e 100644 --- a/tests/Allure.Net.Sdk.Tests/Serialization/SerializerSelectionTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Serialization/SerializerSelectionTests.cs @@ -157,13 +157,7 @@ await Assert.That(registration.Runtime.ParameterSerializer.Serialize(17)) } static IAllureRuntimeRegistrationPlan> PrepareBuilder( - Action, - RecordingRuntimeHook, - IAllureInProcessEndpointRegistrationContext, - RecordingEndpointHook - >> configure + Action> configure ) { var builder = new TestRuntimeBuilder("serializer-selection"); From 0f72a63e75463811554bdb0cdcf4e6a264c8667a Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 14:05:52 +0700 Subject: [PATCH 02/14] feat(sdk): remove registration snapshots --- .../PreparedRuntimeRegistration.cs | 7 +-- .../AllureRuntimeIntegrationSnapshot.cs | 48 ----------------- .../AllureRuntimeRegistrationSession.cs | 48 ++++++++++++----- .../IAllureRuntimeIntegrationSnapshot.cs | 52 ------------------- .../Infrastructure/RuntimeTestEnvironment.cs | 17 ++---- .../AllureRuntimeRegistrationTests.cs | 28 ++++------ .../InProcessEndpointRegistrationTests.cs | 30 ++++------- 7 files changed, 62 insertions(+), 168 deletions(-) delete mode 100644 src/Allure.Net.Sdk/Registration/AllureRuntimeIntegrationSnapshot.cs delete mode 100644 src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationSnapshot.cs diff --git a/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs b/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs index c6836cae..5c81db74 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs @@ -12,7 +12,8 @@ internal class PreparedRuntimeRegistration( string runtimeName, TConfiguration configuration, AllureRuntimeRegistrationSnapshot commonSnapshot, - IAllureRuntimeIntegrationSnapshot integrationSnapshot + Func, TRuntime> runtimeFactory, + Func, IPreparedInProcessRouteBuilder> routeBuilderFactory ) : IPreparedRuntimeRegistration @@ -48,7 +49,7 @@ public IAllureRuntimeRegistration Build() ModelApi: modelApi ); - var runtime = integrationSnapshot.CreateRuntime(runtimeCreationArguments); + var runtime = runtimeFactory(runtimeCreationArguments); IDisposable? endpointRegistration = null; @@ -66,7 +67,7 @@ public IAllureRuntimeRegistration Build() commonSnapshot.RuleBasedSerializerRegistrations, routeRegistration ); - var endpointRouteBuilder = integrationSnapshot.CreateRouteBuilder(endpointBuildArgs); + var endpointRouteBuilder = routeBuilderFactory(endpointBuildArgs); var route = endpointRouteBuilder.Build(); endpointRegistration = AllureRuntimeRouter.Install(route); diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeIntegrationSnapshot.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeIntegrationSnapshot.cs deleted file mode 100644 index 0eeca29d..00000000 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeIntegrationSnapshot.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Allure.Sdk.Configuration; -using Allure.Sdk.Runtime; - -namespace Allure.Sdk.Registration; - -/// -/// Provides the standard runtime factory and an integration-specific in-process route -/// builder factory. -/// -/// The runtime configuration type. -public abstract class AllureRuntimeIntegrationSnapshot() : - IAllureRuntimeIntegrationSnapshot - - where TConfiguration : AllureConfiguration -{ - /// - public abstract IPreparedInProcessRouteBuilder CreateRouteBuilder( - AllureRouteBuilderArgs> args - ); - - /// - public IAllureRuntime CreateRuntime( - RuntimeCreationArguments args - ) => - new AllureRuntime( - args.Configuration, - args.ParameterSerializer, - args.Destination, - args.Context, - args.LifecycleApi, - args.ModelApi - ); -} - -/// -/// Provides the factories used to construct a standard Allure runtime and its -/// in-process route builder. -/// -public class AllureRuntimeIntegrationSnapshot() : - AllureRuntimeIntegrationSnapshot, - IAllureRuntimeIntegrationSnapshot -{ - /// - public override IPreparedInProcessRouteBuilder CreateRouteBuilder( - AllureRouteBuilderArgs> args - ) => - new AllureInProcessRouteBuilder(args); -} diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index c4f8e3b8..6d366def 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -200,11 +200,11 @@ protected void Modify(Action action) /// protected abstract TRegistrationContext RegistrationContext { get; } - /// - /// Captures the integration-specific factories required after the session closes. - /// - /// The immutable integration snapshot. - protected abstract IAllureRuntimeIntegrationSnapshot CaptureIntegrationSnapshot(); + protected abstract TRuntime CreateRuntime(RuntimeCreationArguments args); + + protected abstract IPreparedInProcessRouteBuilder CreateRouteBuilder( + AllureRouteBuilderArgs args + ); internal IPreparedRuntimeRegistration Prepare( string runtimeName, @@ -226,14 +226,14 @@ Action registration this.CloseRegistration(); var commonSnapshot = this.CaptureCommonSnapshot(); - var integrationSnapshot = this.CaptureIntegrationSnapshot(); return new PreparedRuntimeRegistration( runtimeName, finalConfiguration.Configuration, commonSnapshot, - integrationSnapshot + this.CreateRuntime, + this.CreateRouteBuilder ); } catch @@ -416,6 +416,18 @@ public abstract class AllureRuntimeRegistrationSession : protected override IAllureRuntimeIntegrationContext IntegrationContext => this; protected override IAllureRuntimeRegistrationContext RegistrationContext => this; + + protected override IAllureRuntime CreateRuntime( + RuntimeCreationArguments args + ) => + new AllureRuntime( + args.Configuration, + args.ParameterSerializer, + args.Destination, + args.Context, + args.LifecycleApi, + args.ModelApi + ); } public class AllureRuntimeRegistrationSession : @@ -427,12 +439,24 @@ public class AllureRuntimeRegistrationSession : >, IAllureRuntimeIntegrationContext { - protected override IAllureRuntimeIntegrationSnapshot> CaptureIntegrationSnapshot() - { - return new AllureRuntimeIntegrationSnapshot(); - } - protected override IAllureRuntimeIntegrationContext IntegrationContext => this; protected override IAllureRuntimeRegistrationContext RegistrationContext => this; + + protected override IAllureRuntime CreateRuntime( + RuntimeCreationArguments args + ) => + new AllureRuntime( + args.Configuration, + args.ParameterSerializer, + args.Destination, + args.Context, + args.LifecycleApi, + args.ModelApi + ); + + protected override IPreparedInProcessRouteBuilder CreateRouteBuilder( + AllureRouteBuilderArgs> args + ) => + new AllureInProcessRouteBuilder(args); } diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationSnapshot.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationSnapshot.cs deleted file mode 100644 index 8e35fa8a..00000000 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationSnapshot.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Allure.Sdk.Configuration; -using Allure.Sdk.Registration.Hooks; -using Allure.Sdk.Runtime; - -namespace Allure.Sdk.Registration; - -/// -/// Captures the integration-specific factories used to construct a custom runtime and -/// its in-process route builder. -/// -/// The runtime configuration type. -/// The runtime type. -public interface IAllureRuntimeIntegrationSnapshot - where TConfiguration : AllureConfiguration - where TRuntime : IAllureRuntime -{ - /// - /// Creates the runtime from its resolved components. - /// - /// The resolved runtime components. - /// The constructed runtime. - TRuntime CreateRuntime(RuntimeCreationArguments args); - - /// - /// Creates the builder used to configure the runtime's in-process route. - /// - /// The resolved route builder arguments. - /// The in-process route builder. - IPreparedInProcessRouteBuilder CreateRouteBuilder( - AllureRouteBuilderArgs args - ); -} - -/// -/// Captures the integration-specific factories used to construct a standard runtime -/// with custom configuration. -/// -/// The runtime configuration type. -public interface IAllureRuntimeIntegrationSnapshot : - IAllureRuntimeIntegrationSnapshot< - TConfiguration, - IAllureRuntime - > - - where TConfiguration : AllureConfiguration; - -/// -/// Captures the factories used to construct a standard Allure runtime and its -/// in-process route builder. -/// -public interface IAllureRuntimeIntegrationSnapshot : - IAllureRuntimeIntegrationSnapshot; diff --git a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs index 92235856..6fbd0b41 100644 --- a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs +++ b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs @@ -48,25 +48,16 @@ public void Dispose() } } -sealed class TestRuntimeRegistrationSnapshot : - AllureRuntimeIntegrationSnapshot - - where TConfiguration : AllureConfiguration -{ - public override IPreparedInProcessRouteBuilder CreateRouteBuilder(AllureRouteBuilderArgs> args) - { - return new TestEndpointRouteBuilder(args); - } -} - sealed class TestRuntimeRegistrationSession : AllureRuntimeRegistrationSession where TConfiguration : AllureConfiguration, new() { - protected override IAllureRuntimeIntegrationSnapshot> CaptureIntegrationSnapshot() + protected override IPreparedInProcessRouteBuilder CreateRouteBuilder( + AllureRouteBuilderArgs> args + ) { - return new TestRuntimeRegistrationSnapshot(); + return new TestEndpointRouteBuilder(args); } } diff --git a/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs index 24f18594..52a4ab2f 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs @@ -213,19 +213,14 @@ public ValueTask DisposeAsync() } } - sealed class RegistrationTestRuntimeRegistrationSnapshot( + sealed class RegistrationTestRuntimeRegistrationSession( RuntimeFactory runtimeFactory ) : - IAllureRuntimeIntegrationSnapshot + AllureRuntimeRegistrationSession where TRuntime : IAllureRuntime { - public IPreparedInProcessRouteBuilder CreateRouteBuilder(AllureRouteBuilderArgs args) - { - return new RegistrationTestRouteBuilder(args); - } - - public TRuntime CreateRuntime(RuntimeCreationArguments args) + protected override TRuntime CreateRuntime(RuntimeCreationArguments args) { return runtimeFactory(new( args.Configuration, @@ -236,18 +231,13 @@ public TRuntime CreateRuntime(RuntimeCreationArguments args args.ModelApi )); } - } - - sealed class RegistrationTestRuntimeRegistrationSession( - RuntimeFactory runtimeFactory - ) : - AllureRuntimeRegistrationSession - where TRuntime : IAllureRuntime - { - protected override RegistrationTestRuntimeRegistrationSnapshot CaptureIntegrationSnapshot() => new( - runtimeFactory - ); + protected override IPreparedInProcessRouteBuilder CreateRouteBuilder( + AllureRouteBuilderArgs args + ) + { + return new RegistrationTestRouteBuilder(args); + } } sealed class RegistrationTestRuntimeBuilder( diff --git a/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs index d3f3882c..5e3b5f18 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs @@ -184,34 +184,22 @@ object service public object Service { get; } = service; } - sealed class RuntimeWithServiceRegistrationSnapshot(object service, Action notifyRouteBuilderService) : - IAllureRuntimeIntegrationSnapshot< - AllureConfiguration, - RuntimeWithService - > - { - public IPreparedInProcessRouteBuilder CreateRouteBuilder(AllureRouteBuilderArgs args) - { - var builder = new RuntimeWithServiceRouteBuilder(args); - notifyRouteBuilderService(service); - return builder; - } - - public RuntimeWithService CreateRuntime(RuntimeCreationArguments args) - { - return new (args.Configuration, args.ParameterSerializer, args.Destination, args.Context, args.LifecycleApi, args.ModelApi, service); - } - } - sealed class RuntimeWithServiceRegistrationSession( object service, Action notifyRouteBuilderService ) : AllureRuntimeRegistrationSession { - protected override RuntimeWithServiceRegistrationSnapshot CaptureIntegrationSnapshot() + protected override RuntimeWithService CreateRuntime(RuntimeCreationArguments args) + { + return new (args.Configuration, args.ParameterSerializer, args.Destination, args.Context, args.LifecycleApi, args.ModelApi, service); + } + + protected override IPreparedInProcessRouteBuilder CreateRouteBuilder(AllureRouteBuilderArgs args) { - return new(service, notifyRouteBuilderService); + var builder = new RuntimeWithServiceRouteBuilder(args); + notifyRouteBuilderService(service); + return builder; } } From a8915c2c278d68311301f1c80d1b4b72e986bb6f Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 14:29:45 +0700 Subject: [PATCH 03/14] feat(sdk): make endpoint build internal --- .../AllureInProcessRouteBuilder.cs | 29 ++------ .../PreparedRuntimeRegistration.cs | 10 +-- .../Registration/AllureRouteBuilderArgs.cs | 6 +- .../Registration/AllureRuntimeBuilder.cs | 14 +--- .../AllureRuntimeRegistrationSession.cs | 13 +--- .../IPreparedInProcessRouteBuilder.cs | 8 -- .../Infrastructure/RuntimeTestEnvironment.cs | 45 +----------- .../AllureRuntimeRegistrationTests.cs | 17 ----- .../ConfigurationResolutionTests.cs | 2 +- .../InProcessEndpointRegistrationTests.cs | 73 ++----------------- .../Registration/RegistrationHookTests.cs | 2 +- .../RuntimeComponentRegistrationTests.cs | 2 +- .../Serialization/SerializerSelectionTests.cs | 2 +- 13 files changed, 27 insertions(+), 196 deletions(-) rename src/Allure.Net.Sdk/{ => Internal}/Registration/AllureInProcessRouteBuilder.cs (84%) delete mode 100644 src/Allure.Net.Sdk/Registration/IPreparedInProcessRouteBuilder.cs diff --git a/src/Allure.Net.Sdk/Registration/AllureInProcessRouteBuilder.cs b/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessRouteBuilder.cs similarity index 84% rename from src/Allure.Net.Sdk/Registration/AllureInProcessRouteBuilder.cs rename to src/Allure.Net.Sdk/Internal/Registration/AllureInProcessRouteBuilder.cs index d5bdcba2..f14a0e19 100644 --- a/src/Allure.Net.Sdk/Registration/AllureInProcessRouteBuilder.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessRouteBuilder.cs @@ -4,20 +4,14 @@ using Allure.Abstractions; using Allure.Sdk.Configuration; using Allure.Sdk.Internal.Runtime; +using Allure.Sdk.Registration; using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Runtime; -namespace Allure.Sdk.Registration; +namespace Allure.Sdk.Internal.Registration; -/// -/// Provides the base implementation for builders that construct an in-process -/// endpoint route with an integration-specific registration context and hook. -/// -/// The runtime configuration type. -/// The runtime type. -public class AllureInProcessRouteBuilder : - IAllureInProcessEndpointIntegrationContext, - IPreparedInProcessRouteBuilder +internal class AllureInProcessRouteBuilder : + IAllureInProcessEndpointIntegrationContext where TConfiguration : AllureConfiguration where TRuntime : IAllureRuntime @@ -61,7 +55,7 @@ public class AllureInProcessRouteBuilder : /// its runtime builder. /// /// The resolved route builder arguments. - public AllureInProcessRouteBuilder(AllureRouteBuilderArgs args) + public AllureInProcessRouteBuilder(EndpointRouteCreationArguments args) { this.useRuleBasedSerializer = args.UseRuleBasedSerializer; this.runtimeName = args.RuntimeName; @@ -197,16 +191,3 @@ void RunHooks() } } } - -public class AllureInProcessRouteBuilder( - AllureRouteBuilderArgs> args -) : - AllureInProcessRouteBuilder>(args) - - where TConfiguration : AllureConfiguration; - -class AllureInProcessRouteBuilder( - AllureRouteBuilderArgs> args -) : - AllureInProcessRouteBuilder(args), - IAllureInProcessEndpointIntegrationContext; diff --git a/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs b/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs index 5c81db74..a7f9a601 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; +using Allure.Abstractions; using Allure.Runtime; using Allure.Sdk.Configuration; using Allure.Sdk.Registration; -using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Runtime; namespace Allure.Sdk.Internal.Registration; @@ -13,7 +13,7 @@ internal class PreparedRuntimeRegistration( TConfiguration configuration, AllureRuntimeRegistrationSnapshot commonSnapshot, Func, TRuntime> runtimeFactory, - Func, IPreparedInProcessRouteBuilder> routeBuilderFactory + Func, IAllureRuntimeRoute> routeFactory ) : IPreparedRuntimeRegistration @@ -59,7 +59,7 @@ public IAllureRuntimeRegistration Build() if (commonSnapshot.EndpointRegistration is var (routeId, routeRegistration)) { - AllureRouteBuilderArgs endpointBuildArgs = new( + EndpointRouteCreationArguments endpointBuildArgs = new( runtimeName, routeId, runtime, @@ -67,9 +67,9 @@ public IAllureRuntimeRegistration Build() commonSnapshot.RuleBasedSerializerRegistrations, routeRegistration ); - var endpointRouteBuilder = routeBuilderFactory(endpointBuildArgs); - var route = endpointRouteBuilder.Build(); + var route = routeFactory(endpointBuildArgs); + endpointRegistration = AllureRuntimeRouter.Install(route); } diff --git a/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs b/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs index 8dcc51dc..ba0c6247 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs @@ -7,7 +7,7 @@ namespace Allure.Sdk.Registration; /// /// Carries the components resolved by a runtime builder into an in-process -/// route builder. +/// endpoint route. /// /// /// Instances are created by the SDK and supplied to @@ -15,7 +15,7 @@ namespace Allure.Sdk.Registration; /// /// The runtime configuration type. /// The runtime type. -public class AllureRouteBuilderArgs +public class EndpointRouteCreationArguments where TConfiguration : AllureConfiguration where TRuntime : IAllureRuntime { @@ -26,7 +26,7 @@ public class AllureRouteBuilderArgs internal IEnumerable> RuleBasedSerializerRegistrations { get; } internal Action> Registration { get; } - internal AllureRouteBuilderArgs( + internal EndpointRouteCreationArguments( string runtimeName, string routeId, TRuntime runtime, diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs index 7f480f74..3ac66d21 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs @@ -124,17 +124,7 @@ public class AllureRuntimeBuilder( where TConfiguration : AllureConfiguration, new() where TRuntime : IAllureRuntime; -public class AllureRuntimeBuilder( - string runtimeName, - Func< - AllureRuntimeRegistrationSession< - TConfiguration, - IAllureRuntime, - IAllureRuntimeRegistrationContext, - IAllureRuntimeIntegrationContext - > - > sessionFactory -) : +public class AllureRuntimeBuilder(string runtimeName) : AllureRuntimeBuilder< TConfiguration, IAllureRuntime, @@ -142,7 +132,7 @@ public class AllureRuntimeBuilder( IAllureRuntimeIntegrationContext >( runtimeName, - sessionFactory + () => new AllureRuntimeRegistrationSession() ) where TConfiguration : AllureConfiguration, new(); diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index 6d366def..7e824279 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -202,10 +202,6 @@ protected void Modify(Action action) protected abstract TRuntime CreateRuntime(RuntimeCreationArguments args); - protected abstract IPreparedInProcessRouteBuilder CreateRouteBuilder( - AllureRouteBuilderArgs args - ); - internal IPreparedRuntimeRegistration Prepare( string runtimeName, Action registration @@ -233,7 +229,7 @@ Action registration finalConfiguration.Configuration, commonSnapshot, this.CreateRuntime, - this.CreateRouteBuilder + (args) => new AllureInProcessRouteBuilder(args).Build() ); } catch @@ -402,7 +398,7 @@ public abstract class AllureRuntimeRegistrationSession protected override IAllureRuntimeIntegrationContext IntegrationContext => this; } -public abstract class AllureRuntimeRegistrationSession : +public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< TConfiguration, IAllureRuntime, @@ -454,9 +450,4 @@ RuntimeCreationArguments args args.LifecycleApi, args.ModelApi ); - - protected override IPreparedInProcessRouteBuilder CreateRouteBuilder( - AllureRouteBuilderArgs> args - ) => - new AllureInProcessRouteBuilder(args); } diff --git a/src/Allure.Net.Sdk/Registration/IPreparedInProcessRouteBuilder.cs b/src/Allure.Net.Sdk/Registration/IPreparedInProcessRouteBuilder.cs deleted file mode 100644 index aa18b0c3..00000000 --- a/src/Allure.Net.Sdk/Registration/IPreparedInProcessRouteBuilder.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Allure.Abstractions; - -namespace Allure.Sdk.Registration; - -public interface IPreparedInProcessRouteBuilder -{ - IAllureRuntimeRoute Build(); -} diff --git a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs index 6fbd0b41..81e0577c 100644 --- a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs +++ b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs @@ -31,7 +31,7 @@ public static RuntimeTestEnvironment Create( ) { var destination = new InMemoryResultsDestination(); - var builder = new TestRuntimeBuilder("sdk-test"); + var builder = new AllureRuntimeBuilder("sdk-test"); var plan = builder.Prepare((ctx) => { ctx.UseConfiguration(configuration ?? new TConfiguration()); @@ -48,34 +48,6 @@ public void Dispose() } } -sealed class TestRuntimeRegistrationSession : - AllureRuntimeRegistrationSession - - where TConfiguration : AllureConfiguration, new() -{ - protected override IPreparedInProcessRouteBuilder CreateRouteBuilder( - AllureRouteBuilderArgs> args - ) - { - return new TestEndpointRouteBuilder(args); - } -} - -sealed class TestRuntimeBuilder(string runtimeName) : - AllureRuntimeBuilder(runtimeName, () => new TestRuntimeRegistrationSession()) - - where TConfiguration : AllureConfiguration, new(); - -sealed class TestEndpointRouteBuilder( - AllureRouteBuilderArgs< - TConfiguration, - IAllureRuntime - > args -) : - AllureInProcessRouteBuilder(args) - - where TConfiguration : AllureConfiguration; - sealed class RuntimeTestEnvironment { public static RuntimeTestEnvironment Create( @@ -117,18 +89,3 @@ IAllureInProcessEndpointRegistrationContext context setUp?.Invoke(context); } } - -sealed class RecordingEndpointHook( - Action>>? setUp = null -) : IAllureRegistrationHook>> -{ - public int CallCount { get; private set; } - - public void SetUp( - IAllureInProcessEndpointRegistrationContext> context - ) - { - this.CallCount++; - setUp?.Invoke(context); - } -} diff --git a/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs index 52a4ab2f..398c01cf 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/AllureRuntimeRegistrationTests.cs @@ -231,13 +231,6 @@ protected override TRuntime CreateRuntime(RuntimeCreationArguments args - ) - { - return new RegistrationTestRouteBuilder(args); - } } sealed class RegistrationTestRuntimeBuilder( @@ -250,15 +243,5 @@ RuntimeFactory runtimeFactory where TRuntime : IAllureRuntime; - sealed class RegistrationTestRouteBuilder( - AllureRouteBuilderArgs args - ) : - AllureInProcessRouteBuilder< - AllureConfiguration, - TRuntime - >(args) - - where TRuntime : IAllureRuntime; - sealed class TestException : Exception; } diff --git a/tests/Allure.Net.Sdk.Tests/Registration/ConfigurationResolutionTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/ConfigurationResolutionTests.cs index ccaf0f8b..c4a9e5c1 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/ConfigurationResolutionTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/ConfigurationResolutionTests.cs @@ -162,7 +162,7 @@ await Assert.That(runtime.Runtime.Configuration.Value) } } - static TestRuntimeBuilder CreateBuilder() => + static AllureRuntimeBuilder CreateBuilder() => new("configuration-tests"); sealed record class TestConfiguration : AllureConfiguration diff --git a/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs index 5e3b5f18..110a062a 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs @@ -133,33 +133,7 @@ await Assert.That(syncOperations.AddGlobalAttachment( isInGlobalScope.Value = false; } - [Test] - public async Task ShouldExposeIntegrationSpecificRuntimeToRouteBuilder() - { - var service = new object(); - var builder = new RuntimeWithServiceBuilder( - "endpoint-registration-tests", - service - ); - - var plan = builder.Prepare((ctx) => - { - ctx.RegisterInProcessEndpoint(NewRouteId(), (_, ctx) => - { - ctx.SetAvailabilityPredicate((_) => false); - ctx.UseCurrentScopePredicate((_) => false); - ctx.UseGlobalScopePredicate((_) => false); - }); - }); - - - using var _ = plan.Build(); - - await Assert.That(builder.ServiceObservedByRouteBuilder) - .IsSameReferenceAs(service); - } - - static TestRuntimeBuilder CreateBuilder() => + static AllureRuntimeBuilder CreateBuilder() => new("endpoint-registration-tests"); static string NewRouteId() => $"endpoint-registration-{Guid.NewGuid():N}"; @@ -184,58 +158,21 @@ object service public object Service { get; } = service; } - sealed class RuntimeWithServiceRegistrationSession( - object service, - Action notifyRouteBuilderService - ) : + sealed class RuntimeWithServiceRegistrationSession(object service) : AllureRuntimeRegistrationSession { protected override RuntimeWithService CreateRuntime(RuntimeCreationArguments args) { return new (args.Configuration, args.ParameterSerializer, args.Destination, args.Context, args.LifecycleApi, args.ModelApi, service); } - - protected override IPreparedInProcessRouteBuilder CreateRouteBuilder(AllureRouteBuilderArgs args) - { - var builder = new RuntimeWithServiceRouteBuilder(args); - notifyRouteBuilderService(service); - return builder; - } } sealed class RuntimeWithServiceBuilder( string runtimeName, - object service, - RuntimeWithServiceBuilder.ObjectBox observedServiceBox + object service ) : AllureRuntimeBuilder( runtimeName, - () => new RuntimeWithServiceRegistrationSession(service, observedServiceBox.SetValue) - ) - { - public RuntimeWithServiceBuilder(string runtimeName, object service) : this(runtimeName, service, new()) - { - - } - - public object? ServiceObservedByRouteBuilder => observedServiceBox.Value; - - internal class ObjectBox() - { - public object? Value { get; private set; } = null; - - public void SetValue(object value) => this.Value = value; - } - } - - sealed class RuntimeWithServiceRouteBuilder( - AllureRouteBuilderArgs< - AllureConfiguration, - RuntimeWithService - > args - ) : - AllureInProcessRouteBuilder(args) - { - public object Service => this.Runtime.Service; - } + () => new RuntimeWithServiceRegistrationSession(service) + ); } diff --git a/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs index 3524b3e2..05a9eb71 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs @@ -376,7 +376,7 @@ await Assert.That(() => ReflectionHooks.FromConfiguration(); } - static TestRuntimeBuilder CreateBuilder() => + static AllureRuntimeBuilder CreateBuilder() => new("hook-tests"); static AllureRuntimeBuilder CreateReflectionBuilder() => new("reflection-hook-tests"); diff --git a/tests/Allure.Net.Sdk.Tests/Registration/RuntimeComponentRegistrationTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/RuntimeComponentRegistrationTests.cs index bc50b700..68e69fa5 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/RuntimeComponentRegistrationTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/RuntimeComponentRegistrationTests.cs @@ -165,7 +165,7 @@ await Assert.That(modelConfiguration) await Assert.That(registration.Runtime.ModelApi).IsSameReferenceAs(model); } - static TestRuntimeBuilder CreateBuilder() => + static AllureRuntimeBuilder CreateBuilder() => new("component-tests"); static string NewDirectoryPath() => diff --git a/tests/Allure.Net.Sdk.Tests/Serialization/SerializerSelectionTests.cs b/tests/Allure.Net.Sdk.Tests/Serialization/SerializerSelectionTests.cs index f4d6521e..44739610 100644 --- a/tests/Allure.Net.Sdk.Tests/Serialization/SerializerSelectionTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Serialization/SerializerSelectionTests.cs @@ -160,7 +160,7 @@ static IAllureRuntimeRegistrationPlan> configure ) { - var builder = new TestRuntimeBuilder("serializer-selection"); + var builder = new AllureRuntimeBuilder("serializer-selection"); var plan = builder.Prepare((ctx) => { ctx.UseConfiguration(new AllureConfiguration()); From 96efbcd79ff30bc9ad31a28f1574e7477f75f1b4 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 14:52:42 +0700 Subject: [PATCH 04/14] refactor(sdk): optimize route building --- .../AllureInProcessRouteBuilder.cs | 51 +++++++------------ .../PreparedRuntimeRegistration.cs | 27 +++++----- .../Registration/AllureRouteBuilderArgs.cs | 45 ---------------- .../Registration/AllureRuntimeBuilder.cs | 1 - .../AllureRuntimeRegistrationSession.cs | 3 +- .../InProcessEndpointRegistrationTests.cs | 23 +++++++++ 6 files changed, 53 insertions(+), 97 deletions(-) delete mode 100644 src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs diff --git a/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessRouteBuilder.cs b/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessRouteBuilder.cs index f14a0e19..6ac186b0 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessRouteBuilder.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/AllureInProcessRouteBuilder.cs @@ -43,26 +43,25 @@ internal class AllureInProcessRouteBuilder : readonly List> currentRuleBasedSerializerRegistrations; - readonly Action> registration; + readonly Action> endpointRegistration; - /// - /// Gets the integration-specific runtime associated with this route. - /// protected TRuntime Runtime { get; } - /// - /// Initializes an in-process route builder from the components resolved by - /// its runtime builder. - /// - /// The resolved route builder arguments. - public AllureInProcessRouteBuilder(EndpointRouteCreationArguments args) + public AllureInProcessRouteBuilder( + string runtimeName, + string routeId, + TRuntime runtime, + bool useRuleBasedSerializer, + IEnumerable> ruleBasedSerializerRegistrations, + Action> endpointRegistration + ) { - this.useRuleBasedSerializer = args.UseRuleBasedSerializer; - this.runtimeName = args.RuntimeName; - this.routeId = args.RouteId; - this.Runtime = args.Runtime; + this.useRuleBasedSerializer = useRuleBasedSerializer; + this.runtimeName = runtimeName; + this.routeId = routeId; + this.Runtime = runtime; this.currentRuleBasedSerializerRegistrations = [ - .. args.RuleBasedSerializerRegistrations + .. ruleBasedSerializerRegistrations .Select((registration) => (Action)( (runtime, context) => registration(runtime.Configuration, context) @@ -73,13 +72,12 @@ .. args.RuleBasedSerializerRegistrations useRuleBasedSerializer ? (runtime) => AllureRegistrationDefaults.EndpointParameterSerializer( - currentRuleBasedSerializerRegistrations + this.currentRuleBasedSerializerRegistrations )(runtime) : (_) => this.Runtime.ParameterSerializer; - this.registration = args.Registration; + this.endpointRegistration = endpointRegistration; } - /// public void UseRegistrationHooks( Func>?>> hooksFactory ) @@ -87,49 +85,41 @@ public void UseRegistrationHooks( this.currentHooksFactory = hooksFactory; } - /// public void SetAvailabilityPredicate(Func isAvailable) { this.availabilityPredicate = isAvailable; } - /// public void SetAvailabilityPredicate(Func isAvailable) { this.availabilityPredicate = (_) => isAvailable(); } - /// public void SuppressRoutes(Func> suppressedRouteIdsFactory) { this.currentSuppressedRouteIdsFactory = suppressedRouteIdsFactory; } - /// public void SuppressRoutes(Func> suppressedRouteIdsFactory) { this.currentSuppressedRouteIdsFactory = (_) => suppressedRouteIdsFactory(); } - /// public void UseCurrentScopePredicate(Func predicate) { this.currentScopePredicate = predicate; } - /// public void UseGlobalScopePredicate(Func predicate) { this.globalScopePredicate = predicate; } - /// public void UseOperations(Func operationsFactory) { this.currentOperationsFactory = operationsFactory; } - /// public void UseParameterSerializer(Func serializerFactory) { this.useRuleBasedSerializer = false; @@ -137,11 +127,9 @@ public void UseParameterSerializer(Func se this.currentSerializerFactory = serializerFactory; } - /// public void UseParameterSerializer(Func serializerFactory) => this.UseParameterSerializer((_) => serializerFactory()); - /// public void ConfigureSerialization(Action registration) { if (!this.useRuleBasedSerializer) @@ -155,19 +143,14 @@ public void ConfigureSerialization(Action public void ConfigureSerialization(Action registration) { this.ConfigureSerialization((_, ctx) => registration(ctx)); } - /// - /// Runs the configured endpoint hooks and constructs the route. - /// - /// The constructed in-process runtime route. public IAllureRuntimeRoute Build() { - this.registration(this.Runtime, this); + this.endpointRegistration(this.Runtime, this); this.RunHooks(); return new AllureRuntimeRoute( routeId, diff --git a/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs b/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs index a7f9a601..c3b77693 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/PreparedRuntimeRegistration.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Allure.Abstractions; using Allure.Runtime; using Allure.Sdk.Configuration; using Allure.Sdk.Registration; @@ -11,9 +10,8 @@ namespace Allure.Sdk.Internal.Registration; internal class PreparedRuntimeRegistration( string runtimeName, TConfiguration configuration, - AllureRuntimeRegistrationSnapshot commonSnapshot, - Func, TRuntime> runtimeFactory, - Func, IAllureRuntimeRoute> routeFactory + AllureRuntimeRegistrationSnapshot registrationSnapshot, + Func, TRuntime> runtimeFactory ) : IPreparedRuntimeRegistration @@ -24,8 +22,8 @@ Func, IAllureRuntimeRou public IAllureRuntimeRegistration Build() { - var parameterSerializer = commonSnapshot.SerializerFactory(configuration); - var destination = commonSnapshot.DestinationFactory(configuration); + var parameterSerializer = registrationSnapshot.SerializerFactory(configuration); + var destination = registrationSnapshot.DestinationFactory(configuration); var constructionRuntimeReference = new LateBoundReference>(); @@ -36,9 +34,9 @@ public IAllureRuntimeRegistration Build() constructionRuntimeReference ); - var context = commonSnapshot.ContextFactory(serviceCreationContext); - var lifecycleApi = commonSnapshot.LifecycleApiFactory(serviceCreationContext); - var modelApi = commonSnapshot.ModelApiFactory(serviceCreationContext); + var context = registrationSnapshot.ContextFactory(serviceCreationContext); + var lifecycleApi = registrationSnapshot.LifecycleApiFactory(serviceCreationContext); + var modelApi = registrationSnapshot.ModelApiFactory(serviceCreationContext); RuntimeCreationArguments runtimeCreationArguments = new( Configuration: configuration, @@ -57,18 +55,17 @@ public IAllureRuntimeRegistration Build() { constructionRuntimeReference.Bind(runtime); - if (commonSnapshot.EndpointRegistration is var (routeId, routeRegistration)) + if (registrationSnapshot.EndpointRegistration is var (routeId, routeRegistration)) { - EndpointRouteCreationArguments endpointBuildArgs = new( + var routeBuilder = new AllureInProcessRouteBuilder( runtimeName, routeId, runtime, - commonSnapshot.UseRuleBasedSerializer, - commonSnapshot.RuleBasedSerializerRegistrations, + registrationSnapshot.UseRuleBasedSerializer, + registrationSnapshot.RuleBasedSerializerRegistrations, routeRegistration ); - - var route = routeFactory(endpointBuildArgs); + var route = routeBuilder.Build(); endpointRegistration = AllureRuntimeRouter.Install(route); } diff --git a/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs b/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs deleted file mode 100644 index ba0c6247..00000000 --- a/src/Allure.Net.Sdk/Registration/AllureRouteBuilderArgs.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using Allure.Sdk.Configuration; -using Allure.Sdk.Runtime; - -namespace Allure.Sdk.Registration; - -/// -/// Carries the components resolved by a runtime builder into an in-process -/// endpoint route. -/// -/// -/// Instances are created by the SDK and supplied to -/// CreateRouteBuilder implementations. -/// -/// The runtime configuration type. -/// The runtime type. -public class EndpointRouteCreationArguments - where TConfiguration : AllureConfiguration - where TRuntime : IAllureRuntime -{ - internal string RuntimeName { get; } - internal string RouteId { get; } - internal TRuntime Runtime { get; } - internal bool UseRuleBasedSerializer { get; } - internal IEnumerable> RuleBasedSerializerRegistrations { get; } - internal Action> Registration { get; } - - internal EndpointRouteCreationArguments( - string runtimeName, - string routeId, - TRuntime runtime, - bool useRuleBasedSerializer, - IEnumerable> ruleBasedSerializerRegistrations, - Action> registration - ) - { - this.RuntimeName = runtimeName; - this.RouteId = routeId; - this.Runtime = runtime; - this.UseRuleBasedSerializer = useRuleBasedSerializer; - this.RuleBasedSerializerRegistrations = ruleBasedSerializerRegistrations; - this.Registration = registration; - } -} diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs index 3ac66d21..4ecaa2e4 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs @@ -2,7 +2,6 @@ using System.Threading; using Allure.Sdk.Configuration; using Allure.Sdk.Internal.Registration; -using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Runtime; namespace Allure.Sdk.Registration; diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index 7e824279..c31fcd42 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -228,8 +228,7 @@ Action registration runtimeName, finalConfiguration.Configuration, commonSnapshot, - this.CreateRuntime, - (args) => new AllureInProcessRouteBuilder(args).Build() + this.CreateRuntime ); } catch diff --git a/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs index 110a062a..2f65f3ec 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/InProcessEndpointRegistrationTests.cs @@ -133,6 +133,29 @@ await Assert.That(syncOperations.AddGlobalAttachment( isInGlobalScope.Value = false; } + [Test] + public async Task ShouldExposeIntegrationSpecificRuntimeToEndpointRegistration() + { + var service = new object(); + var observedService = default(object); + var builder = new RuntimeWithServiceBuilder("test", service); + + using var _ = builder.Prepare(ctx => + ctx.RegisterInProcessEndpoint( + NewRouteId(), + (runtime, endpoint) => + { + endpoint.UseCurrentScopePredicate(_ => false); + endpoint.UseGlobalScopePredicate(_ => false); + endpoint.SetAvailabilityPredicate(_ => false); + observedService = runtime.Service; + } + ) + ).Build(); + + await Assert.That(observedService).IsSameReferenceAs(service); + } + static AllureRuntimeBuilder CreateBuilder() => new("endpoint-registration-tests"); From 0c43612cbfe898612c59256a85b80772a43bb1a8 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 15:49:20 +0700 Subject: [PATCH 05/14] feat(sdk): reduce the number of builder type args to 3 --- .../Registration/AllureRuntimeBuilder.cs | 44 +++------------ .../AllureRuntimeRegistrationSession.cs | 33 +++++++----- .../AllureRuntimeRegistrationSessionBase.cs | 18 +++++++ .../IAllureRuntimeIntegrationContext.cs | 50 ++--------------- .../IAllureRuntimeIntegrationContextBase.cs | 54 +++++++++++++++++++ 5 files changed, 102 insertions(+), 97 deletions(-) create mode 100644 src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSessionBase.cs create mode 100644 src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs index 4ecaa2e4..e689f143 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs @@ -11,22 +11,20 @@ namespace Allure.Sdk.Registration; /// /// The runtime configuration type. /// The type of runtime constructed by the builder. -/// The registration context type. -/// The integration context type. +/// The integration context type. /// The runtime name used to identify its in-process route. /// /// A factory that creates the single-use registration session configured by /// . /// -public class AllureRuntimeBuilder( +public class AllureRuntimeBuilder( string runtimeName, - Func> sessionFactory + Func> sessionFactory ) where TConfiguration : AllureConfiguration, new() where TRuntime : IAllureRuntime - where TRegistrationContext : IAllureRuntimeRegistrationContext - where TIntegrationContext : IAllureRuntimeIntegrationContext + where TContext : IAllureRuntimeIntegrationContextBase { int state = 0; @@ -53,7 +51,7 @@ Func public IAllureRuntimeRegistrationPlan Prepare( - Action registration + Action registration ) { if (Interlocked.CompareExchange(ref this.state, STAGE_CONSUMED, STAGE_CREATED) != STAGE_CREATED) @@ -76,45 +74,19 @@ Action registration const int STAGE_CONSUMED = 1; } -public class AllureRuntimeBuilder( - string runtimeName, - Func< - AllureRuntimeRegistrationSession< - TConfiguration, - TRuntime, - TRegistrationContext, - IAllureRuntimeIntegrationContext - > - > sessionFactory -) : - AllureRuntimeBuilder>( - runtimeName, - sessionFactory - ) - - where TConfiguration : AllureConfiguration, new() - where TRuntime : IAllureRuntime - where TRegistrationContext : IAllureRuntimeRegistrationContext; - public class AllureRuntimeBuilder( string runtimeName, Func< AllureRuntimeRegistrationSession< TConfiguration, - TRuntime, - IAllureRuntimeRegistrationContext, - IAllureRuntimeIntegrationContext + TRuntime > > sessionFactory ) : AllureRuntimeBuilder< TConfiguration, TRuntime, - IAllureRuntimeRegistrationContext, - IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntime - > + IAllureRuntimeIntegrationContext >( runtimeName, sessionFactory @@ -127,7 +99,6 @@ public class AllureRuntimeBuilder(string runtimeName) : AllureRuntimeBuilder< TConfiguration, IAllureRuntime, - IAllureRuntimeRegistrationContext, IAllureRuntimeIntegrationContext >( runtimeName, @@ -140,7 +111,6 @@ public class AllureRuntimeBuilder(string runtimeName) : AllureRuntimeBuilder< AllureConfiguration, IAllureRuntime, - IAllureRuntimeRegistrationContext, IAllureRuntimeIntegrationContext >( runtimeName, diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index c31fcd42..2f6e4798 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -17,9 +17,10 @@ namespace Allure.Sdk.Registration; /// /// The runtime configuration type. /// The runtime type. -/// The runtime registration context type. /// The runtime integration context type. -public abstract class AllureRuntimeRegistrationSession : +/// The runtime registration context type. +public abstract class AllureRuntimeRegistrationSession : + AllureRuntimeRegistrationSessionBase, IAllureRuntimeIntegrationContext where TConfiguration : AllureConfiguration, new() @@ -202,7 +203,7 @@ protected void Modify(Action action) protected abstract TRuntime CreateRuntime(RuntimeCreationArguments args); - internal IPreparedRuntimeRegistration Prepare( + internal override IPreparedRuntimeRegistration Prepare( string runtimeName, Action registration ) @@ -364,28 +365,32 @@ enum RegistrationState public abstract class AllureRuntimeRegistrationSession< TConfiguration, TRuntime, - TRegistrationContext + TIntegrationContext > : AllureRuntimeRegistrationSession< TConfiguration, TRuntime, - TRegistrationContext, - IAllureRuntimeIntegrationContext + TIntegrationContext, + IAllureRuntimeRegistrationContext > where TConfiguration : AllureConfiguration, new() where TRuntime : IAllureRuntime - where TRegistrationContext : IAllureRuntimeRegistrationContext + where TIntegrationContext : IAllureRuntimeIntegrationContext< + TConfiguration, + TRuntime, + IAllureRuntimeRegistrationContext + > { - protected override IAllureRuntimeIntegrationContext IntegrationContext => this; + protected override IAllureRuntimeRegistrationContext RegistrationContext => this; } public abstract class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< TConfiguration, TRuntime, - IAllureRuntimeRegistrationContext, - IAllureRuntimeIntegrationContext + IAllureRuntimeIntegrationContext, + IAllureRuntimeRegistrationContext >, IAllureRuntimeIntegrationContext @@ -401,8 +406,8 @@ public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< TConfiguration, IAllureRuntime, - IAllureRuntimeRegistrationContext, - IAllureRuntimeIntegrationContext + IAllureRuntimeIntegrationContext, + IAllureRuntimeRegistrationContext >, IAllureRuntimeIntegrationContext @@ -429,8 +434,8 @@ public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< AllureConfiguration, IAllureRuntime, - IAllureRuntimeRegistrationContext, - IAllureRuntimeIntegrationContext + IAllureRuntimeIntegrationContext, + IAllureRuntimeRegistrationContext >, IAllureRuntimeIntegrationContext { diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSessionBase.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSessionBase.cs new file mode 100644 index 00000000..96eeb32d --- /dev/null +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSessionBase.cs @@ -0,0 +1,18 @@ +using System; +using Allure.Sdk.Configuration; +using Allure.Sdk.Internal.Registration; +using Allure.Sdk.Runtime; + +namespace Allure.Sdk.Registration; + +public abstract class AllureRuntimeRegistrationSessionBase + + where TConfiguration : AllureConfiguration, new() + where TRuntime : IAllureRuntime + where TIntegrationContext : IAllureRuntimeIntegrationContextBase +{ + internal abstract IPreparedRuntimeRegistration Prepare( + string runtimeName, + Action registration + ); +} diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs index f186793b..42311079 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs @@ -13,9 +13,9 @@ namespace Allure.Sdk.Registration; /// The type of runtime constructed by the integration. /// The type of runtime integration context. public interface IAllureRuntimeIntegrationContext : - IAllureRuntimeRegistrationContext + IAllureRuntimeIntegrationContextBase - where TConfiguration : AllureConfiguration, new() + where TConfiguration : AllureConfiguration where TRuntime : IAllureRuntime where TContext : IAllureRuntimeRegistrationContext { @@ -28,48 +28,6 @@ public interface IAllureRuntimeIntegrationContext?>> hooksFactory ); - - /// - /// Configures the execution-context service. - /// - /// - /// A factory that creates the service from the resolved configuration. - /// - void UseContext( - Func contextFactory - ); - - /// - /// Configures the lifecycle API service. - /// - /// - /// A factory that creates the service from the resolved configuration. - /// - void UseLifecycleApi( - Func lifecycleApiFactory - ); - - /// - /// Configures the model API service. - /// - /// - /// A factory that creates the service from the resolved configuration. - /// - void UseModelApi( - Func modelApiFactory - ); - - /// - /// Registers an in-process endpoint for the constructed runtime. - /// - /// The route identifier of the endpoint. - /// - /// An action that configures the endpoint after the runtime is constructed. - /// - public void RegisterInProcessEndpoint( - string endpointId, - Action> endpointRegistration - ); } public interface IAllureRuntimeIntegrationContext : @@ -79,7 +37,7 @@ public interface IAllureRuntimeIntegrationContext : IAllureRuntimeRegistrationContext > - where TConfiguration : AllureConfiguration, new() + where TConfiguration : AllureConfiguration where TRuntime : IAllureRuntime; /// @@ -92,7 +50,7 @@ public interface IAllureRuntimeIntegrationContext : IAllureRuntime > - where TConfiguration : AllureConfiguration, new(); + where TConfiguration : AllureConfiguration; /// /// Configures a standard Allure runtime and its in-process endpoint integration. diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs new file mode 100644 index 00000000..8dd64841 --- /dev/null +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs @@ -0,0 +1,54 @@ +using System; +using Allure.Sdk.Configuration; +using Allure.Sdk.Runtime; + +namespace Allure.Sdk.Registration; + +public interface IAllureRuntimeIntegrationContextBase : + IAllureRuntimeRegistrationContext + + where TConfiguration : AllureConfiguration + where TRuntime : IAllureRuntime +{ + /// + /// Configures the execution-context service. + /// + /// + /// A factory that creates the service from the resolved configuration. + /// + void UseContext( + Func contextFactory + ); + + /// + /// Configures the lifecycle API service. + /// + /// + /// A factory that creates the service from the resolved configuration. + /// + void UseLifecycleApi( + Func lifecycleApiFactory + ); + + /// + /// Configures the model API service. + /// + /// + /// A factory that creates the service from the resolved configuration. + /// + void UseModelApi( + Func modelApiFactory + ); + + /// + /// Registers an in-process endpoint for the constructed runtime. + /// + /// The route identifier of the endpoint. + /// + /// An action that configures the endpoint after the runtime is constructed. + /// + public void RegisterInProcessEndpoint( + string endpointId, + Action> endpointRegistration + ); +} From 789f1db2b2a09a86e85d6486de8ab9e4022a088a Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 15:59:42 +0700 Subject: [PATCH 06/14] feat(sdk): simplify in-process endpoint integration context --- ...lureInProcessEndpointIntegrationContext.cs | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs index 65a3832d..51e73738 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Allure.Abstractions; -using Allure.Sdk.Configuration; using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Runtime; @@ -11,18 +10,23 @@ namespace Allure.Sdk.Registration; /// Configures an in-process Allure endpoint and its integration hooks. /// /// The runtime type. -/// The endpoint registration context type. -public interface IAllureInProcessEndpointIntegrationContext : +public interface IAllureInProcessEndpointIntegrationContext : IAllureInProcessEndpointRegistrationContext where TRuntime : IAllureRuntime - where TContext : IAllureInProcessEndpointRegistrationContext { /// /// Configures the hooks invoked during endpoint registration. /// void UseRegistrationHooks( - Func?>> hooksFactory + Func< + TRuntime, + IEnumerable< + IAllureRegistrationHook< + IAllureInProcessEndpointRegistrationContext + >? + > + > hooksFactory ); /// @@ -40,14 +44,3 @@ void UseRegistrationHooks( /// void UseOperations(Func operationsFactory); } - -public interface IAllureInProcessEndpointIntegrationContext : - IAllureInProcessEndpointIntegrationContext< - TRuntime, - IAllureInProcessEndpointRegistrationContext - > - - where TRuntime : IAllureRuntime; - -public interface IAllureInProcessEndpointIntegrationContext : - IAllureInProcessEndpointIntegrationContext>; From c34c4a0385b1971b3c3da58727123e32aa3a4041 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 16:20:18 +0700 Subject: [PATCH 07/14] feat(sdk): create a boundary between integration and registration contexts --- .../Registration/RegistrationContextFacade.cs | 49 +++++++++++++++++++ .../AllureRuntimeRegistrationSession.cs | 14 ++++-- 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs diff --git a/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs b/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs new file mode 100644 index 00000000..22729f23 --- /dev/null +++ b/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using Allure.Abstractions; +using Allure.Sdk.Configuration; +using Allure.Sdk.Registration; +using Allure.Sdk.Results; +using Allure.Sdk.Runtime; + +namespace Allure.Sdk.Internal.Registration; + +class RegistrationContextFacade( + IAllureRuntimeIntegrationContext< + TConfiguration, + TRuntime, + IAllureRuntimeRegistrationContext + > integrationContext +) : + IAllureRuntimeRegistrationContext + + where TConfiguration : AllureConfiguration, new() + where TRuntime : IAllureRuntime +{ + public void ConfigureSerialization( + Action registration + ) => + integrationContext.ConfigureSerialization(registration); + + public void ConfigureSerialization(Action registration) => + integrationContext.ConfigureSerialization(registration); + + public void TransformConfiguration( + Func, TrackedConfiguration> transformation + ) => + integrationContext.TransformConfiguration(transformation); + + public void UseConfigurationSources( + Func>> sourcesFactory + ) => + integrationContext.UseConfigurationSources(sourcesFactory); + + public void UseDestination(Func destinationFactory) => + integrationContext.UseDestination(destinationFactory); + + public void UseParameterSerializer(Func serializerFactory) => + integrationContext.UseParameterSerializer(serializerFactory); + + public void UseParameterSerializer(Func serializerFactory) => + integrationContext.UseParameterSerializer(serializerFactory); +} diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index 2f6e4798..fb07ba67 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -382,7 +382,10 @@ public abstract class AllureRuntimeRegistrationSession< IAllureRuntimeRegistrationContext > { - protected override IAllureRuntimeRegistrationContext RegistrationContext => this; + protected override IAllureRuntimeRegistrationContext RegistrationContext => + new RegistrationContextFacade(this); + + } public abstract class AllureRuntimeRegistrationSession : @@ -397,7 +400,8 @@ public abstract class AllureRuntimeRegistrationSession where TConfiguration : AllureConfiguration, new() where TRuntime : IAllureRuntime { - protected override IAllureRuntimeRegistrationContext RegistrationContext => this; + protected override IAllureRuntimeRegistrationContext RegistrationContext => + new RegistrationContextFacade(this); protected override IAllureRuntimeIntegrationContext IntegrationContext => this; } @@ -415,7 +419,8 @@ public class AllureRuntimeRegistrationSession : { protected override IAllureRuntimeIntegrationContext IntegrationContext => this; - protected override IAllureRuntimeRegistrationContext RegistrationContext => this; + protected override IAllureRuntimeRegistrationContext RegistrationContext => + new RegistrationContextFacade>(this); protected override IAllureRuntime CreateRuntime( RuntimeCreationArguments args @@ -441,7 +446,8 @@ public class AllureRuntimeRegistrationSession : { protected override IAllureRuntimeIntegrationContext IntegrationContext => this; - protected override IAllureRuntimeRegistrationContext RegistrationContext => this; + protected override IAllureRuntimeRegistrationContext RegistrationContext => + new RegistrationContextFacade>(this); protected override IAllureRuntime CreateRuntime( RuntimeCreationArguments args From df3c1a984bf5c35f99deb1530c9ce91a88ea1f78 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 16:26:11 +0700 Subject: [PATCH 08/14] feat(sdk): simplify hook and session --- .../Registration/AllureRegistrationDefaults.cs | 8 +++----- .../Registration/AllureRuntimeBuilder.cs | 10 +++++----- .../Registration/AllureRuntimeRegistrationSession.cs | 3 +-- .../IAllureInProcessEndpointRegistrationContext.cs | 2 +- ...raitonPlan.cs => IAllureRuntimeRegistrationPlan.cs} | 0 5 files changed, 10 insertions(+), 13 deletions(-) rename src/Allure.Net.Sdk/Registration/{IAllureRuntimeRegistraitonPlan.cs => IAllureRuntimeRegistrationPlan.cs} (100%) diff --git a/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs b/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs index 543f0e0a..69415048 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs @@ -77,14 +77,12 @@ IEnumerable> registr /// /// The runtime configuration type. /// The runtime registration context type. - /// The runtime registration hook type. - public static Func> RuntimeHookProviders() + public static Func?>> RuntimeHookProviders() where TConfiguration : AllureConfiguration, new() where TContext : IAllureRuntimeRegistrationContext - where THook : IAllureRegistrationHook => static (configuration) => [ - ReflectionHooks.FromEnvironmentVariable("ALLURE_RUNTIME_REGISTRATION_HOOK"), - ReflectionHooks.FromConfiguration(configuration), + ReflectionHooks.FromEnvironmentVariable>("ALLURE_RUNTIME_REGISTRATION_HOOK"), + ReflectionHooks.FromConfiguration>(configuration), ]; } diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs index e689f143..abc1c9a7 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs @@ -11,20 +11,20 @@ namespace Allure.Sdk.Registration; /// /// The runtime configuration type. /// The type of runtime constructed by the builder. -/// The integration context type. +/// The integration context type. /// The runtime name used to identify its in-process route. /// /// A factory that creates the single-use registration session configured by /// . /// -public class AllureRuntimeBuilder( +public class AllureRuntimeBuilder( string runtimeName, - Func> sessionFactory + Func> sessionFactory ) where TConfiguration : AllureConfiguration, new() where TRuntime : IAllureRuntime - where TContext : IAllureRuntimeIntegrationContextBase + where TIntegrationContext : IAllureRuntimeIntegrationContextBase { int state = 0; @@ -51,7 +51,7 @@ Func> s /// This builder has already been used. /// public IAllureRuntimeRegistrationPlan Prepare( - Action registration + Action registration ) { if (Interlocked.CompareExchange(ref this.state, STAGE_CONSUMED, STAGE_CREATED) != STAGE_CREATED) diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index fb07ba67..d2b779cd 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -45,8 +45,7 @@ readonly List< Func?>> currentHooksFactory = AllureRegistrationDefaults.RuntimeHookProviders< TConfiguration, - TRegistrationContext, - IAllureRegistrationHook + TRegistrationContext >(); Func< diff --git a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs index 9a6ac624..fd6e15de 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs @@ -23,7 +23,7 @@ Func serializerFactory ); /// - /// Configures endpoint availability using the constructed runtime. + /// Configures parameter serialization rules used by the endpoint. /// void ConfigureSerialization(Action registration); diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistraitonPlan.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationPlan.cs similarity index 100% rename from src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistraitonPlan.cs rename to src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationPlan.cs From f1e8b43026fe673c7027fd83c07c5ca89211502f Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 16:46:24 +0700 Subject: [PATCH 09/14] feat(sdk): use parameterless type for default runtime hooks --- .../Registration/RegistrationContextFacade.cs | 6 +++++ .../AllureRuntimeRegistrationSession.cs | 6 ++--- .../Hooks/IAllureRegistrationHook.cs | 3 +++ .../Registration/Hooks/ReflectionHooks.cs | 2 +- .../IAllureRuntimeIntegrationContext.cs | 6 ++++- .../IAllureRuntimeRegistrationContext.cs | 3 +++ .../Registration/RegistrationHookTests.cs | 24 +++++++++---------- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs b/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs index 22729f23..1a5811e6 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs @@ -47,3 +47,9 @@ public void UseParameterSerializer(Func serializerFactory) => integrationContext.UseParameterSerializer(serializerFactory); } + +sealed class RegistrationContextFacade( + IAllureRuntimeIntegrationContext integrationContext +) : + RegistrationContextFacade>(integrationContext), + IAllureRuntimeRegistrationContext; diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index d2b779cd..4208d6d7 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -439,14 +439,14 @@ public class AllureRuntimeRegistrationSession : AllureConfiguration, IAllureRuntime, IAllureRuntimeIntegrationContext, - IAllureRuntimeRegistrationContext + IAllureRuntimeRegistrationContext >, IAllureRuntimeIntegrationContext { protected override IAllureRuntimeIntegrationContext IntegrationContext => this; - protected override IAllureRuntimeRegistrationContext RegistrationContext => - new RegistrationContextFacade>(this); + protected override IAllureRuntimeRegistrationContext RegistrationContext => + new RegistrationContextFacade(this); protected override IAllureRuntime CreateRuntime( RuntimeCreationArguments args diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs index 1abf2b2b..6ac38e96 100644 --- a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs +++ b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs @@ -12,3 +12,6 @@ public interface IAllureRegistrationHook /// void SetUp(TContext context); } + +public interface IAllureRuntimeRegistrationHook : + IAllureRegistrationHook; diff --git a/src/Allure.Net.Sdk/Registration/Hooks/ReflectionHooks.cs b/src/Allure.Net.Sdk/Registration/Hooks/ReflectionHooks.cs index bee35c20..aed185c8 100644 --- a/src/Allure.Net.Sdk/Registration/Hooks/ReflectionHooks.cs +++ b/src/Allure.Net.Sdk/Registration/Hooks/ReflectionHooks.cs @@ -39,7 +39,7 @@ internal static THook Resolve(string assemblyQualifiedTypeName) ignoreCase: false ); - if (!type.GetInterfaces().Any(static (iFace) => iFace == typeof(THook))) + if (!type.GetInterfaces().Any(static (iFace) => typeof(THook).IsAssignableFrom(iFace))) { throw new InvalidOperationException( $"Type '{type}' must implement '{typeof(THook)}' to be an " diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs index 42311079..fc406db0 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs @@ -56,4 +56,8 @@ public interface IAllureRuntimeIntegrationContext : /// Configures a standard Allure runtime and its in-process endpoint integration. /// public interface IAllureRuntimeIntegrationContext : - IAllureRuntimeIntegrationContext; + IAllureRuntimeIntegrationContext< + AllureConfiguration, + IAllureRuntime, + IAllureRuntimeRegistrationContext + >; diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs index 3ba27112..4b1b7dfa 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs @@ -65,3 +65,6 @@ Func serializerFactory /// void UseDestination(Func destinationFactory); } + +public interface IAllureRuntimeRegistrationContext : + IAllureRuntimeRegistrationContext; diff --git a/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs b/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs index 05a9eb71..0f51c38f 100644 --- a/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Registration/RegistrationHookTests.cs @@ -344,34 +344,34 @@ public async Task ShouldResolveReflectionHooksAndIgnoreMissingValues() { var typeName = typeof(ReflectionRuntimeHook).AssemblyQualifiedName!; var fromConfiguration = ReflectionHooks - .FromConfiguration>>( + .FromConfiguration( new() { RuntimeRegistrationHook = typeName } ); var variableName = $"ALLURE_SDK_TEST_HOOK_{Guid.NewGuid():N}"; Environment.SetEnvironmentVariable(variableName, null); var fromEnvironment = ReflectionHooks - .FromEnvironmentVariable>>(variableName); + .FromEnvironmentVariable(variableName); await Assert.That(fromConfiguration).IsTypeOf(); await Assert.That(fromEnvironment).IsNull(); await Assert.That( - ReflectionHooks.FromConfiguration>>(new()) + ReflectionHooks.FromConfiguration(new()) ).IsNull(); } [Test] public async Task ShouldRejectInvalidReflectionHooks() { - await Assert.That(() => ReflectionHooks.FromConfiguration>>( + await Assert.That(() => ReflectionHooks.FromConfiguration( new() { RuntimeRegistrationHook = typeof(NotARegistrationHook).AssemblyQualifiedName } )).Throws().WithMessageContaining("must implement"); - await Assert.That(() => ReflectionHooks.FromConfiguration>>( + await Assert.That(() => ReflectionHooks.FromConfiguration( new() { RuntimeRegistrationHook = typeof(PrivateConstructorRuntimeHook).AssemblyQualifiedName } )).Throws().WithMessageContaining("public parameterless constructor"); - await Assert.That(() => ReflectionHooks.FromConfiguration>>( + await Assert.That(() => ReflectionHooks.FromConfiguration( new() { RuntimeRegistrationHook = "No.Such.Hook, No.Such.Assembly" } )).Throws(); } @@ -386,26 +386,26 @@ sealed record class TestConfiguration : AllureConfiguration public string? Value { get; init; } } - public class ReflectionRuntimeHook : IAllureRegistrationHook> + public class ReflectionRuntimeHook : IAllureRuntimeRegistrationHook { public static System.Collections.Concurrent.ConcurrentQueue Calls { get; } = []; - public void SetUp(IAllureRuntimeRegistrationContext context) + public void SetUp(IAllureRuntimeRegistrationContext context) => Calls.Enqueue("configuration"); } - public sealed class EnvironmentReflectionRuntimeHook : IAllureRegistrationHook> + public sealed class EnvironmentReflectionRuntimeHook : IAllureRuntimeRegistrationHook { - public void SetUp(IAllureRuntimeRegistrationContext context) => + public void SetUp(IAllureRuntimeRegistrationContext context) => ReflectionRuntimeHook.Calls.Enqueue("environment"); } public sealed class NotARegistrationHook; - public sealed class PrivateConstructorRuntimeHook : IAllureRegistrationHook> + public sealed class PrivateConstructorRuntimeHook : IAllureRuntimeRegistrationHook { PrivateConstructorRuntimeHook() { } - public void SetUp(IAllureRuntimeRegistrationContext context) { } + public void SetUp(IAllureRuntimeRegistrationContext context) { } } } From 223b677a0ce6b434896c4860778075bd9cf9739e Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 16:53:56 +0700 Subject: [PATCH 10/14] feat(sdk): IAllureRuntime -> IAllureRuntimeBase --- .../Registration/AllureRuntimeRegistration.cs | 2 +- .../Runtime/AsyncFixtureOperationContext.cs | 2 +- .../Runtime/AsyncStepOperationContext.cs | 2 +- .../Runtime/FixtureOperationContext.cs | 2 +- .../Internal/Runtime/OperationContext.cs | 4 +- .../Internal/Runtime/RuntimeLifecycleApi.cs | 2 +- .../Internal/Runtime/RuntimeModelApi.cs | 2 +- .../Internal/Runtime/StepOperationContext.cs | 2 +- .../Runtime/SyncFixtureOperationContext.cs | 2 +- .../Runtime/SyncStepOperationContext.cs | 2 +- .../AllureRegistrationDefaults.cs | 2 +- ...lureInProcessEndpointIntegrationContext.cs | 2 +- ...ureInProcessEndpointRegistrationContext.cs | 3 +- .../IAllureRuntimeRegistration.cs | 2 +- .../Runtime/AllureExecutionContext.cs | 12 +++--- src/Allure.Net.Sdk/Runtime/AllureRuntime.cs | 2 +- .../Runtime/AsyncLocalExecutionContext.cs | 2 +- .../Runtime/IAllureExecutionContext.cs | 14 +++---- src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs | 40 +----------------- .../Runtime/IAllureRuntimeBase.cs | 41 +++++++++++++++++++ .../RuntimeTestEnvironmentTests.cs | 2 +- .../AsyncLocalExecutionContextTests.cs | 2 +- 22 files changed, 74 insertions(+), 72 deletions(-) create mode 100644 src/Allure.Net.Sdk/Runtime/IAllureRuntimeBase.cs diff --git a/src/Allure.Net.Sdk/Internal/Registration/AllureRuntimeRegistration.cs b/src/Allure.Net.Sdk/Internal/Registration/AllureRuntimeRegistration.cs index 28fe8151..978cf959 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/AllureRuntimeRegistration.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/AllureRuntimeRegistration.cs @@ -11,7 +11,7 @@ sealed class AllureRuntimeRegistration( IDisposable? routeRegistration ) : IAllureRuntimeRegistration - where TRuntime : IAllureRuntime + where TRuntime : IAllureRuntimeBase { int disposed = 0; diff --git a/src/Allure.Net.Sdk/Internal/Runtime/AsyncFixtureOperationContext.cs b/src/Allure.Net.Sdk/Internal/Runtime/AsyncFixtureOperationContext.cs index 4afd5861..76079b73 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/AsyncFixtureOperationContext.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/AsyncFixtureOperationContext.cs @@ -6,7 +6,7 @@ namespace Allure.Sdk.Internal.Runtime; -sealed class AsyncFixtureOperationContext(IAllureRuntime runtime) : +sealed class AsyncFixtureOperationContext(IAllureRuntimeBase runtime) : FixtureOperationContext(runtime), IAllureInProcessAsyncFixtureContext { diff --git a/src/Allure.Net.Sdk/Internal/Runtime/AsyncStepOperationContext.cs b/src/Allure.Net.Sdk/Internal/Runtime/AsyncStepOperationContext.cs index c2fd982f..e61aa1f3 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/AsyncStepOperationContext.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/AsyncStepOperationContext.cs @@ -6,7 +6,7 @@ namespace Allure.Sdk.Internal.Runtime; -sealed class AsyncStepOperationContext(IAllureRuntime runtime, int level) : +sealed class AsyncStepOperationContext(IAllureRuntimeBase runtime, int level) : StepOperationContext(runtime, level), IAllureInProcessAsyncStepContext { diff --git a/src/Allure.Net.Sdk/Internal/Runtime/FixtureOperationContext.cs b/src/Allure.Net.Sdk/Internal/Runtime/FixtureOperationContext.cs index e70d3490..68d805ee 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/FixtureOperationContext.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/FixtureOperationContext.cs @@ -6,7 +6,7 @@ namespace Allure.Sdk.Internal.Runtime; -abstract class FixtureOperationContext(IAllureRuntime runtime) : +abstract class FixtureOperationContext(IAllureRuntimeBase runtime) : OperationContext(runtime), IAllureOperationContext { diff --git a/src/Allure.Net.Sdk/Internal/Runtime/OperationContext.cs b/src/Allure.Net.Sdk/Internal/Runtime/OperationContext.cs index 3978daf8..35b5aea4 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/OperationContext.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/OperationContext.cs @@ -4,11 +4,11 @@ namespace Allure.Sdk.Internal.Runtime; -abstract class OperationContext(IAllureRuntime runtime) : IAllureOperationContext, IDisposable +abstract class OperationContext(IAllureRuntimeBase runtime) : IAllureOperationContext, IDisposable { bool disposed = false; - protected IAllureRuntime Runtime => runtime; + protected IAllureRuntimeBase Runtime => runtime; protected AllureExecutionState CurrentState => runtime.ContextApi.CurrentState; diff --git a/src/Allure.Net.Sdk/Internal/Runtime/RuntimeLifecycleApi.cs b/src/Allure.Net.Sdk/Internal/Runtime/RuntimeLifecycleApi.cs index ee9d45bc..02c4b654 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/RuntimeLifecycleApi.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/RuntimeLifecycleApi.cs @@ -6,7 +6,7 @@ namespace Allure.Sdk.Internal.Runtime; class RuntimeLifecycleApi( - IReadOnlyLateBoundReference runtimeReference + IReadOnlyLateBoundReference runtimeReference ) : IAllureLifecycleApi { diff --git a/src/Allure.Net.Sdk/Internal/Runtime/RuntimeModelApi.cs b/src/Allure.Net.Sdk/Internal/Runtime/RuntimeModelApi.cs index fc55be7b..01da3c14 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/RuntimeModelApi.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/RuntimeModelApi.cs @@ -9,7 +9,7 @@ namespace Allure.Sdk.Internal.Runtime; class RuntimeModelApi( - IReadOnlyLateBoundReference runtimeReference + IReadOnlyLateBoundReference runtimeReference ) : IAllureModelApi { diff --git a/src/Allure.Net.Sdk/Internal/Runtime/StepOperationContext.cs b/src/Allure.Net.Sdk/Internal/Runtime/StepOperationContext.cs index dfd4d88b..2526eece 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/StepOperationContext.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/StepOperationContext.cs @@ -6,7 +6,7 @@ namespace Allure.Sdk.Internal.Runtime; -abstract class StepOperationContext(IAllureRuntime runtime, int level) : +abstract class StepOperationContext(IAllureRuntimeBase runtime, int level) : OperationContext(runtime), IAllureOperationContext { diff --git a/src/Allure.Net.Sdk/Internal/Runtime/SyncFixtureOperationContext.cs b/src/Allure.Net.Sdk/Internal/Runtime/SyncFixtureOperationContext.cs index 57312f5e..cdbf928d 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/SyncFixtureOperationContext.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/SyncFixtureOperationContext.cs @@ -4,7 +4,7 @@ namespace Allure.Sdk.Internal.Runtime; -sealed class SyncFixtureOperationContext(IAllureRuntime runtime) : +sealed class SyncFixtureOperationContext(IAllureRuntimeBase runtime) : FixtureOperationContext(runtime), IAllureInProcessSyncFixtureContext { diff --git a/src/Allure.Net.Sdk/Internal/Runtime/SyncStepOperationContext.cs b/src/Allure.Net.Sdk/Internal/Runtime/SyncStepOperationContext.cs index 215dfc4b..e1c128d3 100644 --- a/src/Allure.Net.Sdk/Internal/Runtime/SyncStepOperationContext.cs +++ b/src/Allure.Net.Sdk/Internal/Runtime/SyncStepOperationContext.cs @@ -4,7 +4,7 @@ namespace Allure.Sdk.Internal.Runtime; -sealed class SyncStepOperationContext(IAllureRuntime runtime, int level) : +sealed class SyncStepOperationContext(IAllureRuntimeBase runtime, int level) : StepOperationContext(runtime, level), IAllureInProcessSyncStepContext { diff --git a/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs b/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs index 69415048..4db8c9a9 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs @@ -42,7 +42,7 @@ public static Func Destination EndpointParameterSerializer( IEnumerable> registrations ) - where TRuntime : IAllureRuntime + where TRuntime : IAllureRuntimeBase => (configuration) => { diff --git a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs index 51e73738..1381fd26 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs @@ -13,7 +13,7 @@ namespace Allure.Sdk.Registration; public interface IAllureInProcessEndpointIntegrationContext : IAllureInProcessEndpointRegistrationContext - where TRuntime : IAllureRuntime + where TRuntime : IAllureRuntimeBase { /// /// Configures the hooks invoked during endpoint registration. diff --git a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs index fd6e15de..843b61fa 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Allure.Abstractions; -using Allure.Sdk.Configuration; using Allure.Sdk.Runtime; namespace Allure.Sdk.Registration; @@ -13,7 +12,7 @@ namespace Allure.Sdk.Registration; public interface IAllureInProcessEndpointRegistrationContext : IAllureEndpointRegistrationContext - where TRuntime : IAllureRuntime + where TRuntime : IAllureRuntimeBase { /// /// Configures the parameter serializer used by the endpoint. diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistration.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistration.cs index 1f6d4790..1c83ac91 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistration.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistration.cs @@ -18,7 +18,7 @@ public interface IAllureRuntimeRegistration : IDisposable, IAsyncDisposable - where TRuntime : IAllureRuntime + where TRuntime : IAllureRuntimeBase { /// /// Gets the constructed runtime. diff --git a/src/Allure.Net.Sdk/Runtime/AllureExecutionContext.cs b/src/Allure.Net.Sdk/Runtime/AllureExecutionContext.cs index 5db2bfc6..684a1c1d 100644 --- a/src/Allure.Net.Sdk/Runtime/AllureExecutionContext.cs +++ b/src/Allure.Net.Sdk/Runtime/AllureExecutionContext.cs @@ -14,18 +14,18 @@ namespace Allure.Sdk.Runtime; /// A reference to the Allure runtime associated with this context. /// public abstract class AllureExecutionContext( - IReadOnlyLateBoundReference runtimeReference + IReadOnlyLateBoundReference runtimeReference ) : IAllureExecutionContext { /// - public IAllureRuntime Runtime => runtimeReference.Value; + public IAllureRuntimeBase Runtime => runtimeReference.Value; /// public abstract AllureExecutionState CurrentState { get; protected set; } /// - public T GetWithState(AllureExecutionState state, Func function) + public T GetWithState(AllureExecutionState state, Func function) { using ExecutionStateScope _ = new(this, state); return function(this.Runtime); @@ -34,7 +34,7 @@ public T GetWithState(AllureExecutionState state, Func fun /// public async Task GetWithStateAsync( AllureExecutionState state, - Func> asyncFunction + Func> asyncFunction ) { using ExecutionStateScope _ = new(this, state); @@ -44,7 +44,7 @@ Func> asyncFunction /// public AllureExecutionState RunWithState( AllureExecutionState state, - Action action + Action action ) { using ExecutionStateScope _ = new(this, state); @@ -55,7 +55,7 @@ Action action /// public async Task RunWithStateAsync( AllureExecutionState state, - Func asyncAction + Func asyncAction ) { using ExecutionStateScope _ = new(this, state); diff --git a/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs b/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs index f2367b18..06f3395d 100644 --- a/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs +++ b/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs @@ -30,7 +30,7 @@ IAllureModelApi modelApi where TConfiguration : AllureConfiguration { - AllureConfiguration IAllureRuntime.Configuration => this.Configuration; + AllureConfiguration IAllureRuntimeBase.Configuration => this.Configuration; /// public TConfiguration Configuration { get; } = configuration; diff --git a/src/Allure.Net.Sdk/Runtime/AsyncLocalExecutionContext.cs b/src/Allure.Net.Sdk/Runtime/AsyncLocalExecutionContext.cs index d7eb360c..c5a4fcc2 100644 --- a/src/Allure.Net.Sdk/Runtime/AsyncLocalExecutionContext.cs +++ b/src/Allure.Net.Sdk/Runtime/AsyncLocalExecutionContext.cs @@ -13,7 +13,7 @@ namespace Allure.Sdk.Runtime; /// A reference to the Allure runtime associated with this context. /// public sealed class AsyncLocalExecutionContext( - IReadOnlyLateBoundReference reference + IReadOnlyLateBoundReference reference ) : AllureExecutionContext(reference) { readonly AsyncLocal currentState = new() { Value = new() }; diff --git a/src/Allure.Net.Sdk/Runtime/IAllureExecutionContext.cs b/src/Allure.Net.Sdk/Runtime/IAllureExecutionContext.cs index 4ec7de0c..58519fad 100644 --- a/src/Allure.Net.Sdk/Runtime/IAllureExecutionContext.cs +++ b/src/Allure.Net.Sdk/Runtime/IAllureExecutionContext.cs @@ -12,7 +12,7 @@ public interface IAllureExecutionContext /// /// Gets the Allure runtime associated with this context. /// - IAllureRuntime Runtime { get; } + IAllureRuntimeBase Runtime { get; } /// /// Gets the current execution state for the current execution flow. @@ -47,7 +47,7 @@ public interface IAllureExecutionContext /// AllureExecutionState RunWithState( AllureExecutionState state, - Action action + Action action ); /// @@ -68,15 +68,15 @@ Action action /// The execution state that was current before the call is restored after /// the returned task completes, including when the action throws an /// exception. Unlike - /// , + /// , /// this method does not return the new state with the changes made within /// the asynchronous action. Use - /// + /// /// to capture the state from the asynchronous flow explicitly. /// Task RunWithStateAsync( AllureExecutionState state, - Func asyncAction + Func asyncAction ); /// @@ -103,7 +103,7 @@ Func asyncAction /// T GetWithState( AllureExecutionState state, - Func function + Func function ); /// @@ -131,6 +131,6 @@ Func function /// Task GetWithStateAsync( AllureExecutionState state, - Func> asyncFunction + Func> asyncFunction ); } diff --git a/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs b/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs index 15a85cd7..31397bbd 100644 --- a/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs +++ b/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs @@ -1,50 +1,12 @@ -using Allure.Abstractions; using Allure.Sdk.Configuration; -using Allure.Sdk.Results; namespace Allure.Sdk.Runtime; -/// -/// Exposes the configuration and services that make up an Allure runtime. -/// -public interface IAllureRuntime -{ - /// - /// Gets the runtime configuration. - /// - AllureConfiguration Configuration { get; } - - /// - /// Gets the execution-context service. - /// - IAllureExecutionContext ContextApi { get; } - - /// - /// Gets the lifecycle API. - /// - IAllureLifecycleApi LifecycleApi { get; } - - /// - /// Gets the model API. - /// - IAllureModelApi ModelApi { get; } - - /// - /// Gets the destination for generated results. - /// - IAllureResultsDestination ResultsDestination { get; } - - /// - /// Gets the parameter serializer. - /// - IAllureParameterSerializer ParameterSerializer { get; } -} - /// /// Exposes an Allure runtime with a strongly typed configuration. /// /// The runtime configuration type. -public interface IAllureRuntime : IAllureRuntime +public interface IAllureRuntime : IAllureRuntimeBase where TConfiguration : AllureConfiguration { /// diff --git a/src/Allure.Net.Sdk/Runtime/IAllureRuntimeBase.cs b/src/Allure.Net.Sdk/Runtime/IAllureRuntimeBase.cs new file mode 100644 index 00000000..b4fbd49b --- /dev/null +++ b/src/Allure.Net.Sdk/Runtime/IAllureRuntimeBase.cs @@ -0,0 +1,41 @@ +using Allure.Abstractions; +using Allure.Sdk.Configuration; +using Allure.Sdk.Results; + +namespace Allure.Sdk.Runtime; + +/// +/// Exposes the configuration and services that make up an Allure runtime. +/// +public interface IAllureRuntimeBase +{ + /// + /// Gets the runtime configuration. + /// + AllureConfiguration Configuration { get; } + + /// + /// Gets the execution-context service. + /// + IAllureExecutionContext ContextApi { get; } + + /// + /// Gets the lifecycle API. + /// + IAllureLifecycleApi LifecycleApi { get; } + + /// + /// Gets the model API. + /// + IAllureModelApi ModelApi { get; } + + /// + /// Gets the destination for generated results. + /// + IAllureResultsDestination ResultsDestination { get; } + + /// + /// Gets the parameter serializer. + /// + IAllureParameterSerializer ParameterSerializer { get; } +} diff --git a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironmentTests.cs b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironmentTests.cs index f5c4df76..fa8bc22b 100644 --- a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironmentTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironmentTests.cs @@ -10,7 +10,7 @@ public async Task ShouldBuildIsolatedRuntime() { var environment = RuntimeTestEnvironment.Create(); - await Assert.That(environment.Runtime).IsAssignableTo(); + await Assert.That(environment.Runtime).IsAssignableTo(); await Assert.That(environment.Runtime.ResultsDestination) .IsSameReferenceAs(environment.Destination); await Assert.That(environment.Destination) diff --git a/tests/Allure.Net.Sdk.Tests/Runtime/AsyncLocalExecutionContextTests.cs b/tests/Allure.Net.Sdk.Tests/Runtime/AsyncLocalExecutionContextTests.cs index 255d67be..dc31f9fa 100644 --- a/tests/Allure.Net.Sdk.Tests/Runtime/AsyncLocalExecutionContextTests.cs +++ b/tests/Allure.Net.Sdk.Tests/Runtime/AsyncLocalExecutionContextTests.cs @@ -155,7 +155,7 @@ Task ReadName(AllureExecutionState state) => } static AllureExecutionState CaptureTestState( - IAllureRuntime runtime, + IAllureRuntimeBase runtime, string name ) { From 60d3ff03a818ff1fa6c92baa3495c6785b8e6a66 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 17:47:08 +0700 Subject: [PATCH 11/14] feat(sdk): add convenience overload of IAllureRuntime --- .../IPreparedRuntimeRegistration.cs | 2 +- .../Registration/RegistrationContextFacade.cs | 2 +- .../Registration/AllureRuntimeBuilder.cs | 2 +- .../AllureRuntimeRegistrationSession.cs | 6 +++--- .../Hooks/IAllureRegistrationHook.cs | 3 --- .../Hooks/IAllureRuntimeRegistrationHook.cs | 4 ++++ .../IAllureEndpointIntegrationContext.cs | 2 +- .../IAllureRuntimeIntegrationContext.cs | 6 +++--- .../IAllureRuntimeIntegrationContextBase.cs | 2 +- .../IAllureRuntimeRegistration.cs | 2 +- .../IAllureRuntimeRegistrationPlan.cs | 2 +- src/Allure.Net.Sdk/Runtime/AllureRuntime.cs | 18 ++++++++++++++++++ src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs | 2 ++ .../Infrastructure/RuntimeTestEnvironment.cs | 19 +++++++++++++++---- 14 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs diff --git a/src/Allure.Net.Sdk/Internal/Registration/IPreparedRuntimeRegistration.cs b/src/Allure.Net.Sdk/Internal/Registration/IPreparedRuntimeRegistration.cs index 19b854e8..c4aa62e1 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/IPreparedRuntimeRegistration.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/IPreparedRuntimeRegistration.cs @@ -4,7 +4,7 @@ namespace Allure.Sdk.Internal.Registration; -internal interface IPreparedRuntimeRegistration +internal interface IPreparedRuntimeRegistration where TConfiguration : AllureConfiguration where TRuntime : IAllureRuntime { diff --git a/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs b/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs index 1a5811e6..69dca14e 100644 --- a/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs +++ b/src/Allure.Net.Sdk/Internal/Registration/RegistrationContextFacade.cs @@ -51,5 +51,5 @@ public void UseParameterSerializer(Func serializerFa sealed class RegistrationContextFacade( IAllureRuntimeIntegrationContext integrationContext ) : - RegistrationContextFacade>(integrationContext), + RegistrationContextFacade(integrationContext), IAllureRuntimeRegistrationContext; diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs index abc1c9a7..e78c75e7 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs @@ -110,7 +110,7 @@ public class AllureRuntimeBuilder(string runtimeName) : public class AllureRuntimeBuilder(string runtimeName) : AllureRuntimeBuilder< AllureConfiguration, - IAllureRuntime, + IAllureRuntime, IAllureRuntimeIntegrationContext >( runtimeName, diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index 4208d6d7..663ca189 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -437,7 +437,7 @@ RuntimeCreationArguments args public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< AllureConfiguration, - IAllureRuntime, + IAllureRuntime, IAllureRuntimeIntegrationContext, IAllureRuntimeRegistrationContext >, @@ -448,10 +448,10 @@ public class AllureRuntimeRegistrationSession : protected override IAllureRuntimeRegistrationContext RegistrationContext => new RegistrationContextFacade(this); - protected override IAllureRuntime CreateRuntime( + protected override IAllureRuntime CreateRuntime( RuntimeCreationArguments args ) => - new AllureRuntime( + new AllureRuntime( args.Configuration, args.ParameterSerializer, args.Destination, diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs index 6ac38e96..1abf2b2b 100644 --- a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs +++ b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs @@ -12,6 +12,3 @@ public interface IAllureRegistrationHook /// void SetUp(TContext context); } - -public interface IAllureRuntimeRegistrationHook : - IAllureRegistrationHook; diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs new file mode 100644 index 00000000..2bf3d748 --- /dev/null +++ b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs @@ -0,0 +1,4 @@ +namespace Allure.Sdk.Registration.Hooks; + +public interface IAllureRuntimeRegistrationHook : + IAllureRegistrationHook; diff --git a/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs index 664a220a..7f374479 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs @@ -9,7 +9,7 @@ namespace Allure.Sdk.Registration; /// Configures an external Allure runtime endpoint. /// /// The registration context type. -public interface IAllureEndpointIntegrationContext : IAllureEndpointRegistrationContext +public interface IAllureEndpointIntegrationContext : IAllureEndpointRegistrationContext where TContext : IAllureEndpointRegistrationContext { /// diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs index fc406db0..4b951d8b 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs @@ -12,7 +12,7 @@ namespace Allure.Sdk.Registration; /// The runtime configuration type. /// The type of runtime constructed by the integration. /// The type of runtime integration context. -public interface IAllureRuntimeIntegrationContext : +public interface IAllureRuntimeIntegrationContext : IAllureRuntimeIntegrationContextBase where TConfiguration : AllureConfiguration @@ -30,7 +30,7 @@ void UseRegistrationHooks( ); } -public interface IAllureRuntimeIntegrationContext : +public interface IAllureRuntimeIntegrationContext : IAllureRuntimeIntegrationContext< TConfiguration, TRuntime, @@ -58,6 +58,6 @@ public interface IAllureRuntimeIntegrationContext : public interface IAllureRuntimeIntegrationContext : IAllureRuntimeIntegrationContext< AllureConfiguration, - IAllureRuntime, + IAllureRuntime, IAllureRuntimeRegistrationContext >; diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs index 8dd64841..523f05e8 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs @@ -4,7 +4,7 @@ namespace Allure.Sdk.Registration; -public interface IAllureRuntimeIntegrationContextBase : +public interface IAllureRuntimeIntegrationContextBase : IAllureRuntimeRegistrationContext where TConfiguration : AllureConfiguration diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistration.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistration.cs index 1c83ac91..e5c2be4b 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistration.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistration.cs @@ -14,7 +14,7 @@ namespace Allure.Sdk.Registration; /// . /// /// The runtime type. -public interface IAllureRuntimeRegistration : +public interface IAllureRuntimeRegistration : IDisposable, IAsyncDisposable diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationPlan.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationPlan.cs index ce0a5e5e..59181eba 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationPlan.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationPlan.cs @@ -13,7 +13,7 @@ namespace Allure.Sdk.Registration; /// /// The runtime configuration type. /// The runtime type. -public interface IAllureRuntimeRegistrationPlan +public interface IAllureRuntimeRegistrationPlan where TConfiguration : AllureConfiguration where TRuntime : IAllureRuntime { diff --git a/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs b/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs index 06f3395d..e9e9b9fc 100644 --- a/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs +++ b/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs @@ -50,3 +50,21 @@ IAllureModelApi modelApi /// public IAllureModelApi ModelApi { get; } = modelApi; } + +public class AllureRuntime( + AllureConfiguration configuration, + IAllureParameterSerializer parameterSerializer, + IAllureResultsDestination resultsDestination, + IAllureExecutionContext context, + IAllureLifecycleApi lifecycleApi, + IAllureModelApi modelApi +) : + AllureRuntime( + configuration, + parameterSerializer, + resultsDestination, + context, + lifecycleApi, + modelApi + ), + IAllureRuntime; diff --git a/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs b/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs index 31397bbd..937aac8a 100644 --- a/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs +++ b/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs @@ -14,3 +14,5 @@ public interface IAllureRuntime : IAllureRuntimeBase /// new TConfiguration Configuration { get; } } + +public interface IAllureRuntime : IAllureRuntime; diff --git a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs index 81e0577c..aaf5085f 100644 --- a/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs +++ b/tests/Allure.Net.Sdk.Tests/Infrastructure/RuntimeTestEnvironment.cs @@ -10,7 +10,7 @@ sealed class RuntimeTestEnvironment : IDisposable where TConfiguration : AllureConfiguration, new() { readonly IAllureRuntimeRegistration> registration; - RuntimeTestEnvironment( + internal RuntimeTestEnvironment( IAllureRuntimeRegistration> registration, InMemoryResultsDestination destination ) @@ -52,9 +52,20 @@ sealed class RuntimeTestEnvironment { public static RuntimeTestEnvironment Create( AllureConfiguration? configuration = null, - Action>? configure = null - ) => - RuntimeTestEnvironment.Create(configuration, configure); + Action? configure = null + ) + { + var destination = new InMemoryResultsDestination(); + var builder = new AllureRuntimeBuilder("sdk-test"); + var plan = builder.Prepare((ctx) => + { + ctx.UseConfiguration(configuration ?? new AllureConfiguration()); + ctx.UseDestination(_ => destination); + configure?.Invoke(ctx); + }); + + return new(plan.Build(), destination); + } } sealed class RecordingRuntimeHook( From e0201b0ebd410f2ac5f7ec2db432d7993f651e49 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 18:02:57 +0700 Subject: [PATCH 12/14] docs(sdk): fix doc comments --- .../AllureRegistrationDefaults.cs | 34 ++++++++++++--- .../Registration/AllureRuntimeBuilder.cs | 33 +++++++++++++- .../AllureRuntimeRegistrationSession.cs | 43 ++++++++++++++++--- .../AllureRuntimeRegistrationSessionBase.cs | 8 ++++ .../Hooks/IAllureRegistrationHook.cs | 5 ++- .../Hooks/IAllureRuntimeRegistrationHook.cs | 3 ++ .../IAllureEndpointIntegrationContext.cs | 16 ++++++- ...lureInProcessEndpointIntegrationContext.cs | 14 ++++++ ...ureInProcessEndpointRegistrationContext.cs | 12 ++++++ .../IAllureRuntimeIntegrationContext.cs | 11 ++++- .../IAllureRuntimeIntegrationContextBase.cs | 5 +++ .../IAllureRuntimeRegistrationContext.cs | 4 ++ src/Allure.Net.Sdk/Runtime/AllureRuntime.cs | 10 +++++ src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs | 4 ++ 14 files changed, 184 insertions(+), 18 deletions(-) diff --git a/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs b/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs index 4db8c9a9..ad6b780f 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRegistrationDefaults.cs @@ -15,8 +15,10 @@ namespace Allure.Sdk.Registration; public static class AllureRegistrationDefaults { /// - /// Creates the default ordered configuration-source factory. + /// Creates the default factory for an ordered sequence of configuration sources. /// + /// The runtime configuration type. + /// A factory that creates the default configuration sources. public static Func>> ConfigurationSources() where TConfiguration : AllureConfiguration, new() => @@ -26,8 +28,12 @@ public static Func>> Conf ]; /// - /// Creates the default file-system results-destination factory. + /// Creates the default file-system results destination factory. /// + /// The runtime configuration type. + /// + /// A factory that creates a results destination from the resolved configuration. + /// public static Func Destination() where TConfiguration : AllureConfiguration => @@ -37,8 +43,15 @@ public static Func Destination - /// Creates an endpoint rule-based parameter-serializer factory from rule registrations. + /// Creates a rule-based parameter serializer factory for an in-process endpoint. /// + /// The runtime type. + /// + /// The actions that configure serialization rules using the constructed runtime. + /// + /// + /// A factory that creates a parameter serializer from the constructed runtime. + /// public static Func EndpointParameterSerializer( IEnumerable> registrations ) @@ -55,8 +68,15 @@ IEnumerable> registrations }; /// - /// Creates a runtime rule-based parameter-serializer factory from rule registrations. + /// Creates a rule-based parameter serializer factory for a runtime. /// + /// The runtime configuration type. + /// + /// The actions that configure serialization rules using the resolved configuration. + /// + /// + /// A factory that creates a parameter serializer from the resolved configuration. + /// public static Func RuntimeParameterSerializer( IEnumerable> registrations ) @@ -73,10 +93,14 @@ IEnumerable> registr }; /// - /// Creates the default runtime-hook provider factory. + /// Creates the default runtime registration hook factory. /// /// The runtime configuration type. /// The runtime registration context type. + /// + /// A factory that discovers registration hooks from the environment and the + /// resolved configuration. + /// public static Func?>> RuntimeHookProviders() where TConfiguration : AllureConfiguration, new() where TContext : IAllureRuntimeRegistrationContext diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs index e78c75e7..e3316b72 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeBuilder.cs @@ -11,8 +11,12 @@ namespace Allure.Sdk.Registration; /// /// The runtime configuration type. /// The type of runtime constructed by the builder. -/// The integration context type. -/// The runtime name used to identify its in-process route. +/// +/// The integration context type passed to the registration action. +/// +/// +/// The runtime name assigned to its in-process endpoint. +/// /// /// A factory that creates the single-use registration session configured by /// . @@ -74,6 +78,16 @@ Action registration const int STAGE_CONSUMED = 1; } +/// +/// Prepares registration of a custom Allure runtime using the standard +/// integration and registration contexts. +/// +/// The runtime configuration type. +/// The type of runtime constructed by the builder. +/// +/// The runtime name assigned to its in-process endpoint. +/// +/// A factory that creates a registration session. public class AllureRuntimeBuilder( string runtimeName, Func< @@ -95,6 +109,14 @@ public class AllureRuntimeBuilder( where TConfiguration : AllureConfiguration, new() where TRuntime : IAllureRuntime; +/// +/// Prepares registration of a standard Allure runtime with a custom +/// configuration type. +/// +/// The runtime configuration type. +/// +/// The runtime name assigned to its in-process endpoint. +/// public class AllureRuntimeBuilder(string runtimeName) : AllureRuntimeBuilder< TConfiguration, @@ -107,6 +129,13 @@ public class AllureRuntimeBuilder(string runtimeName) : where TConfiguration : AllureConfiguration, new(); +/// +/// Prepares registration of a standard Allure runtime and its optional +/// in-process endpoint. +/// +/// +/// The runtime name assigned to its in-process endpoint. +/// public class AllureRuntimeBuilder(string runtimeName) : AllureRuntimeBuilder< AllureConfiguration, diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index 663ca189..09b93755 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -189,17 +189,20 @@ protected void Modify(Action action) } /// - /// Gets the integration-specific context passed to runtime registration - /// hooks. + /// Gets the integration-specific context passed to the registration action. /// protected abstract TIntegrationContext IntegrationContext { get; } /// - /// Gets the integration-specific context passed to hooks - /// hooks. + /// Gets the integration-specific context passed to runtime registration hooks. /// protected abstract TRegistrationContext RegistrationContext { get; } + /// + /// Creates the runtime from the components resolved by this registration session. + /// + /// The resolved runtime components. + /// The constructed runtime. protected abstract TRuntime CreateRuntime(RuntimeCreationArguments args); internal override IPreparedRuntimeRegistration Prepare( @@ -361,6 +364,13 @@ enum RegistrationState } } +/// +/// Provides a single-use registration session for a custom Allure runtime with +/// a custom integration context and the standard runtime registration context. +/// +/// The runtime configuration type. +/// The runtime type. +/// The runtime integration context type. public abstract class AllureRuntimeRegistrationSession< TConfiguration, TRuntime, @@ -381,12 +391,17 @@ public abstract class AllureRuntimeRegistrationSession< IAllureRuntimeRegistrationContext > { + /// protected override IAllureRuntimeRegistrationContext RegistrationContext => new RegistrationContextFacade(this); - - } +/// +/// Provides a single-use registration session for a custom Allure runtime using +/// the standard integration and registration contexts. +/// +/// The runtime configuration type. +/// The runtime type. public abstract class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< TConfiguration, @@ -399,12 +414,19 @@ public abstract class AllureRuntimeRegistrationSession where TConfiguration : AllureConfiguration, new() where TRuntime : IAllureRuntime { + /// protected override IAllureRuntimeRegistrationContext RegistrationContext => new RegistrationContextFacade(this); + /// protected override IAllureRuntimeIntegrationContext IntegrationContext => this; } +/// +/// Provides a single-use registration session for a standard Allure runtime +/// with a custom configuration type. +/// +/// The runtime configuration type. public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< TConfiguration, @@ -416,11 +438,14 @@ public class AllureRuntimeRegistrationSession : where TConfiguration : AllureConfiguration, new() { + /// protected override IAllureRuntimeIntegrationContext IntegrationContext => this; + /// protected override IAllureRuntimeRegistrationContext RegistrationContext => new RegistrationContextFacade>(this); + /// protected override IAllureRuntime CreateRuntime( RuntimeCreationArguments args ) => @@ -434,6 +459,9 @@ RuntimeCreationArguments args ); } +/// +/// Provides a single-use registration session for a standard Allure runtime. +/// public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< AllureConfiguration, @@ -443,11 +471,14 @@ public class AllureRuntimeRegistrationSession : >, IAllureRuntimeIntegrationContext { + /// protected override IAllureRuntimeIntegrationContext IntegrationContext => this; + /// protected override IAllureRuntimeRegistrationContext RegistrationContext => new RegistrationContextFacade(this); + /// protected override IAllureRuntime CreateRuntime( RuntimeCreationArguments args ) => diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSessionBase.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSessionBase.cs index 96eeb32d..eb468453 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSessionBase.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSessionBase.cs @@ -5,6 +5,14 @@ namespace Allure.Sdk.Registration; +/// +/// Defines the base contract for a single-use runtime registration session. +/// +/// The runtime configuration type. +/// The runtime type. +/// +/// The runtime integration context type passed to the registration action. +/// public abstract class AllureRuntimeRegistrationSessionBase where TConfiguration : AllureConfiguration, new() diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs index 1abf2b2b..d225afba 100644 --- a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs +++ b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRegistrationHook.cs @@ -1,14 +1,15 @@ namespace Allure.Sdk.Registration.Hooks; /// -/// Customizes an Allure runtime during registration. +/// Customizes an Allure component during registration. /// /// The registration context type. public interface IAllureRegistrationHook where TContext : IAllureRegistrationContext { /// - /// Applies custom runtime configuration. + /// Applies custom registration configuration. /// + /// The active registration context. void SetUp(TContext context); } diff --git a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs index 2bf3d748..20a7e4e9 100644 --- a/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs +++ b/src/Allure.Net.Sdk/Registration/Hooks/IAllureRuntimeRegistrationHook.cs @@ -1,4 +1,7 @@ namespace Allure.Sdk.Registration.Hooks; +/// +/// Customizes a standard Allure runtime during registration. +/// public interface IAllureRuntimeRegistrationHook : IAllureRegistrationHook; diff --git a/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs index 7f374479..1293b7b1 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureEndpointIntegrationContext.cs @@ -6,7 +6,7 @@ namespace Allure.Sdk.Registration; /// -/// Configures an external Allure runtime endpoint. +/// Configures an external Allure runtime endpoint and its registration hooks. /// /// The registration context type. public interface IAllureEndpointIntegrationContext : IAllureEndpointRegistrationContext @@ -15,6 +15,7 @@ public interface IAllureEndpointIntegrationContext : IAllureEndpoi /// /// Configures the hooks invoked during endpoint registration. /// + /// A factory that creates the registration hooks. void UseRegistrationHooks( Func?>> hooksFactory ); @@ -22,18 +23,31 @@ void UseRegistrationHooks( /// /// Configures the predicate used to match the current test or fixture scope. /// + /// + /// A function that returns when the endpoint matches + /// the current scope. + /// void UseCurrentScopePredicate(Func predicate); /// /// Configures the predicate used to match the global scope. /// + /// + /// A function that returns when the endpoint matches + /// the global scope. + /// void UseGlobalScopePredicate(Func predicate); /// /// Configures the operations exposed by the endpoint. /// + /// A factory that creates the endpoint operations. void UseOperations(Func operationsFactory); } +/// +/// Configures an external Allure runtime endpoint using the standard endpoint +/// registration context. +/// public interface IAllureEndpointIntegrationContext : IAllureEndpointIntegrationContext; diff --git a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs index 1381fd26..ea7bfee3 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointIntegrationContext.cs @@ -18,6 +18,9 @@ public interface IAllureInProcessEndpointIntegrationContext : /// /// Configures the hooks invoked during endpoint registration. /// + /// + /// A factory that creates the registration hooks from the constructed runtime. + /// void UseRegistrationHooks( Func< TRuntime, @@ -32,15 +35,26 @@ void UseRegistrationHooks( /// /// Configures the predicate used to match the current test or fixture scope. /// + /// + /// A function that uses the constructed runtime to determine whether the + /// endpoint matches the current scope. + /// void UseCurrentScopePredicate(Func predicate); /// /// Configures the predicate used to match the global scope. /// + /// + /// A function that uses the constructed runtime to determine whether the + /// endpoint matches the global scope. + /// void UseGlobalScopePredicate(Func predicate); /// /// Configures the operations exposed by the endpoint. /// + /// + /// A factory that creates the endpoint operations from the constructed runtime. + /// void UseOperations(Func operationsFactory); } diff --git a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs index 843b61fa..fbb0cc17 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureInProcessEndpointRegistrationContext.cs @@ -17,6 +17,9 @@ public interface IAllureInProcessEndpointRegistrationContext : /// /// Configures the parameter serializer used by the endpoint. /// + /// + /// A factory that creates the serializer from the constructed runtime. + /// void UseParameterSerializer( Func serializerFactory ); @@ -24,15 +27,24 @@ Func serializerFactory /// /// Configures parameter serialization rules used by the endpoint. /// + /// + /// An action that configures the serialization rules using the constructed runtime. + /// void ConfigureSerialization(Action registration); /// /// Configures endpoint availability using the constructed runtime. /// + /// + /// A function that determines whether the endpoint is available. + /// void SetAvailabilityPredicate(Func isAvailable); /// /// Configures suppressed route IDs using the constructed runtime. /// + /// + /// A factory that returns the route IDs suppressed by this endpoint. + /// void SuppressRoutes(Func> routeIdsFactory); } diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs index 4b951d8b..7f00e65e 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContext.cs @@ -11,7 +11,7 @@ namespace Allure.Sdk.Registration; /// /// The runtime configuration type. /// The type of runtime constructed by the integration. -/// The type of runtime integration context. +/// The runtime registration context type. public interface IAllureRuntimeIntegrationContext : IAllureRuntimeIntegrationContextBase @@ -30,6 +30,12 @@ void UseRegistrationHooks( ); } +/// +/// Configures a custom Allure runtime and its optional in-process endpoint using +/// the standard runtime registration context. +/// +/// The runtime configuration type. +/// The type of runtime constructed by the integration. public interface IAllureRuntimeIntegrationContext : IAllureRuntimeIntegrationContext< TConfiguration, @@ -41,7 +47,8 @@ public interface IAllureRuntimeIntegrationContext where TRuntime : IAllureRuntime; /// -/// Configures a standard Allure runtime with a custom configuration type. +/// Configures a standard Allure runtime with a custom configuration type and an +/// optional in-process endpoint. /// /// The runtime configuration type. public interface IAllureRuntimeIntegrationContext : diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs index 523f05e8..b999f9d2 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeIntegrationContextBase.cs @@ -4,6 +4,11 @@ namespace Allure.Sdk.Registration; +/// +/// Configures the services and optional in-process endpoint of an Allure runtime. +/// +/// The runtime configuration type. +/// The type of runtime constructed by the integration. public interface IAllureRuntimeIntegrationContextBase : IAllureRuntimeRegistrationContext diff --git a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs index 4b1b7dfa..e32bee45 100644 --- a/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs +++ b/src/Allure.Net.Sdk/Registration/IAllureRuntimeRegistrationContext.cs @@ -66,5 +66,9 @@ Func serializerFactory void UseDestination(Func destinationFactory); } +/// +/// Configures an Allure runtime that uses the standard +/// before it is constructed. +/// public interface IAllureRuntimeRegistrationContext : IAllureRuntimeRegistrationContext; diff --git a/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs b/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs index e9e9b9fc..ffef44f6 100644 --- a/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs +++ b/src/Allure.Net.Sdk/Runtime/AllureRuntime.cs @@ -51,6 +51,16 @@ IAllureModelApi modelApi public IAllureModelApi ModelApi { get; } = modelApi; } +/// +/// Provides the standard implementation of an Allure runtime using +/// . +/// +/// The runtime configuration. +/// The parameter serializer. +/// The destination for generated results. +/// The execution-context service. +/// The lifecycle API. +/// The model API. public class AllureRuntime( AllureConfiguration configuration, IAllureParameterSerializer parameterSerializer, diff --git a/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs b/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs index 937aac8a..31f344cf 100644 --- a/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs +++ b/src/Allure.Net.Sdk/Runtime/IAllureRuntime.cs @@ -15,4 +15,8 @@ public interface IAllureRuntime : IAllureRuntimeBase new TConfiguration Configuration { get; } } +/// +/// Exposes an Allure runtime that uses the standard +/// . +/// public interface IAllureRuntime : IAllureRuntime; From db5d214799d3907818f7bffd845291ef301b5847 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 18:56:02 +0700 Subject: [PATCH 13/14] feat(sdk): use registration context in 3-param session --- .../AllureRuntimeRegistrationSession.cs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs index 09b93755..2af29e3d 100644 --- a/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs +++ b/src/Allure.Net.Sdk/Registration/AllureRuntimeRegistrationSession.cs @@ -17,9 +17,9 @@ namespace Allure.Sdk.Registration; /// /// The runtime configuration type. /// The runtime type. -/// The runtime integration context type. /// The runtime registration context type. -public abstract class AllureRuntimeRegistrationSession : +/// The runtime integration context type. +public abstract class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSessionBase, IAllureRuntimeIntegrationContext @@ -370,30 +370,30 @@ enum RegistrationState /// /// The runtime configuration type. /// The runtime type. -/// The runtime integration context type. +/// The runtime registration context type. public abstract class AllureRuntimeRegistrationSession< TConfiguration, TRuntime, - TIntegrationContext + TRegistrationContext > : AllureRuntimeRegistrationSession< TConfiguration, TRuntime, - TIntegrationContext, - IAllureRuntimeRegistrationContext + TRegistrationContext, + IAllureRuntimeIntegrationContext< + TConfiguration, + TRuntime, + TRegistrationContext + > > where TConfiguration : AllureConfiguration, new() where TRuntime : IAllureRuntime - where TIntegrationContext : IAllureRuntimeIntegrationContext< - TConfiguration, - TRuntime, - IAllureRuntimeRegistrationContext - > + where TRegistrationContext : IAllureRuntimeRegistrationContext { /// - protected override IAllureRuntimeRegistrationContext RegistrationContext => - new RegistrationContextFacade(this); + protected override IAllureRuntimeIntegrationContext IntegrationContext => + this; } /// @@ -406,8 +406,8 @@ public abstract class AllureRuntimeRegistrationSession AllureRuntimeRegistrationSession< TConfiguration, TRuntime, - IAllureRuntimeIntegrationContext, - IAllureRuntimeRegistrationContext + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext >, IAllureRuntimeIntegrationContext @@ -431,8 +431,8 @@ public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< TConfiguration, IAllureRuntime, - IAllureRuntimeIntegrationContext, - IAllureRuntimeRegistrationContext + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext >, IAllureRuntimeIntegrationContext @@ -466,8 +466,8 @@ public class AllureRuntimeRegistrationSession : AllureRuntimeRegistrationSession< AllureConfiguration, IAllureRuntime, - IAllureRuntimeIntegrationContext, - IAllureRuntimeRegistrationContext + IAllureRuntimeRegistrationContext, + IAllureRuntimeIntegrationContext >, IAllureRuntimeIntegrationContext { From 54dc7213465b5fd11e2b92d34904c96fae29473a Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 12 Aug 2026 19:37:43 +0700 Subject: [PATCH 14/14] docs(sdk): fix README --- src/Allure.Net.Sdk/README.md | 636 +++++++++++++++++------------------ 1 file changed, 313 insertions(+), 323 deletions(-) diff --git a/src/Allure.Net.Sdk/README.md b/src/Allure.Net.Sdk/README.md index 70cf3230..4b554663 100644 --- a/src/Allure.Net.Sdk/README.md +++ b/src/Allure.Net.Sdk/README.md @@ -1,8 +1,7 @@ # Allure.Net.Sdk -[![Nuget release](https://img.shields.io/nuget/v/Allure.Net.Sdk?style=flat)](https://www.nuget.org/packages/Allure.Net.Sdk) -[![Nuget downloads](https://img.shields.io/nuget/dt/Allure.Net.Sdk?label=downloads&style=flat)](https://www.nuget.org/packages/Allure.Net.Sdk) - +[![NuGet release](https://img.shields.io/nuget/v/Allure.Net.Sdk?style=flat)](https://www.nuget.org/packages/Allure.Net.Sdk) +[![NuGet downloads](https://img.shields.io/nuget/dt/Allure.Net.Sdk?label=downloads&style=flat)](https://www.nuget.org/packages/Allure.Net.Sdk) > Allure.Net.Sdk provides APIs and utilities for building Allure test-framework integrations. @@ -11,9 +10,9 @@ - Learn more about Allure Report at [https://allurereport.org](https://allurereport.org) - 📚 [Documentation](https://allurereport.org/docs/) – discover official documentation for Allure Report - ❓ [Questions and Support](https://github.com/orgs/allure-framework/discussions/categories/questions-support) – get help from the team and community -- 📢 [Official announcements](https://github.com/orgs/allure-framework/discussions/categories/announcements) – stay updated with our latest news and updates +- 📢 [Official announcements](https://github.com/orgs/allure-framework/discussions/categories/announcements) – stay updated with our latest news and updates - 💬 [General Discussion](https://github.com/orgs/allure-framework/discussions/categories/general-discussion) – engage in casual conversations, share insights and ideas with the community -- 🖥️ [Live Demo](https://demo.allurereport.org/) — explore a live example of Allure Report in action +- 🖥️ [Live Demo](https://demo.allurereport.org/) – explore a live example of Allure Report in action --- @@ -35,33 +34,28 @@ adapter built with this package, rather than using the SDK directly. ## Build a runtime Create one runtime for each independently configured integration instance and -keep its registration alive for the lifetime of that instance. Use one of the -builders provided by `Allure.Net.Sdk`. A builder is single-use: its `Prepare` -method resolves configuration, runs registration hooks, and returns an -`IAllureRuntimeRegistrationPlan`. Calling `Build` on -the plan constructs the runtime and installs its configured endpoint. The -returned `IAllureRuntimeRegistration` exposes the runtime through its -`Runtime` property. `Dispose` removes the endpoint and disposes a synchronous -runtime; `DisposeAsync` also supports asynchronously disposable runtimes. - -Choose the simplest builder that provides the extension points your integration -needs. +keep its registration alive for the lifetime of that instance. A builder is +single-use: call `Prepare` once to resolve configuration and run registration +hooks, then call `Build` once to construct the runtime and install its optional +endpoint. Access the runtime through `registration.Runtime`. + +Dispose the registration when the integration shuts down. This removes the +endpoint and disposes the runtime. Use `DisposeAsync` for a runtime that needs +asynchronous disposal. ### Use the standard runtime and configuration If the integration does not add configuration properties or runtime services, -use the non-generic `AllureRuntimeBuilder`. No custom builder, registration -session, integration snapshot, context, or hook types are required: +use the non-generic `AllureRuntimeBuilder`: ```csharp -using Allure.Sdk.Configuration; using Allure.Sdk.Registration; using Allure.Sdk.Runtime; var builder = new AllureRuntimeBuilder("My Test Framework"); var plan = builder.Prepare(_ => { }); using var registration = plan.Build(); -IAllureRuntime runtime = registration.Runtime; +IAllureRuntime runtime = registration.Runtime; ``` The registration action passed to `Prepare` receives an @@ -70,8 +64,9 @@ The registration action passed to `Prepare` receives an - select configuration sources; - configure the results destination and parameter serialization; - replace the execution context, lifecycle API, or model API; -- configure runtime and endpoint hook providers; -- register an in-process endpoint that connects the Allure API with the runtime. +- configure runtime hooks; +- register and configure an in-process endpoint that connects the public Allure + API with the runtime. #### Let framework users customize registration @@ -94,11 +89,10 @@ public sealed class ProjectAllureRegistration : } ``` -By default, the builder first loads the hook named by the -`ALLURE_RUNTIME_REGISTRATION_HOOK` environment variable, then the hook named -by the resolved configuration's `runtimeRegistrationHook` property. Unset -hooks are ignored. For example, a user can select a hook in -`allureConfig.json`: +By default, the builder looks for hooks in two places: first in the +`ALLURE_RUNTIME_REGISTRATION_HOOK` environment variable, then in the resolved +configuration's `runtimeRegistrationHook` property. For example, a user can +select a hook in `allureConfig.json`: ```json { @@ -142,9 +136,11 @@ var plan = builder.Prepare(context => }); using var registration = plan.Build(); -IAllureRuntime runtime = registration.Runtime; +IAllureRuntime runtime = registration.Runtime; ``` +Unset hooks are ignored. + To disable registration hooks, return an empty collection: ```csharp @@ -156,173 +152,56 @@ var plan = builder.Prepare(context => ### Add integration-specific configuration Derive from `AllureConfiguration` when the integration needs additional -settings but can otherwise use the standard `AllureRuntime`. -This scenario uses the seven-parameter `AllureRuntimeBuilder` together with a -matching registration session and integration snapshot: +settings but can otherwise use the standard runtime: ```csharp using Allure.Sdk.Configuration; -using Allure.Sdk.Registration; -using Allure.Sdk.Registration.Hooks; -using Allure.Sdk.Runtime; public sealed record class MyFrameworkConfiguration : AllureConfiguration { public bool CaptureFrameworkOutput { get; init; } = true; } +``` -public interface IMyFrameworkRuntimeRegistrationContext : - IAllureRuntimeRegistrationContext; - -public interface IMyFrameworkRuntimeRegistrationHook : - IAllureRuntimeRegistrationHook< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext - >; - -public interface IMyFrameworkEndpointRegistrationContext : - IAllureInProcessEndpointRegistrationContext; +Then pass the configuration type to `AllureRuntimeBuilder`: -public interface IMyFrameworkEndpointRegistrationHook : - IAllureInProcessEndpointRegistrationHook< - MyFrameworkConfiguration, - IMyFrameworkEndpointRegistrationContext - >; - -sealed class MyFrameworkRouteBuilder( - AllureRouteBuilderArgs< - MyFrameworkConfiguration, - IAllureRuntime - > args -) : - AllureInProcessRouteBuilder< - MyFrameworkConfiguration, - IMyFrameworkEndpointRegistrationContext, - IMyFrameworkEndpointRegistrationHook, - IAllureRuntime - >(args), - IMyFrameworkEndpointRegistrationContext -{ - protected override IMyFrameworkEndpointRegistrationContext - RegistrationContext => this; -} - -public sealed class MyFrameworkRuntimeIntegrationSnapshot : - AllureRuntimeIntegrationSnapshot< - MyFrameworkConfiguration, - IMyFrameworkEndpointRegistrationContext, - IMyFrameworkEndpointRegistrationHook - > -{ - public override AllureInProcessRouteBuilder< - MyFrameworkConfiguration, - IMyFrameworkEndpointRegistrationContext, - IMyFrameworkEndpointRegistrationHook, - IAllureRuntime - > CreateRouteBuilder( - AllureRouteBuilderArgs< - MyFrameworkConfiguration, - IAllureRuntime - > args - ) => new MyFrameworkRouteBuilder(args); -} +```csharp +using Allure.Sdk.Registration; +using Allure.Sdk.Runtime; -sealed class MyFrameworkRuntimeRegistrationSession : - AllureRuntimeRegistrationSession< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkEndpointRegistrationContext, - IMyFrameworkEndpointRegistrationHook, - IAllureRuntimeIntegrationContext< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkEndpointRegistrationContext, - IMyFrameworkEndpointRegistrationHook - >, - MyFrameworkRuntimeIntegrationSnapshot - >, - IMyFrameworkRuntimeRegistrationContext +var builder = new AllureRuntimeBuilder( + "My Test Framework" +); +var plan = builder.Prepare(context => { - protected override IAllureRuntimeIntegrationContext< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkEndpointRegistrationContext, - IMyFrameworkEndpointRegistrationHook - > IntegrationContext => this; - - protected override IMyFrameworkRuntimeRegistrationContext - RegistrationContext => this; - - protected override MyFrameworkRuntimeIntegrationSnapshot - CaptureIntegrationSnapshot() => new(); -} + // Configure sources, serialization, hooks, or an endpoint here. +}); +using var registration = plan.Build(); -public sealed class MyFrameworkRuntimeBuilder(string runtimeName) : - AllureRuntimeBuilder< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkEndpointRegistrationContext, - IMyFrameworkEndpointRegistrationHook, - IAllureRuntimeIntegrationContext< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkEndpointRegistrationContext, - IMyFrameworkEndpointRegistrationHook - >, - MyFrameworkRuntimeIntegrationSnapshot - >( - runtimeName, - () => new MyFrameworkRuntimeRegistrationSession() - ); +IAllureRuntime runtime = registration.Runtime; ``` -The integration prepares and builds the standard runtime, then retains its -registration: +Expose a framework-specific hook interface so users do not need to reference +the SDK's generic hook contract directly: ```csharp -var builder = new MyFrameworkRuntimeBuilder("My Test Framework"); -var plan = builder.Prepare(_ => { }); -using var registration = plan.Build(); +using Allure.Sdk.Registration; +using Allure.Sdk.Registration.Hooks; -IAllureRuntime runtime = registration.Runtime; +public interface IMyFrameworkRuntimeRegistrationHook : + IAllureRegistrationHook< + IAllureRuntimeRegistrationContext + >; ``` -Implementation checklist: - -- Define `MyFrameworkConfiguration`, derived from `AllureConfiguration`. -- Define the runtime registration context and hook interfaces for that - configuration. -- Define the in-process endpoint registration context and hook interfaces for - `IAllureRuntime`. -- Define a route builder derived from `AllureInProcessRouteBuilder<...>` and implement the in-process endpoint registration context interface you've defined earlier. - Return `this` from `RegistrationContext`. -- Define an integration snapshot derived from - `AllureRuntimeIntegrationSnapshot<...>` and create the route builder in - `CreateRouteBuilder`. -- Define a registration session derived from the seven-parameter - `AllureRuntimeRegistrationSession<...>` and implement the runtime registration context interface you've defined earlier; return the session itself from both - context properties and create the snapshot in - `CaptureIntegrationSnapshot`. -- Optionally, define a builder derived from the seven-parameter `AllureRuntimeBuilder<...>` - and pass a factory for the registration session to its base constructor. Alternatively, you can create an instance of the seven-parameter `AllureRuntimeBuilder<...>` directly where needed. -- At startup, instantiate that builder, call `Prepare` once with the desired - registrations, call `Build` once on the returned plan, and retain the - registration. - -Framework users customize registration by implementing the hook interface -provided by the integration: +Users can then customize the runtime by implementing that interface: ```csharp public sealed class ProjectAllureRegistration : IMyFrameworkRuntimeRegistrationHook { public void SetUp( - IMyFrameworkRuntimeRegistrationContext context + IAllureRuntimeRegistrationContext context ) { context.ConfigureSerialization( @@ -332,24 +211,24 @@ public sealed class ProjectAllureRegistration : } ``` +The branded interface becomes part of the integration's public API. Because it +derives from the generic SDK contract, it remains compatible with the standard +registration pipeline. As in the standard configuration example, use +`UseRegistrationHooks` to customize where hooks are loaded from. + ### Add integration-specific runtime services If the integration also exposes additional runtime services, derive a runtime -from `AllureRuntime`. This scenario uses the eight-parameter -`AllureRuntimeBuilder`; its integration snapshot constructs both the custom -runtime and the custom route builder. The runtime registration context and hook -from the previous example can be reused. Replace scenario 2's endpoint types, -route builder, integration snapshot, registration session, and runtime builder -with custom-runtime versions: +from `AllureRuntime` and define a registration session to +construct it: ```csharp using Allure.Abstractions; using Allure.Sdk.Registration; -using Allure.Sdk.Registration.Hooks; using Allure.Sdk.Results; using Allure.Sdk.Runtime; -// An extra service to add. +// An extra runtime service. public sealed class FrameworkOutputCapture(bool enabled) { public bool Enabled { get; } = enabled; @@ -375,58 +254,10 @@ public sealed class MyFrameworkRuntime( public FrameworkOutputCapture OutputCapture { get; } = outputCapture; } -public interface IMyFrameworkRuntimeEndpointRegistrationContext : - IAllureInProcessEndpointRegistrationContext< - MyFrameworkConfiguration, - MyFrameworkRuntime - >; - -public interface IMyFrameworkRuntimeEndpointRegistrationHook : - IAllureInProcessEndpointRegistrationHook< - MyFrameworkConfiguration, - IMyFrameworkRuntimeEndpointRegistrationContext, - MyFrameworkRuntime - >; - -sealed class MyFrameworkRuntimeRouteBuilder( - AllureRouteBuilderArgs< - MyFrameworkConfiguration, - MyFrameworkRuntime - > args -) : - AllureInProcessRouteBuilder< - MyFrameworkConfiguration, - IMyFrameworkRuntimeEndpointRegistrationContext, - IMyFrameworkRuntimeEndpointRegistrationHook, - MyFrameworkRuntime - >(args), - IMyFrameworkRuntimeEndpointRegistrationContext -{ - protected override IMyFrameworkRuntimeEndpointRegistrationContext - RegistrationContext => this; -} - -public sealed class MyFrameworkRuntimeIntegrationSnapshot : - IAllureRuntimeIntegrationSnapshot< - MyFrameworkConfiguration, - IMyFrameworkRuntimeEndpointRegistrationContext, - IMyFrameworkRuntimeEndpointRegistrationHook, - MyFrameworkRuntime - > +sealed class MyFrameworkRuntimeRegistrationSession : + AllureRuntimeRegistrationSession { - public AllureInProcessRouteBuilder< - MyFrameworkConfiguration, - IMyFrameworkRuntimeEndpointRegistrationContext, - IMyFrameworkRuntimeEndpointRegistrationHook, - MyFrameworkRuntime - > CreateRouteBuilder( - AllureRouteBuilderArgs< - MyFrameworkConfiguration, - MyFrameworkRuntime - > args - ) => new MyFrameworkRuntimeRouteBuilder(args); - - public MyFrameworkRuntime CreateRuntime( + protected override MyFrameworkRuntime CreateRuntime( RuntimeCreationArguments args ) => new( args.Configuration, @@ -440,107 +271,262 @@ public sealed class MyFrameworkRuntimeIntegrationSnapshot : ) ); } +``` + +Pass a factory for that session to the two-parameter builder: + +```csharp +var builder = new AllureRuntimeBuilder< + MyFrameworkConfiguration, + MyFrameworkRuntime +>( + "My Test Framework", + () => new MyFrameworkRuntimeRegistrationSession() +); +var plan = builder.Prepare(_ => { }); +using var registration = plan.Build(); + +MyFrameworkRuntime runtime = registration.Runtime; + +if (runtime.OutputCapture.Enabled) +{ + // ... +} +``` + +Framework users can continue to customize standard runtime components through +the branded hook interface from the custom configuration example. + +#### Let users customize runtime services + +The hook interface in the custom configuration example exposes only the +standard runtime registration operations. To let users customize +integration-specific runtime services, replace it with a branded registration +context and hook pair, then expose the service factory through the context: + +```csharp +using System; +using Allure.Sdk.Registration; +using Allure.Sdk.Registration.Hooks; + +public interface IMyFrameworkRuntimeRegistrationContext : + IAllureRuntimeRegistrationContext +{ + void UseOutputCapture( + Func factory + ); +} +public interface IMyFrameworkRuntimeRegistrationHook : + IAllureRegistrationHook; +``` + +Implement the context on a session derived from the three-parameter session +class: + +```csharp sealed class MyFrameworkRuntimeRegistrationSession : AllureRuntimeRegistrationSession< MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkRuntimeEndpointRegistrationContext, - IMyFrameworkRuntimeEndpointRegistrationHook, - IAllureRuntimeIntegrationContext< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkRuntimeEndpointRegistrationContext, - IMyFrameworkRuntimeEndpointRegistrationHook, - MyFrameworkRuntime - >, - MyFrameworkRuntimeIntegrationSnapshot, - MyFrameworkRuntime + MyFrameworkRuntime, + IMyFrameworkRuntimeRegistrationContext >, IMyFrameworkRuntimeRegistrationContext { - protected override IAllureRuntimeIntegrationContext< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkRuntimeEndpointRegistrationContext, - IMyFrameworkRuntimeEndpointRegistrationHook, - MyFrameworkRuntime - > IntegrationContext => this; + Func + outputCaptureFactory = + configuration => new( + configuration.CaptureFrameworkOutput + ); + + public void UseOutputCapture( + Func factory + ) => + this.Modify(() => this.outputCaptureFactory = factory); protected override IMyFrameworkRuntimeRegistrationContext RegistrationContext => this; - protected override MyFrameworkRuntimeIntegrationSnapshot - CaptureIntegrationSnapshot() => new(); + protected override MyFrameworkRuntime CreateRuntime( + RuntimeCreationArguments args + ) => new( + args.Configuration, + args.ParameterSerializer, + args.Destination, + args.Context, + args.LifecycleApi, + args.ModelApi, + this.outputCaptureFactory(args.Configuration) + ); } +``` + +`Modify` ensures that the factory can change only while registration is active. +In this design, users change it through registration hooks. + +Pass the corresponding three-parameter `IAllureRuntimeIntegrationContext` and +the session factory to the builder: -public sealed class MyFrameworkRuntimeBuilder(string runtimeName) : - AllureRuntimeBuilder< +```csharp +var builder = new AllureRuntimeBuilder< + MyFrameworkConfiguration, + MyFrameworkRuntime, + IAllureRuntimeIntegrationContext< MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkRuntimeEndpointRegistrationContext, - IMyFrameworkRuntimeEndpointRegistrationHook, - IAllureRuntimeIntegrationContext< - MyFrameworkConfiguration, - IMyFrameworkRuntimeRegistrationContext, - IMyFrameworkRuntimeRegistrationHook, - IMyFrameworkRuntimeEndpointRegistrationContext, - IMyFrameworkRuntimeEndpointRegistrationHook, - MyFrameworkRuntime - >, - MyFrameworkRuntimeIntegrationSnapshot, - MyFrameworkRuntime - >( - runtimeName, - () => new MyFrameworkRuntimeRegistrationSession() - ); + MyFrameworkRuntime, + IMyFrameworkRuntimeRegistrationContext + > +>( + "My Test Framework", + () => new MyFrameworkRuntimeRegistrationSession() +); ``` -Within `MyFrameworkRuntimeRouteBuilder`, the inherited `Runtime` property has type -`MyFrameworkRuntime`, so route construction can use integration-specific -runtime services. +The action passed to `Prepare` still receives the standard +`IAllureRuntimeIntegrationContext` shown above. The branded registration +context is passed to registration hooks, where users can configure both +standard and integration-specific services. -The registration exposes the concrete runtime type: +Framework users can now customize both standard runtime components and the +integration-specific service through the branded hook API: ```csharp -var builder = new MyFrameworkRuntimeBuilder("My Test Framework"); -var plan = builder.Prepare(_ => { }); -using var registration = plan.Build(); +public sealed class ProjectAllureRegistration : + IMyFrameworkRuntimeRegistrationHook +{ + public void SetUp( + IMyFrameworkRuntimeRegistrationContext context + ) + { + context.UseOutputCapture( + _ => new FrameworkOutputCapture(enabled: false) + ); + } +} +``` -MyFrameworkRuntime runtime = registration.Runtime; +#### Build a reusable integration platform -if (runtime.OutputCapture.Enabled) +A reusable platform may need to expose additional customization operations to +framework adapters through `Prepare` while retaining a smaller user-facing API +for registration hooks. In that case, define a branded integration context +that extends the branded registration context: + +```csharp +using System; + +public interface IMyFrameworkRuntimeIntegrationContext : + IAllureRuntimeIntegrationContext< + MyFrameworkConfiguration, + MyFrameworkRuntime, + IMyFrameworkRuntimeRegistrationContext + >, + IMyFrameworkRuntimeRegistrationContext { - // ... + void UseLogger(Action logger); } ``` +Implement the integration context on a session derived from the four-parameter +session class: + +```csharp +sealed class MyFrameworkRuntimeRegistrationSession : + AllureRuntimeRegistrationSession< + MyFrameworkConfiguration, + MyFrameworkRuntime, + IMyFrameworkRuntimeRegistrationContext, + IMyFrameworkRuntimeIntegrationContext + >, + IMyFrameworkRuntimeIntegrationContext +{ + Func + outputCaptureFactory = + configuration => new( + configuration.CaptureFrameworkOutput + ); + + Action logger = _ => { }; + + public void UseOutputCapture( + Func factory + ) => + this.Modify(() => this.outputCaptureFactory = factory); + + public void UseLogger(Action logger) => + this.Modify(() => this.logger = logger); + + protected override IMyFrameworkRuntimeRegistrationContext + RegistrationContext => this; + + protected override IMyFrameworkRuntimeIntegrationContext + IntegrationContext => this; + + protected override MyFrameworkRuntime CreateRuntime( + RuntimeCreationArguments args + ) + { + this.logger("Creating the Allure runtime."); + + return new( + args.Configuration, + args.ParameterSerializer, + args.Destination, + args.Context, + args.LifecycleApi, + args.ModelApi, + this.outputCaptureFactory(args.Configuration) + ); + } +} +``` + +Expose the branded integration context through the builder so each framework +adapter can configure the shared platform during `Prepare`: + +```csharp +var builder = new AllureRuntimeBuilder< + MyFrameworkConfiguration, + MyFrameworkRuntime, + IMyFrameworkRuntimeIntegrationContext +>( + "My Test Framework", + () => new MyFrameworkRuntimeRegistrationSession() +); + +var plan = builder.Prepare(context => +{ + context.UseLogger( + message => Console.WriteLine($"[My Framework] {message}") + ); +}); +``` + +Framework adapters receive `IMyFrameworkRuntimeIntegrationContext` through +`Prepare`. Because that interface extends +`IMyFrameworkRuntimeRegistrationContext`, adapters receive all user-facing +registration operations as well as adapter-specific operations such as +`UseLogger`. Application users receive only +`IMyFrameworkRuntimeRegistrationContext` through registration hooks. + Implementation checklist: -- Reuse or define the custom configuration, runtime registration context, and - runtime registration hook types from scenario 2. +- Define a custom configuration derived from `AllureConfiguration`. - Define the custom runtime derived from `AllureRuntime` and expose its integration-specific services. -- Define endpoint registration context and hook interfaces parameterized with - the custom runtime type. -- Define a route builder derived from `AllureInProcessRouteBuilder<...>` for the - custom runtime. Implement the endpoint registration context interface you've defined earlier. Return `this` from `RegistrationContext`. -- Define an integration snapshot implementing the four-parameter - `IAllureRuntimeIntegrationSnapshot<...>`; construct the custom runtime in - `CreateRuntime` and the route builder in `CreateRouteBuilder`. -- Define a registration session derived from the eight-parameter - `AllureRuntimeRegistrationSession<...>` and implement the runtime registration context interface you've defined earlier; return the session itself from both - context properties and create the snapshot in - `CaptureIntegrationSnapshot`. -- Optionally, define a builder derived from the eight-parameter `AllureRuntimeBuilder<...>` - and pass a factory for the registration session to its base constructor. Alternatively, create an instance of the eight-parameter `AllureRuntimeBuilder<...>` directly where needed. -- At startup, instantiate that builder, call `Prepare` once with the desired - registrations, call `Build` once on the returned plan, and retain the - registration. +- If users need to customize only standard runtime components, derive + `AllureRuntimeRegistrationSession` and use + `AllureRuntimeBuilder`. +- To expose integration-specific service registration, define a branded + registration context and implement it through + `AllureRuntimeRegistrationSession`. + Use `IAllureRuntimeIntegrationContext` + as the third type argument of `AllureRuntimeBuilder`. +- For a reusable integration platform, define a branded integration context and + derive it from the branded registration context. Implement the integration + context through the four-parameter session and expose it as the third type + argument of `AllureRuntimeBuilder`. +- Call `Prepare` and `Build` once, then retain the registration. ## Map the framework lifecycle @@ -569,7 +555,7 @@ var scope = new TestResultScope Name = "CheckoutTests", }; -runtime.LifecycleApi.StartScope(scope); +runtime.LifecycleApi.StartTestScope(scope); var test = new TestResult { @@ -603,15 +589,15 @@ finally var completedTest = runtime.LifecycleApi.StopTest(); runtime.ResultsDestination.WriteTestResult(completedTest); - var completedScope = runtime.LifecycleApi.StopScope(); + var completedScope = runtime.LifecycleApi.StopTestScope(); runtime.ResultsDestination.WriteContainer(completedScope); } ``` -Use `ScheduleTest` before `StartTest` when the -framework reports discovery and execution as separate events. Setup and teardown -fixtures require an active scope. A step requires an active fixture, test, or -parent step. Stop nested items in reverse order. +Use `ScheduleTest` before `StartTest` when the framework reports discovery and +execution as separate events. Setup and teardown fixtures require an active +scope. A step requires an active fixture, test, or parent step. Stop nested +items in reverse order. `ModelApi` updates or reads the active scope, fixture, test, step, or current executable item. It supports concurrent access, so prefer it over retaining @@ -620,11 +606,12 @@ mutable model references across unrelated callbacks. ## Preserve state across framework callbacks The runtime uses `IAllureExecutionContext` to identify the active scope, -fixture, test, and step. The default `AsyncLocalExecutionContext` follows -normal synchronous and asynchronous calls. A framework may, however, deliver -related events on a disconnected execution flow where the original `AsyncLocal` -value is no longer available. In such a case, choose a state storage strategy -that follows the framework's notion of the current execution. +fixture, test, and step. The default `AsyncLocalExecutionContext` propagates +state through normal synchronous and asynchronous call flows. A framework may, +however, deliver related events on a disconnected execution flow where the +original `AsyncLocal` value is no longer available. In such a case, choose a +state storage strategy that follows the framework's notion of the current +execution. ### Use the framework's execution context @@ -642,7 +629,7 @@ using Allure.Sdk.Registration; using Allure.Sdk.Runtime; public sealed class FrameworkAllureExecutionContext( - IReadOnlyLateBoundReference runtimeReference + IReadOnlyLateBoundReference runtimeReference ) : AllureExecutionContext(runtimeReference) { public override AllureExecutionState CurrentState @@ -657,18 +644,14 @@ public sealed class FrameworkAllureExecutionContext( } ``` -Register the adapter while preparing the runtime. The builder's projected +Register the adapter while preparing the runtime. The builder's late-bound runtime reference becomes available after the plan is built: ```csharp var plan = builder.Prepare(context => { - var runtimeReference = builder.RuntimeReference.Select( - runtime => (IAllureRuntime)runtime - ); - context.UseContext(_ => - new FrameworkAllureExecutionContext(runtimeReference) + new FrameworkAllureExecutionContext(builder.RuntimeReference) ); }); @@ -694,8 +677,14 @@ AllureExecutionState state = runtime.ContextApi.CurrentState; await runtime.ContextApi.RunWithStateAsync(state, async activeRuntime => { activeRuntime.LifecycleApi.StartStep(new StepResult { Name = "HTTP request" }); - await SendRequestAsync(); - activeRuntime.LifecycleApi.StopStep(); + try + { + await SendRequestAsync(); + } + finally + { + activeRuntime.LifecycleApi.StopStep(); + } }); ``` @@ -757,8 +746,9 @@ default; `UseOperations`, endpoint-level `ConfigureSerialization`, and `Allure.Net.Sdk` currently provides registration support only for in-process endpoints. Integrations that communicate with the runtime across a process -boundary must implement `Allure.Abstractions.IAllureRuntimeEndpoint` and `Allure.Abstractions.IAllureRuntimeRoute`, -then install the route with `Allure.Runtime.AllureRuntimeRouter.Install`. +boundary must implement `Allure.Abstractions.IAllureRuntimeEndpoint` and +`Allure.Abstractions.IAllureRuntimeRoute`, then install the route with +`Allure.Runtime.AllureRuntimeRouter.Install`. The integration is responsible for the transport, request routing, serialization, availability checks, and resource cleanup. Keep the @@ -767,7 +757,7 @@ down to remove the route. ## Customize runtime components -The registration context passed to `Prepare` lets integrations replace +The integration context passed to `Prepare` lets integrations replace individual runtime components: - `UseDestination` for a custom `IAllureResultsDestination`. The package also