Path: redb-route/tests/redb.Route.Tests/Processors/OwnedPropertiesMergeBackTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests/Processors/OwnedPropertiesMergeBackTests.cs
----
using AwesomeAssertions;
using Microsoft.Extensions.DependencyInjection;
using redb.Route.Abstractions;
using redb.Route.Components;
using redb.Route.Core;
using redb.Route.Processors;
namespace redb.Route.Tests.Processors;
///
/// The exchange's own bookkeeping — a cached named DI scope (__redb_scope:*) or a registered resource
/// (__redb_resource:*) — belongs to the exchange that created it. A branch that caches a scope on its clone
/// must not hand that scope to the original through the aggregation merge-back: the clone releases it right after,
/// and the original would keep a disposed scope under the same key (ObjectDisposedException on the next use).
///
public class OwnedPropertiesMergeBackTests
{
private const string ScopeKey = "__redb_scope:audit";
private sealed class TrackingScope : IServiceScope, IAsyncDisposable
{
public int DisposeCount;
public IServiceProvider ServiceProvider => null!;
public void Dispose() => Interlocked.Increment(ref DisposeCount);
public ValueTask DisposeAsync() { Interlocked.Increment(ref DisposeCount); return ValueTask.CompletedTask; }
}
[Fact]
public async Task Multicast_BranchScope_StaysWithTheClone()
{
var scope = new TrackingScope();
var multicast = new MulticastProcessor(parallelProcessing: false, aggregationStrategy: (_, latest) => latest)
.AddTarget(new DelegateProcessor(ex => ex.Properties[ScopeKey] = scope));
var original = new Exchange(new Message("m"));
await multicast.Process(original);
original.Properties.Should().NotContainKey(ScopeKey, "the clone owns the scope it cached and has released it");
scope.DisposeCount.Should().Be(1, "released once, with the clone");
}
[Fact]
public async Task Loop_IterationScope_StaysWithTheIterationCopy()
{
var scope = new TrackingScope();
var loop = new LoopProcessor(new DelegateProcessor(ex => ex.Properties[ScopeKey] = scope), 1, copy: true);
var original = new Exchange(new Message("m"));
await loop.Process(original);
original.Properties.Should().NotContainKey(ScopeKey, "the iteration copy owns the scope it cached and has released it");
scope.DisposeCount.Should().Be(1, "released once, with the iteration copy");
}
[Fact]
public async Task Splitter_PartScope_StaysWithThePart()
{
var scope = new TrackingScope();
var splitter = new SplitterProcessor(
ex => (IEnumerable