コード例 #1
0
        public async Task UnsubscribeAsync()
        {
            // Arrange
            ChannelTypes channelType = ChannelTypes.Presence;
            string       channelName = ChannelNameFactory.CreateUniqueChannelName(channelType: channelType);
            Pusher       pusher      = PusherFactory.GetPusher(channelType: channelType, saveTo: _clients);
            Channel      channel     = await SubscribeAsync(connectBeforeSubscribing : true, pusher : pusher, channelName : channelName).ConfigureAwait(false);

            // Act
            await pusher.UnsubscribeAsync(channelName).ConfigureAwait(false);

            // Assert
            SubscriptionTest.ValidateUnsubscribedChannel(pusher, channel);
        }
コード例 #2
0
        public async Task ConcurrentUnsubscribesShouldBeIdempotentAsync()
        {
            // Arrange
            ChannelTypes channelType = ChannelTypes.Presence;
            string       channelName = ChannelNameFactory.CreateUniqueChannelName(channelType: channelType);
            Pusher       pusher      = PusherFactory.GetPusher(channelType: channelType, saveTo: _clients);
            Channel      channel     = await SubscribeAsync(connectBeforeSubscribing : true, pusher : pusher, channelName : channelName).ConfigureAwait(false);

            // Act
            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 4; i++)
            {
                tasks.Add(Task.Run(() =>
                {
                    return(pusher.UnsubscribeAsync(channelName));
                }));
            }

            Task.WaitAll(tasks.ToArray());

            // Assert
            SubscriptionTest.ValidateUnsubscribedChannel(pusher, channel);
        }