Fix cross access to async events. (#1515)

fix cross access to async events.
This commit is contained in:
Christian
2022-09-16 08:20:42 +02:00
committed by GitHub
parent ae92b0ed33
commit e977546297
3 changed files with 80 additions and 7 deletions
@@ -41,6 +41,33 @@ namespace MQTTnet.Tests.Internal
Assert.AreEqual(0, _testEventAsyncCount);
}
[TestMethod]
public void Has_Handlers()
{
var testClass = new TestClass();
testClass.TestEventAsync += OnTestEventAsync;
Assert.AreEqual(true, testClass.HasTestHandlers);
}
[TestMethod]
public void No_Handlers()
{
var testClass = new TestClass();
Assert.AreEqual(false, testClass.HasTestHandlers);
}
[TestMethod]
public void Remove_Handlers()
{
var testClass = new TestClass();
testClass.TestEventAsync += OnTestEventAsync;
testClass.TestEventAsync -= OnTestEventAsync;
Assert.AreEqual(false, testClass.HasTestHandlers);
}
Task OnTestEventAsync(EventArgs arg)
{
Interlocked.Increment(ref _testEventAsyncCount);
@@ -57,6 +84,8 @@ namespace MQTTnet.Tests.Internal
remove => _testEvent.RemoveHandler(value);
}
public bool HasTestHandlers => _testEvent.HasHandlers;
public Task FireEventAsync(EventArgs eventArgs)
{
return _testEvent.InvokeAsync(eventArgs);