Path: redb-route/tests/redb.Route.Tests.IbmMq/IbmMqTemporaryModelTests.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.IbmMq/IbmMqTemporaryModelTests.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.IbmMq;
namespace redb.Route.Tests.IbmMq;
///
/// temporaryModel (IBM MQ TEMPMODEL) against a real IBM MQ broker: the dynamic reply queue of a
/// request-reply producer is created from the model queue the option names, on the poll path (MQ classes,
/// AccessQueue on the model) and the listener path (XMS CreateTemporaryQueue) alike.
/// Expects IBM MQ at localhost:1414, QM1, channel DEV.APP.SVRCONN, user app/admin; the developer image grants
/// app DEV.APP.MODEL.QUEUE.
///
[Trait("Category", "Integration")]
[Collection("IbmMqIntegration")]
public sealed class IbmMqTemporaryModelTests
{
private const string Queue = "DEV.QUEUE.2";
private static IbmMqEndpoint CreateEndpoint(string destination, string? extraParams = null)
{
var qs = "host=localhost&port=1414&channel=DEV.APP.SVRCONN&queueManager=QM1&user=app&password=admin";
if (extraParams is not null) qs += $"&{extraParams}";
var uri = EndpointUriParser.Parse($"wmq:{destination}?{qs}");
return (IbmMqEndpoint)new IbmMqComponent().CreateEndpoint(uri);
}
[Theory]
[InlineData("poll")]
[InlineData("listener")]
public async Task Rpc_DynamicReplyQueueFromTheNamedModel_GetsTheReply(string receiveMode)
{
await using var server = await EchoServer.StartAsync();
var epClient = CreateEndpoint(Queue,
$"replyTo=true&timeout=15&receiveMode={receiveMode}&temporaryModel=DEV.APP.MODEL.QUEUE");
var rpc = (IbmMqProducer)epClient.CreateProducer();
await rpc.Start();
try
{
var exchange = new Exchange(new Message("ping"));
await rpc.Process(exchange);
exchange.HasOut.Should().BeTrue("the reply comes back on the queue made from DEV.APP.MODEL.QUEUE");
exchange.Out!.Body?.ToString().Should().Be("ECHO:ping");
}
finally
{
await rpc.Stop();
await epClient.Stop();
}
}
[Theory]
[InlineData("poll")]
[InlineData("listener")]
public async Task Rpc_ModelQueueThatDoesNotExist_Fails(string receiveMode)
{
var epClient = CreateEndpoint(Queue,
$"replyTo=true&timeout=5&receiveMode={receiveMode}&temporaryModel=REDB.NO.SUCH.MODEL");
var rpc = (IbmMqProducer)epClient.CreateProducer();
try
{
var act = async () =>
{
await rpc.Start();
var exchange = new Exchange(new Message("ping"));
await rpc.Process(exchange);
if (exchange.Exception is { } failure)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(failure).Throw();
};
// MQRC_UNKNOWN_OBJECT_NAME (2085): the option reaches the broker, not the old fixed model.
(await act.Should().ThrowAsync()).Which.ToString().Should().Contain("2085");
}
finally
{
await rpc.Stop();
await epClient.Stop();
}
}
/// A poll consumer on that answers every request with ECHO: and its body.
private sealed class EchoServer : IAsyncDisposable
{
private readonly IbmMqEndpoint _endpoint;
private readonly IConsumer _consumer;
private EchoServer(IbmMqEndpoint endpoint, IConsumer consumer)
{
_endpoint = endpoint;
_consumer = consumer;
}
public static async Task StartAsync()
{
var endpoint = CreateEndpoint(Queue, "waitInterval=200");
var processor = Substitute.For();
processor.Process(Arg.Any(), Arg.Any())
.Returns(call =>
{
var ex = call.Arg();
ex.Out = new Message($"ECHO:{ex.In.Body}");
return Task.CompletedTask;
});
var consumer = endpoint.CreateConsumer(processor);
await consumer.Start();
return new EchoServer(endpoint, consumer);
}
public async ValueTask DisposeAsync()
{
await _consumer.Stop();
await _endpoint.Stop();
}
}
}