using System.Diagnostics; using Xunit; namespace VRCAuthProxy.Tests.Helpers { /// /// Collection definition for Redis tests /// [CollectionDefinition("Redis")] public class RedisCollection : ICollectionFixture { // This class has no code, and is never created. Its purpose is simply // to be the place to apply [CollectionDefinition] and all the // ICollectionFixture<> interfaces. } /// /// Redis test fixture that ensures a Redis instance is available for tests /// public class RedisFixture : IDisposable { private Process? _redisProcess; // Kept for future implementation where we might start Redis private bool _disposedValue; public RedisFixture() { // For CI environments, this would start Redis using Docker // For local development, we assume Redis is already running // Check if Redis is available if (!IsRedisRunning()) { // In a real implementation, we could start Redis here if needed Console.WriteLine("Warning: Redis is not running. Redis integration tests will be skipped."); } } /// /// Check if Redis is available on localhost:6379 /// private bool IsRedisRunning() { try { using var client = new System.Net.Sockets.TcpClient(); var result = client.BeginConnect("localhost", 6379, null, null); var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(1)); client.EndConnect(result); return success; } catch { return false; } } protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { // Stop Redis if we started it _redisProcess?.Kill(); _redisProcess?.Dispose(); } _disposedValue = true; } } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } } }