using ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Cluster; namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Admin; /// /// Provisions a single inbound API method so the API-key form renders at least one method checkbox /// (id="method-access-{MethodId}"). Created API keys are deleted per-test; this fixture owns /// only the method. /// public sealed class ApiSurfaceFixture : IAsyncLifetime { /// The id of the provisioned inbound API method. public int MethodId { get; private set; } /// The unique name of the provisioned inbound API method. public string MethodName { get; private set; } = string.Empty; /// Whether the cluster was reachable and the method was provisioned. public bool Available { get; private set; } /// Prepares the test class before the tests run. /// A task that represents the asynchronous operation. public async Task InitializeAsync() { Available = await ClusterAvailability.IsAvailableAsync(); if (!Available) { return; } try { MethodName = CliRunner.UniqueName("method"); MethodId = await CliRunner.CreateApiMethodAsync(MethodName); } catch { // Partial-init guard: MethodId is non-zero only if CreateApiMethodAsync succeeded, // so skip the delete when nothing was created (avoids a phantom delete --id 0). if (MethodId != 0) { await CliRunner.DeleteApiMethodAsync(MethodId); } Available = false; throw; } } /// Releases the resources held by this test class asynchronously. /// A task that represents the asynchronous operation. public async Task DisposeAsync() { if (Available) { await CliRunner.DeleteApiMethodAsync(MethodId); } } }