예제 #1
0
        public async Task Wait_Cancels_WhenAnySubscriptionWaitsCancels()
        {
            var message = new Amqp.Message();

            IDelivery[] subscriptions = Enumerable
                                        .Range(0, 3)
                                        .Select((_, index) =>
            {
                IDelivery subscription = Substitute.For <IDelivery>();
                subscription
                .WaitAsync(Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>())
                .Returns(async call =>
                {
                    TimeSpan delay = index != 1 ? call.ArgAt <TimeSpan>(0) : TimeSpan.FromSeconds(15);
                    CancellationToken cancellationToken = call.ArgAt <CancellationToken>(1);
                    await Task.Delay(delay.Add(TimeSpan.FromMilliseconds(1)), cancellationToken);
                    cancellationToken.ThrowIfCancellationRequested();
                    return(true);
                });
                return(subscription);
            })
                                        .ToArray();
            var         delivery = new TopicDelivery(message, subscriptions);
            var         cts      = new CancellationTokenSource(TimeSpan.FromMilliseconds(10));
            Task <bool> task     = delivery.WaitAsync(TimeSpan.FromMilliseconds(1), cts.Token);

            await task.ShouldCancelOperationAsync();
        }
예제 #2
0
        public void Wait_Throws_WhenObjectDisposed()
        {
            var delivery = new TopicDelivery(new Amqp.Message(), new List <IDelivery>());

            delivery.Dispose();

            Should.ThrowAsync <ObjectDisposedException>(delivery.WaitAsync(TimeSpan.Zero));
        }
예제 #3
0
        public async Task Wait_ReturnsTrue_WhenSubscriptionsEmpty()
        {
            var message       = new Amqp.Message();
            var subscriptions = new IDelivery[0];
            var delivery      = new TopicDelivery(message, subscriptions);

            var result = await delivery.WaitAsync(TimeSpan.FromMilliseconds(1));

            result.ShouldBeTrue();
        }
예제 #4
0
        public async Task Wait_ReturnsFalse_WhenAnySubscriptionWaitsReturnFalseWithinTimeout()
        {
            var message = new Amqp.Message();

            IDelivery[] subscriptions = Enumerable
                                        .Range(0, 3)
                                        .Select((_, index) =>
            {
                IDelivery subscription = Substitute.For <IDelivery>();
                subscription.WaitAsync(Arg.Any <TimeSpan>()).Returns(index != 1);
                return(subscription);
            })
                                        .ToArray();
            var delivery = new TopicDelivery(message, subscriptions);

            var result = await delivery.WaitAsync(TimeSpan.FromMilliseconds(1));

            result.ShouldBeFalse();
        }