// Copyright 2012-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0
using NATS.Client.Core;
namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers;
///
/// Helper for creating NATS client connections in integration tests.
/// Wraps NATS.Client.Core connection setup.
///
public sealed class NatsTestClient : IAsyncDisposable
{
private readonly NatsConnection _connection;
private NatsTestClient(NatsConnection connection)
{
_connection = connection;
}
public NatsConnection Connection => _connection;
///
/// Connects to a NATS server at the given URL.
///
public static async Task Connect(string url)
{
var opts = new NatsOpts { Url = url };
var conn = new NatsConnection(opts);
await conn.ConnectAsync();
return new NatsTestClient(conn);
}
///
/// Connects to the local NATS server at its default port (for stub tests).
///
public static async Task ConnectToServer(string serverUrl)
{
return await Connect(serverUrl);
}
public async ValueTask DisposeAsync()
{
await _connection.DisposeAsync();
}
}