예제 #1
0
        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);
        }
예제 #2
0
        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);
        }