namespace StellaOps.Plugin.Testing; using StellaOps.Plugin.Abstractions.Context; /// /// Test implementation of IPluginContext. /// public sealed class TestPluginContext : IPluginContext { /// /// Gets the test configuration. /// public TestPluginConfiguration Configuration { get; } /// /// Gets the test logger. /// public TestPluginLogger Logger { get; } /// /// Gets the test services. /// public TestPluginServices Services { get; } /// public Guid? TenantId { get; set; } /// public Guid InstanceId { get; } /// public CancellationToken ShutdownToken { get; } /// public TimeProvider TimeProvider { get; } /// /// Gets the GUID generator for deterministic testing. /// public SequentialGuidGenerator GuidGenerator { get; } /// /// Gets the HTTP client factory for test mocking. /// public TestHttpClientFactory HttpClientFactory { get; } IPluginConfiguration IPluginContext.Configuration => Configuration; IPluginLogger IPluginContext.Logger => Logger; IPluginServices IPluginContext.Services => Services; /// /// Creates a new test context. /// /// Test host options. public TestPluginContext(PluginTestHostOptions options) { Configuration = new TestPluginConfiguration(options.Configuration, options.Secrets); Logger = new TestPluginLogger(options.MinLogLevel, options.EnableLogging); Services = new TestPluginServices(); TimeProvider = options.TimeProvider ?? new FakeTimeProvider(options.StartTime ?? DateTimeOffset.UtcNow); GuidGenerator = new SequentialGuidGenerator(); HttpClientFactory = new TestHttpClientFactory(); InstanceId = GuidGenerator.NewGuid(); ShutdownToken = CancellationToken.None; // Register common services Services.Register(HttpClientFactory); Services.Register(TimeProvider); } /// /// Creates a new test context with a custom shutdown token. /// /// Test host options. /// Shutdown cancellation token. public TestPluginContext(PluginTestHostOptions options, CancellationToken shutdownToken) : this(options) { ShutdownToken = shutdownToken; } }