public async Task UnSubscribedActionNotInvoked() { var mediatRCourier = new MediatRCourier(); var receivedMessageCount = 0; void NotificationAction(TestNotification _, CancellationToken __) => ++ receivedMessageCount; mediatRCourier.Subscribe <TestNotification>(NotificationAction); await mediatRCourier.Handle(new TestNotification(), CancellationToken.None).ConfigureAwait(false); mediatRCourier.UnSubscribe <TestNotification>(NotificationAction); await mediatRCourier.Handle(new TestNotification(), CancellationToken.None).ConfigureAwait(false); Assert.True(receivedMessageCount == 1); }
public async Task UnSubscribedAsyncActionNotInvoked() { var mediatRCourier = new MediatRCourier(); var receivedMessageCount = 0; async Task NotificationAction(TestNotification _, CancellationToken cancellationToken) { ++receivedMessageCount; await Task.Delay(TimeSpan.FromMilliseconds(1), cancellationToken).ConfigureAwait(false); } mediatRCourier.Subscribe <TestNotification>(NotificationAction); await mediatRCourier.Handle(new TestNotification(), CancellationToken.None).ConfigureAwait(false); mediatRCourier.UnSubscribe <TestNotification>(NotificationAction); await mediatRCourier.Handle(new TestNotification(), CancellationToken.None).ConfigureAwait(false); Assert.True(receivedMessageCount == 1); }