Files
natsnet/dotnet/tests/ZB.MOM.NatsNet.Server.IntegrationTests/Helpers/IntegrationTestBase.cs
Joseph Doherty e0a87ca41f feat(batch50): merge JetStream cluster 1 tests and fix build errors
- Added ShouldSkip() and ServerRuntimeUnavailable to IntegrationTestBase
- Fixed WaitOnPeerCount -> WaitOnClusterReady
- Fixed using -> await using for NatsConnection (IAsyncDisposable)
- Removed duplicate PackageReference entries from csproj
2026-03-01 12:18:40 -05:00

71 lines
2.9 KiB
C#

// Copyright 2012-2026 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Xunit.Abstractions;
namespace ZB.MOM.NatsNet.Server.IntegrationTests;
/// <summary>
/// Abstract base class for all integration tests.
/// Skips the entire test class if the server cannot boot (i.e., the .NET server
/// runtime is not yet complete). Individual test classes inherit from this class.
/// </summary>
[Trait("Category", "Integration")]
public abstract class IntegrationTestBase : IDisposable
{
// =========================================================================
// Constructor — Skip guard
// =========================================================================
/// <summary>
/// Initializes the test base and verifies that the server can boot.
/// If <see cref="Helpers.TestServerHelper.CanBoot()"/> returns false the test
/// is skipped via <c>Xunit.SkippableFact</c>'s <c>Skip.If</c> mechanism.
/// </summary>
protected IntegrationTestBase(ITestOutputHelper output)
{
Output = output;
Skip.If(!Helpers.TestServerHelper.CanBoot(), "Server cannot boot — skipping integration tests.");
}
// =========================================================================
// Protected members
// =========================================================================
/// <summary>xUnit output helper, available to derived test classes.</summary>
protected ITestOutputHelper Output { get; }
/// <summary>
/// Returns true if integration tests should be skipped.
/// Convenience method for use in individual test methods that call
/// <c>Skip.If(ShouldSkip(), "reason")</c>.
/// </summary>
protected static bool ShouldSkip() => !Helpers.TestServerHelper.CanBoot();
/// <summary>
/// Returns true if the server runtime is unavailable.
/// Alias for <see cref="ShouldSkip"/> used by some test batches.
/// </summary>
protected static bool ServerRuntimeUnavailable => !Helpers.TestServerHelper.CanBoot();
// =========================================================================
// IDisposable
// =========================================================================
/// <summary>
/// Override in subclasses to perform per-test cleanup (e.g., shut down servers,
/// delete temp dirs). The base implementation does nothing.
/// </summary>
public virtual void Dispose() { }
}