2023-10-20 11:38:40 +00:00
|
|
|
|
using Elsa.ServiceBus.IntegrationTests.Contracts;
|
2023-10-19 18:00:43 +00:00
|
|
|
|
|
2023-12-18 19:20:39 +00:00
|
|
|
|
namespace Elsa.ServiceBus.IntegrationTests.Helpers;
|
|
|
|
|
|
|
|
|
|
|
|
public class TestResetEventManager : ITestResetEventManager
|
2023-10-19 18:00:43 +00:00
|
|
|
|
{
|
2023-12-18 19:20:39 +00:00
|
|
|
|
public AutoResetEvent WaitHandleTest { get; } = new(false);
|
|
|
|
|
|
private readonly Dictionary<string, AutoResetEvent> _events = new();
|
|
|
|
|
|
|
|
|
|
|
|
public AutoResetEvent Get()
|
2023-10-19 18:00:43 +00:00
|
|
|
|
{
|
2023-12-18 19:20:39 +00:00
|
|
|
|
return WaitHandleTest;
|
|
|
|
|
|
}
|
2023-10-19 18:00:43 +00:00
|
|
|
|
|
2023-12-18 19:20:39 +00:00
|
|
|
|
public AutoResetEvent? Get(string resetEvent)
|
|
|
|
|
|
{
|
|
|
|
|
|
_events.TryGetValue(resetEvent, out var result);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2023-10-19 18:00:43 +00:00
|
|
|
|
|
2023-12-18 19:20:39 +00:00
|
|
|
|
public AutoResetEvent Init(string resetEvent)
|
|
|
|
|
|
{
|
|
|
|
|
|
var autoResetEvent = Get(resetEvent);
|
|
|
|
|
|
if (autoResetEvent != null)
|
|
|
|
|
|
return autoResetEvent;
|
|
|
|
|
|
|
|
|
|
|
|
var newEvent = new AutoResetEvent(false);
|
|
|
|
|
|
_events.Add(resetEvent, newEvent);
|
|
|
|
|
|
return newEvent;
|
|
|
|
|
|
}
|
2023-10-19 18:00:43 +00:00
|
|
|
|
|
2023-12-18 19:20:39 +00:00
|
|
|
|
public void Set(string resetEvent)
|
|
|
|
|
|
{
|
|
|
|
|
|
Get(resetEvent)?.Set();
|
2023-10-19 18:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|