public void OnFlow_CancelsPreviousTask_WhenCalledMultipleTimes()
        {
            ListenerLink   link        = Construct.Uninitialized <ListenerLink>();
            FlowContext    flowContext = Construct.ForPrivate <FlowContext>(link, 1, new Fields());
            IDeliveryQueue queue       = Substitute.For <IDeliveryQueue>();
            var            endpoint    = new OutgoingLinkEndpoint(queue);

            endpoint.OnFlow(flowContext);

            Should.NotThrow(() => endpoint.OnFlow(flowContext));
        }
Beispiel #2
0
        public void Process_DoesNotProcessDeliveryIfItDoesntExist()
        {
            var message = new Message();

            message.InitializePrivateProperty("Delivery");
            ListenerLink   link           = Construct.Uninitialized <ListenerLink>();
            MessageContext messageContext = Construct.ForPrivate <MessageContext>(link, message);
            var            queue          = new DeliveryQueue();

            Should.NotThrow(() => queue.Process(messageContext));
        }
        public void OnMessage_PostsMessageToEntityAndCompletesMessageContext()
        {
            var message = new Message();

            message.InitializePrivateProperty("Delivery");
            ListenerLink   link           = Construct.Uninitialized <ListenerLink>();
            MessageContext messageContext = Construct.ForPrivate <MessageContext>(link, message);
            IEntity        entity         = Substitute.For <IEntity>();
            var            endpoint       = new IncomingLinkEndpoint(entity);

            endpoint.OnMessage(messageContext);

            endpoint.ShouldSatisfyAllConditions(
                () => entity.Received(1).Post(Arg.Is <Message>(m => !ReferenceEquals(m, message))),
                () => messageContext.State.ShouldBe(ContextState.Completed)
                );
        }
Beispiel #4
0
        public void Process_ProcessesDelivery()
        {
            var message = new Message();

            message.InitializePrivateProperty("Delivery");
            ListenerLink   link           = Construct.Uninitialized <ListenerLink>();
            MessageContext messageContext = Construct.ForPrivate <MessageContext>(link, message);
            var            delivery       = new Delivery(message);
            var            queue          = new DeliveryQueue();

            queue.Enqueue(delivery);
            queue.Dequeue(CancellationToken.None);

            queue.Process(messageContext);

            delivery.Processed.ShouldNotBeNull();
        }
        public void OnLinkClosed_CancelsSendingMessages()
        {
            var            backingQueue = new BlockingCollection <Message>(new ConcurrentQueue <Message>());
            ListenerLink   link         = Construct.Uninitialized <ListenerLink>();
            FlowContext    flowContext  = Construct.ForPrivate <FlowContext>(link, 1, new Fields());
            IDeliveryQueue queue        = Substitute.For <IDeliveryQueue>();

            queue.Dequeue(Arg.Any <CancellationToken>())
            .Returns(ci => backingQueue.Take(ci.Arg <CancellationToken>()));
            var endpoint = new OutgoingLinkEndpoint(queue);

            endpoint.OnFlow(flowContext);
            endpoint.OnLinkClosed(null, null);
            backingQueue.Add(new Message());
            Thread.Sleep(10);

            backingQueue.Count.ShouldBe(1);
        }
        public void OnDisposition_CallsIDeliveryQueueProcess()
        {
            var message = new Message();

            message.InitializePrivateProperty("Delivery");
            IDeliveryQueue     queue = Substitute.For <IDeliveryQueue>();
            DispositionContext dispositionContext = Construct.ForPrivate <DispositionContext>(
                Construct.Uninitialized <ListenerLink>(),
                message,
                new Accepted(),
                true
                );
            var endpoint = new OutgoingLinkEndpoint(queue);

            endpoint.OnDisposition(dispositionContext);

            queue.Received(1).Process(dispositionContext);
            dispositionContext.State.ShouldBe(ContextState.Completed);
        }
        public async Task OnFlow_StartsSendingMessagesAsynchronously()
        {
            var            backingQueue = new BlockingCollection <Message>(new ConcurrentQueue <Message>());
            ListenerLink   link         = Construct.Uninitialized <ListenerLink>();
            FlowContext    flowContext  = Construct.ForPrivate <FlowContext>(link, 1, new Fields());
            IDeliveryQueue queue        = Substitute.For <IDeliveryQueue>();

            queue.Dequeue(Arg.Any <CancellationToken>())
            .Returns(ci => backingQueue.Take(ci.Arg <CancellationToken>()));
            var endpoint = new OutgoingLinkEndpoint(queue);

            endpoint.OnFlow(flowContext);
            backingQueue.Add(new Message());

            await Task.Delay(500);

            queue.Received(1).Dequeue(Arg.Any <CancellationToken>());
            backingQueue.ShouldBeEmpty();
        }
        public void OnMessage_DoesNotCompleteMessageContext_WhenPostingFails()
        {
            var message = new Message();

            message.InitializePrivateProperty("Delivery");
            ListenerLink   link           = Construct.Uninitialized <ListenerLink>();
            MessageContext messageContext = Construct.ForPrivate <MessageContext>(link, message);
            IEntity        entity         = Substitute.For <IEntity>();

            entity.When(instance => instance.Post(Arg.Any <Message>()))
            .Do(_ => throw new NotSupportedException());
            var endpoint = new IncomingLinkEndpoint(entity);

            Action action = () => endpoint.OnMessage(messageContext);

            endpoint.ShouldSatisfyAllConditions(
                () => action.ShouldThrow <NotSupportedException>(),
                () => messageContext.State.ShouldBe(ContextState.Active)
                );
        }