Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests/Admin/ApiSurfaceFixture.cs
T

45 lines
1.2 KiB
C#

using ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Cluster;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Admin;
/// <summary>
/// Provisions a single inbound API method so the API-key form renders at least one method checkbox
/// (<c>id="method-access-{MethodId}"</c>). Created API keys are deleted per-test; this fixture owns
/// only the method.
/// </summary>
public sealed class ApiSurfaceFixture : IAsyncLifetime
{
public int MethodId { get; private set; }
public string MethodName { get; private set; } = string.Empty;
public bool Available { get; private set; }
public async Task InitializeAsync()
{
Available = await ClusterAvailability.IsAvailableAsync();
if (!Available)
{
return;
}
try
{
MethodName = CliRunner.UniqueName("method");
MethodId = await CliRunner.CreateApiMethodAsync(MethodName);
}
catch
{
await CliRunner.DeleteApiMethodAsync(MethodId);
Available = false;
throw;
}
}
public async Task DisposeAsync()
{
if (Available)
{
await CliRunner.DeleteApiMethodAsync(MethodId);
}
}
}