using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
using Xunit;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests;
public class PollGateTests
{
/// Verifies that a rejected renderer dispatch releases the gate and reports the fault.
/// A task that represents the asynchronous operation.
[Fact]
public async Task RejectedRendererDispatch_ReleasesGateAndObservesFault()
{
var gate = new PollGate();
Exception? observed = null;
await gate.RunAsync(() => Task.FromException(new ObjectDisposedException("renderer")), ex => observed = ex);
Assert.IsType(observed);
Assert.True(gate.TryEnter());
}
/// Verifies that a second entry attempt while the gate is held returns false.
[Fact]
public void TryEnter_SecondCallWhileHeld_ReturnsFalse()
{
var gate = new PollGate();
Assert.True(gate.TryEnter());
Assert.False(gate.TryEnter());
gate.Exit();
Assert.True(gate.TryEnter());
}
}