Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<TConfiguration, TRuntime>(
string Id,
Action<
TRuntime,
IAllureInProcessEndpointIntegrationContext<
TConfiguration,
TEndpointRegistrationContext,
TEndpointHook,
TRuntime
>
IAllureInProcessEndpointIntegrationContext<TRuntime>
> Registration
)
where TConfiguration : AllureConfiguration
where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext<TConfiguration, TRuntime>
where TEndpointHook : IAllureInProcessEndpointRegistrationHook<TConfiguration, TEndpointRegistrationContext, TRuntime>
where TRuntime : IAllureRuntime<TConfiguration>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using System;
using System.Collections.Generic;
using System.Linq;
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.Internal.Registration;

internal class AllureInProcessRouteBuilder<TConfiguration, TRuntime> :
IAllureInProcessEndpointIntegrationContext<TRuntime>

where TConfiguration : AllureConfiguration
where TRuntime : IAllureRuntime<TConfiguration>
{
readonly string runtimeName;

readonly string routeId;

Func<TRuntime, IEnumerable<IAllureRegistrationHook<IAllureInProcessEndpointRegistrationContext<TRuntime>>?>> currentHooksFactory =
(_) => [];

Func<TRuntime, bool> availabilityPredicate = (_) => true;

Func<TRuntime, bool> currentScopePredicate = (_) => true;

Func<TRuntime, bool> globalScopePredicate = (_) => true;

Func<TRuntime, IEnumerable<string>> currentSuppressedRouteIdsFactory = (_) => [];

Func<TRuntime, AllureInProcessOperations> currentOperationsFactory = (runtime) =>
new AllureInProcessOperations(
new RuntimeSyncOperations<TConfiguration>(runtime),
new RuntimeAsyncOperations<TConfiguration>(runtime)
);

bool useRuleBasedSerializer = false;

Func<TRuntime, IAllureParameterSerializer> currentSerializerFactory;

readonly List<Action<TRuntime, IParameterSerializationRulesContext>> currentRuleBasedSerializerRegistrations;

readonly Action<TRuntime, IAllureInProcessEndpointIntegrationContext<TRuntime>> endpointRegistration;

protected TRuntime Runtime { get; }

public AllureInProcessRouteBuilder(
string runtimeName,
string routeId,
TRuntime runtime,
bool useRuleBasedSerializer,
IEnumerable<Action<TConfiguration, IParameterSerializationRulesContext>> ruleBasedSerializerRegistrations,
Action<TRuntime, IAllureInProcessEndpointIntegrationContext<TRuntime>> endpointRegistration
)
{
this.useRuleBasedSerializer = useRuleBasedSerializer;
this.runtimeName = runtimeName;
this.routeId = routeId;
this.Runtime = runtime;
this.currentRuleBasedSerializerRegistrations = [
.. ruleBasedSerializerRegistrations
.Select((registration) =>
(Action<TRuntime, IParameterSerializationRulesContext>)(
(runtime, context) => registration(runtime.Configuration, context)
)
)
];
this.currentSerializerFactory =
useRuleBasedSerializer
? (runtime) =>
AllureRegistrationDefaults.EndpointParameterSerializer(
this.currentRuleBasedSerializerRegistrations
)(runtime)
: (_) => this.Runtime.ParameterSerializer;
this.endpointRegistration = endpointRegistration;
}

public void UseRegistrationHooks(
Func<TRuntime, IEnumerable<IAllureRegistrationHook<IAllureInProcessEndpointRegistrationContext<TRuntime>>?>> hooksFactory
)
{
this.currentHooksFactory = hooksFactory;
}

public void SetAvailabilityPredicate(Func<TRuntime, bool> isAvailable)
{
this.availabilityPredicate = isAvailable;
}

public void SetAvailabilityPredicate(Func<bool> isAvailable)
{
this.availabilityPredicate = (_) => isAvailable();
}

public void SuppressRoutes(Func<TRuntime, IEnumerable<string>> suppressedRouteIdsFactory)
{
this.currentSuppressedRouteIdsFactory = suppressedRouteIdsFactory;
}

public void SuppressRoutes(Func<IEnumerable<string>> suppressedRouteIdsFactory)
{
this.currentSuppressedRouteIdsFactory = (_) => suppressedRouteIdsFactory();
}

public void UseCurrentScopePredicate(Func<TRuntime, bool> predicate)
{
this.currentScopePredicate = predicate;
}

public void UseGlobalScopePredicate(Func<TRuntime, bool> predicate)
{
this.globalScopePredicate = predicate;
}

public void UseOperations(Func<TRuntime, AllureInProcessOperations> operationsFactory)
{
this.currentOperationsFactory = operationsFactory;
}

public void UseParameterSerializer(Func<TRuntime, IAllureParameterSerializer> serializerFactory)
{
this.useRuleBasedSerializer = false;
this.currentRuleBasedSerializerRegistrations.Clear();
this.currentSerializerFactory = serializerFactory;
}

public void UseParameterSerializer(Func<IAllureParameterSerializer> serializerFactory) =>
this.UseParameterSerializer((_) => serializerFactory());

public void ConfigureSerialization(Action<TRuntime, IParameterSerializationRulesContext> registration)
{
if (!this.useRuleBasedSerializer)
{
this.currentSerializerFactory = (runtime) => AllureRegistrationDefaults.EndpointParameterSerializer(
currentRuleBasedSerializerRegistrations
)(runtime);
this.useRuleBasedSerializer = true;
}

this.currentRuleBasedSerializerRegistrations.Add(registration);
}

public void ConfigureSerialization(Action<IParameterSerializationRulesContext> registration)
{
this.ConfigureSerialization((_, ctx) => registration(ctx));
}

public IAllureRuntimeRoute Build()
{
this.endpointRegistration(this.Runtime, this);
this.RunHooks();
return new AllureRuntimeRoute(
routeId,
() => this.currentScopePredicate(this.Runtime),
() => this.globalScopePredicate(this.Runtime),
[.. this.currentSuppressedRouteIdsFactory(this.Runtime)],
new AllureInProcessRuntimeEndpoint(
this.runtimeName,
() => this.availabilityPredicate(this.Runtime),
this.currentOperationsFactory(this.Runtime),
this.currentSerializerFactory(this.Runtime)
)
);
}

void RunHooks()
{
foreach (var hook in this.currentHooksFactory(this.Runtime))
{
hook?.SetUp(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sealed class AllureRuntimeRegistration<TRuntime>(
IDisposable? routeRegistration
) :
IAllureRuntimeRegistration<TRuntime>
where TRuntime : IAllureRuntime
where TRuntime : IAllureRuntimeBase
{
int disposed = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,20 @@
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<TConfiguration, TRuntime>(
Func<RuntimeServiceCreationContext<TConfiguration>, IAllureExecutionContext> ContextFactory,
Func<RuntimeServiceCreationContext<TConfiguration>, IAllureLifecycleApi> LifecycleApiFactory,
Func<RuntimeServiceCreationContext<TConfiguration>, IAllureModelApi> ModelApiFactory,
bool UseRuleBasedSerializer,
Func<TConfiguration, IAllureParameterSerializer> SerializerFactory,
Func<TConfiguration, IAllureResultsDestination> DestinationFactory,
ImmutableArray<Action<TConfiguration, IParameterSerializationRulesContext>> RuleBasedSerializerRegistrations,
AllureInProcessEndpointRegistration<TConfiguration, TEndpointRegistrationContext, TEndpointHook, TRuntime>? EndpointRegistration
AllureInProcessEndpointRegistration<TConfiguration, TRuntime>? EndpointRegistration
)
where TConfiguration : AllureConfiguration
where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext<TConfiguration, TRuntime>
where TEndpointHook : IAllureInProcessEndpointRegistrationHook<TConfiguration, TEndpointRegistrationContext, TRuntime>
where TRuntime : IAllureRuntime<TConfiguration>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Allure.Sdk.Internal.Registration;

internal interface IPreparedRuntimeRegistration<TConfiguration, TRuntime>
internal interface IPreparedRuntimeRegistration<out TConfiguration, out TRuntime>
where TConfiguration : AllureConfiguration
where TRuntime : IAllureRuntime<TConfiguration>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,27 @@
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;

internal class PreparedRuntimeRegistration<
TConfiguration,
TEndpointRegistrationContext,
TEndpointHook,
TRuntime,
TIntegrationSnapshot
>(
internal class PreparedRuntimeRegistration<TConfiguration, TRuntime>(
string runtimeName,
TConfiguration configuration,
AllureRuntimeRegistrationSnapshot<
TConfiguration,
TEndpointRegistrationContext,
TEndpointHook,
TRuntime
> commonSnapshot,
TIntegrationSnapshot integrationSnapshot
AllureRuntimeRegistrationSnapshot<TConfiguration, TRuntime> registrationSnapshot,
Func<RuntimeCreationArguments<TConfiguration>, TRuntime> runtimeFactory
) :
IPreparedRuntimeRegistration<TConfiguration, TRuntime>

where TConfiguration : AllureConfiguration
where TEndpointRegistrationContext : IAllureInProcessEndpointRegistrationContext<
TConfiguration,
TRuntime
>
where TEndpointHook : IAllureInProcessEndpointRegistrationHook<
TConfiguration,
TEndpointRegistrationContext,
TRuntime
>
where TIntegrationSnapshot : IAllureRuntimeIntegrationSnapshot<
TConfiguration,
TEndpointRegistrationContext,
TEndpointHook,
TRuntime
>
where TRuntime : IAllureRuntime<TConfiguration>
{
public TConfiguration Configuration => configuration;

public IAllureRuntimeRegistration<TRuntime> 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<IAllureRuntime<TConfiguration>>();
Expand All @@ -61,9 +34,9 @@ public IAllureRuntimeRegistration<TRuntime> 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<TConfiguration> runtimeCreationArguments = new(
Configuration: configuration,
Expand All @@ -74,28 +47,26 @@ public IAllureRuntimeRegistration<TRuntime> Build()
ModelApi: modelApi
);

var runtime = integrationSnapshot.CreateRuntime(runtimeCreationArguments);
var runtime = runtimeFactory(runtimeCreationArguments);

IDisposable? endpointRegistration = null;

try
{
constructionRuntimeReference.Bind(runtime);

if (commonSnapshot.EndpointRegistration is var (routeId, routeRegistration))
if (registrationSnapshot.EndpointRegistration is var (routeId, routeRegistration))
{
AllureRouteBuilderArgs<TConfiguration, TRuntime> endpointBuildArgs = new(
var routeBuilder = new AllureInProcessRouteBuilder<TConfiguration, TRuntime>(
runtimeName,
routeId,
runtime,
commonSnapshot.UseRuleBasedSerializer,
commonSnapshot.RuleBasedSerializerRegistrations
registrationSnapshot.UseRuleBasedSerializer,
registrationSnapshot.RuleBasedSerializerRegistrations,
routeRegistration
);
var endpointRouteBuilder = integrationSnapshot.CreateRouteBuilder(endpointBuildArgs);
var route = routeBuilder.Build();

routeRegistration(runtime, endpointRouteBuilder);

var route = endpointRouteBuilder.Build();
endpointRegistration = AllureRuntimeRouter.Install(route);
}

Expand Down
Loading
Loading