feat: add inital in memory dispatcher

Add a simple in memory dispatcher for scalar requests and stream request.
This commit is contained in:
Louis Seubert 2026-05-08 20:26:26 +02:00
commit 1218d3617a
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
145 changed files with 6388 additions and 0 deletions

View file

@ -0,0 +1,19 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class AmbiguousScalarHandler : IScalarRequestHandler<AmbiguousScalarRequest, string>
{
// Public method with the same name and signature
public Task<string> HandleAsync(AmbiguousScalarRequest request, CancellationToken ct)
{
return Task.FromResult("Public-Handled");
}
// Explicit interface implementation
Task<string> IScalarRequestHandler<AmbiguousScalarRequest, string>.HandleAsync(AmbiguousScalarRequest request, CancellationToken ct)
{
return Task.FromResult("Interface-Handled");
}
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class AmbiguousScalarRequest : IScalarRequest<string>
{
}

View file

@ -0,0 +1,19 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class AmbiguousStreamHandler : IStreamRequestHandler<AmbiguousStreamRequest, string>
{
// Public method with the same name and signature
public async IAsyncEnumerable<string> HandleAsync(AmbiguousStreamRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return "Public-Handled";
}
// Explicit interface implementation
async IAsyncEnumerable<string> IStreamRequestHandler<AmbiguousStreamRequest, string>.HandleAsync(AmbiguousStreamRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return "Interface-Handled";
}
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class AmbiguousStreamRequest : IStreamRequest<string>
{
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class AnotherNamedScalarRequest : INamedScalarRequest
{
public string Name { get; set; } = string.Empty;
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class AnotherNamedStreamRequest : INamedStreamRequest
{
public string Name { get; set; } = string.Empty;
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
internal sealed class AnotherTestHandler : IScalarRequestHandler<AnotherTestRequest, string>
{
public Task<string> HandleAsync(AnotherTestRequest request, CancellationToken ct)
{
return Task.FromResult("ok");
}
}

View file

@ -0,0 +1,6 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
internal sealed class AnotherTestRequest : IScalarRequest<string> { }

View file

@ -0,0 +1,10 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public abstract class BaseScalarHandler<TRequest> : IScalarRequestHandler<TRequest, string>
where TRequest : IScalarRequest<string>
{
public abstract Task<string> HandleAsync(TRequest request, CancellationToken cancellationToken);
}

View file

@ -0,0 +1,10 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public abstract class BaseStreamHandler<TRequest> : IStreamRequestHandler<TRequest, string>
where TRequest : IStreamRequest<string>
{
public abstract IAsyncEnumerable<string> HandleAsync(TRequest request, CancellationToken cancellationToken);
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ConstrainedScalarHandler<TRequest> : IScalarRequestHandler<TRequest, string>
where TRequest : ConstrainedScalarRequest
{
public Task<string> HandleAsync(TRequest request, CancellationToken cancellationToken)
{
return Task.FromResult($"{request.Value}-Constrained");
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ConstrainedScalarRequest : IScalarRequest<string>
{
public int Value { get; set; }
}

View file

@ -0,0 +1,14 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ConstrainedStreamHandler<TRequest> : IStreamRequestHandler<TRequest, string>
where TRequest : ConstrainedStreamRequest
{
public async IAsyncEnumerable<string> HandleAsync(TRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return $"{request.Value}-Constrained-0";
yield return $"{request.Value}-Constrained-1";
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ConstrainedStreamRequest : IStreamRequest<string>
{
public int Value { get; set; }
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class DeepDerivedScalarRequest : InheritedScalarRequest
{
public int DeepValue { get; set; }
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class DeepDerivedStreamRequest : InheritedStreamRequest
{
public int DeepValue { get; set; }
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class DerivedScalarHandler : BaseScalarHandler<DerivedScalarRequest>
{
public override Task<string> HandleAsync(DerivedScalarRequest request, CancellationToken cancellationToken)
{
return Task.FromResult($"Derived: {request.Value}");
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class DerivedScalarRequest : IScalarRequest<string>
{
public int Value { get; set; }
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class DerivedStreamHandler : BaseStreamHandler<DerivedStreamRequest>
{
public override async IAsyncEnumerable<string> HandleAsync(DerivedStreamRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return $"Derived: {request.Value}-0";
yield return $"Derived: {request.Value}-1";
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class DerivedStreamRequest : IStreamRequest<string>
{
public int Value { get; set; }
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ExplicitGenericScalarHandler<T> : IScalarRequestHandler<ExplicitGenericScalarRequest, string>
{
Task<string> IScalarRequestHandler<ExplicitGenericScalarRequest, string>.HandleAsync(ExplicitGenericScalarRequest request, CancellationToken ct)
{
return Task.FromResult($"{request.Value}-ExplicitHandled");
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ExplicitGenericScalarRequest : IScalarRequest<string>
{
public string Value { get; set; } = string.Empty;
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ExplicitGenericStreamHandler<T> : IStreamRequestHandler<ExplicitGenericStreamRequest, string>
{
async IAsyncEnumerable<string> IStreamRequestHandler<ExplicitGenericStreamRequest, string>.HandleAsync(ExplicitGenericStreamRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct)
{
yield return $"{request.Value}-ExplicitHandled";
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ExplicitGenericStreamRequest : IStreamRequest<string>
{
public string Value { get; set; } = string.Empty;
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class FailingScalarHandler : IScalarRequestHandler<FailingScalarRequest, string>
{
public Task<string> HandleAsync(FailingScalarRequest request, CancellationToken cancellationToken)
{
throw new InvalidOperationException("Handler failed");
}
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class FailingScalarRequest : IScalarRequest<string>
{
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class FailingStreamHandler : IStreamRequestHandler<FailingStreamRequest, string>
{
public async IAsyncEnumerable<string> HandleAsync(FailingStreamRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return "Wait for it...";
throw new InvalidOperationException("Handler failed");
}
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class FailingStreamRequest : IStreamRequest<string>
{
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public interface INamedScalarRequest : IScalarRequest<string>
{
string Name { get; }
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public interface INamedStreamRequest : IStreamRequest<string>
{
string Name { get; }
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class InheritedScalarRequest : OpenScalarRequest
{
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class InheritedStreamRequest : OpenStreamRequest
{
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class InterfaceConstrainedScalarHandler<TRequest> : IScalarRequestHandler<TRequest, string>
where TRequest : INamedScalarRequest
{
public Task<string> HandleAsync(TRequest request, CancellationToken cancellationToken)
{
return Task.FromResult($"{request.Name}-ConstrainedByInterface");
}
}

View file

@ -0,0 +1,14 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class InterfaceConstrainedStreamHandler<TRequest> : IStreamRequestHandler<TRequest, string>
where TRequest : INamedStreamRequest
{
public async IAsyncEnumerable<string> HandleAsync(TRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return $"{request.Name}-ConstrainedByInterface-0";
yield return $"{request.Name}-ConstrainedByInterface-1";
}
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class InterfaceInheritedScalarHandler : IScalarRequestHandler<InterfaceInheritedScalarRequest, string>
{
public Task<string> HandleAsync(InterfaceInheritedScalarRequest request, CancellationToken cancellationToken)
{
return Task.FromResult($"{request.Name}-InterfaceHandled");
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class InterfaceInheritedScalarRequest : INamedScalarRequest
{
public string Name { get; set; } = string.Empty;
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class InterfaceInheritedStreamHandler : IStreamRequestHandler<InterfaceInheritedStreamRequest, string>
{
public async IAsyncEnumerable<string> HandleAsync(InterfaceInheritedStreamRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return $"{request.Name}-InterfaceHandled-0";
yield return $"{request.Name}-InterfaceHandled-1";
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class InterfaceInheritedStreamRequest : INamedStreamRequest
{
public string Name { get; set; } = string.Empty;
}

View file

@ -0,0 +1,17 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class MultiInterfaceScalarHandler : IScalarRequestHandler<MultiInterfaceScalarRequest, int>, IScalarRequestHandler<MultiInterfaceScalarRequest, string>
{
public Task<int> HandleAsync(MultiInterfaceScalarRequest request, CancellationToken cancellationToken)
{
return Task.FromResult(1);
}
Task<string> IScalarRequestHandler<MultiInterfaceScalarRequest, string>.HandleAsync(MultiInterfaceScalarRequest request, CancellationToken ct)
{
return Task.FromResult("One");
}
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class MultiInterfaceScalarRequest : IScalarRequest<int>, IScalarRequest<string>
{
}

View file

@ -0,0 +1,19 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class MultiInterfaceStreamHandler : IStreamRequestHandler<MultiInterfaceStreamRequest, int>, IStreamRequestHandler<MultiInterfaceStreamRequest, string>
{
public async IAsyncEnumerable<int> HandleAsync(MultiInterfaceStreamRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return 1;
yield return 2;
}
async IAsyncEnumerable<string> IStreamRequestHandler<MultiInterfaceStreamRequest, string>.HandleAsync(MultiInterfaceStreamRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken ct)
{
yield return "One";
yield return "Two";
}
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class MultiInterfaceStreamRequest : IStreamRequest<int>, IStreamRequest<string>
{
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class OpenScalarHandler<TRequest> : IScalarRequestHandler<TRequest, string>
where TRequest : OpenScalarRequest
{
public Task<string> HandleAsync(TRequest request, CancellationToken cancellationToken)
{
return Task.FromResult($"{request.Data}-Handled");
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class OpenScalarRequest : IScalarRequest<string>
{
public string Data { get; set; } = string.Empty;
}

View file

@ -0,0 +1,14 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class OpenStreamHandler<TRequest> : IStreamRequestHandler<TRequest, string>
where TRequest : OpenStreamRequest
{
public async IAsyncEnumerable<string> HandleAsync(TRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return $"{request.Data}-Stream-0";
yield return $"{request.Data}-Stream-1";
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class OpenStreamRequest : IStreamRequest<string>
{
public string Data { get; set; } = string.Empty;
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarChainedBehaviour1(ScalarTestTracker tracker) : IScalarRequestBehavior<ScalarTestRequest, string>
{
public async Task<string> HandleAsync(ScalarTestRequest request, ScalarHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Log.Add("Behaviour1");
return await next(request, cancellationToken);
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarChainedBehaviour2(ScalarTestTracker tracker) : IScalarRequestBehavior<ScalarTestRequest, string>
{
public async Task<string> HandleAsync(ScalarTestRequest request, ScalarHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Log.Add("Behaviour2");
return await next(request, cancellationToken);
}
}

View file

@ -0,0 +1,14 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarOpenBehavior<TRequest, TResponse>(ScalarTestTracker tracker) : IScalarRequestBehavior<TRequest, TResponse>
where TRequest : IScalarRequest<TResponse>
{
public async Task<TResponse> HandleAsync(TRequest request, ScalarHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
tracker.Executed = true;
return await next(request, cancellationToken);
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarOrderingClosedBehavior(ScalarTestTracker tracker) : IScalarRequestBehavior<ScalarTestRequest, string>
{
public Task<string> HandleAsync(ScalarTestRequest request, ScalarHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Log.Add("OrderingClosed");
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,14 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarOrderingOpenBehavior<TRequest, TOutput>(ScalarTestTracker tracker) : IScalarRequestBehavior<TRequest, TOutput>
where TRequest : IScalarRequest<TOutput>
{
public Task<TOutput> HandleAsync(TRequest request, ScalarHandlerDelegate<TOutput> next, CancellationToken cancellationToken)
{
tracker.Log.Add("OrderingOpen");
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarTestBehavior(ScalarTestTracker tracker) : IScalarRequestBehavior<ScalarTestRequest, string>
{
public async Task<string> HandleAsync(ScalarTestRequest request, ScalarHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Executed = true;
return await next(request, cancellationToken);
}
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarTestHandler : IScalarRequestHandler<ScalarTestRequest, string>
{
public Task<string> HandleAsync(ScalarTestRequest request, CancellationToken cancellationToken)
{
return Task.FromResult($"{request.Value}-Handled");
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarTestRequest : IScalarRequest<string>
{
public string Value { get; set; } = string.Empty;
}

View file

@ -0,0 +1,10 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarTestTracker
{
public List<string> Log { get; } = [];
public bool Executed { get; set; }
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarTestWrapperHandler<T> : IScalarRequestHandler<ScalarTestWrapperRequest<T>, string>
{
public Task<string> HandleAsync(ScalarTestWrapperRequest<T> request, CancellationToken cancellationToken)
{
return Task.FromResult($"Handled-{request.Item}");
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarTestWrapperRequest<T> : IScalarRequest<string>
{
public T Item { get; set; } = default!;
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class ScalarWrapperBehavior<T>(ScalarTestTracker tracker) : IScalarRequestBehavior<ScalarTestWrapperRequest<T>, string>
{
public async Task<string> HandleAsync(ScalarTestWrapperRequest<T> request, ScalarHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Executed = true;
return await next(request, cancellationToken);
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamChainedBehaviour1(StreamTestTracker tracker) : IStreamRequestBehavior<StreamTestRequest, string>
{
public IAsyncEnumerable<string> HandleAsync(StreamTestRequest request, StreamHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Log.Add("Behaviour1");
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamChainedBehaviour2(StreamTestTracker tracker) : IStreamRequestBehavior<StreamTestRequest, string>
{
public IAsyncEnumerable<string> HandleAsync(StreamTestRequest request, StreamHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Log.Add("Behaviour2");
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,14 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamOpenBehavior<TRequest, TResponse>(StreamTestTracker tracker) : IStreamRequestBehavior<TRequest, TResponse>
where TRequest : IStreamRequest<TResponse>
{
public IAsyncEnumerable<TResponse> HandleAsync(TRequest request, StreamHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
tracker.Executed = true;
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamOrderingClosedBehavior(StreamTestTracker tracker) : IStreamRequestBehavior<StreamTestRequest, string>
{
public IAsyncEnumerable<string> HandleAsync(StreamTestRequest request, StreamHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Log.Add("Closed");
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,14 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamOrderingOpenBehavior<TRequest, TOutput>(StreamTestTracker tracker) : IStreamRequestBehavior<TRequest, TOutput>
where TRequest : IStreamRequest<TOutput>
{
public IAsyncEnumerable<TOutput> HandleAsync(TRequest request, StreamHandlerDelegate<TOutput> next, CancellationToken cancellationToken)
{
tracker.Log.Add("Open");
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamTestBehavior(StreamTestTracker tracker) : IStreamRequestBehavior<StreamTestRequest, string>
{
public IAsyncEnumerable<string> HandleAsync(StreamTestRequest request, StreamHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Executed = true;
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamTestHandler : IStreamRequestHandler<StreamTestRequest, string>
{
public async IAsyncEnumerable<string> HandleAsync(StreamTestRequest request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return $"{request.Value}-Handled-0";
yield return $"{request.Value}-Handled-1";
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamTestRequest : IStreamRequest<string>
{
public string Value { get; set; } = string.Empty;
}

View file

@ -0,0 +1,10 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamTestTracker
{
public List<string> Log { get; } = [];
public bool Executed { get; set; }
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamTestWrapperHandler<T> : IStreamRequestHandler<StreamTestWrapperRequest<T>, string>
{
public async IAsyncEnumerable<string> HandleAsync(StreamTestWrapperRequest<T> request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return $"Handled-{request.Item}-0";
yield return $"Handled-{request.Item}-1";
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamTestWrapperRequest<T> : IStreamRequest<string>
{
public T? Item { get; set; }
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class StreamWrapperBehavior<T>(StreamTestTracker tracker) : IStreamRequestBehavior<StreamTestWrapperRequest<T>, string>
{
public IAsyncEnumerable<string> HandleAsync(StreamTestWrapperRequest<T> request, StreamHandlerDelegate<string> next, CancellationToken cancellationToken)
{
tracker.Executed = true;
return next(request, cancellationToken);
}
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
internal sealed class TestHandler : IScalarRequestHandler<TestRequest, string>
{
public Task<string> HandleAsync(TestRequest request, CancellationToken ct)
{
return Task.FromResult("ok");
}
}

View file

@ -0,0 +1,6 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
internal sealed class TestRequest : IScalarRequest<string> { }

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class UnhandledScalarRequest : IScalarRequest<string>
{
}

View file

@ -0,0 +1,8 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class UnhandledStreamRequest : IStreamRequest<string>
{
}

View file

@ -0,0 +1,12 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class WrapperScalarHandler<T> : IScalarRequestHandler<WrapperScalarRequest<T>, string>
{
public Task<string> HandleAsync(WrapperScalarRequest<T> request, CancellationToken cancellationToken)
{
return Task.FromResult($"Handled-{request.Item}");
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class WrapperScalarRequest<T> : IScalarRequest<string>
{
public T Item { get; set; } = default!;
}

View file

@ -0,0 +1,13 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class WrapperStreamHandler<T> : IStreamRequestHandler<WrapperStreamRequest<T>, string>
{
public async IAsyncEnumerable<string> HandleAsync(WrapperStreamRequest<T> request, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
yield return $"Handled-{request.Item}-0";
yield return $"Handled-{request.Item}-1";
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
namespace Geekeey.Request.Tests;
public class WrapperStreamRequest<T> : IStreamRequest<string>
{
public T Item { get; set; } = default!;
}