Ejemplo n.º 1
0
        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)
                );
        }
Ejemplo n.º 2
0
        private void AttachIncomingLink(AttachContext attachContext, Target target)
        {
            IEntity entity = _entityLookup.Find(target.Address);

            if (entity == null)
            {
                attachContext.Complete(new Error(ErrorCode.NotFound)
                {
                    Description = "Entity not found."
                });
                _logger.LogError($"Could not attach incoming link to non-existing entity '{target.Address}'.");
                return;
            }

            var incomingLinkEndpoint = new IncomingLinkEndpoint(entity);

            attachContext.Complete(incomingLinkEndpoint, 300);
            _logger.LogDebug($"Attached incoming link to entity '{target.Address}'.");
        }
Ejemplo n.º 3
0
        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)
                );
        }
Ejemplo n.º 4
0
        public void OnDisposition_Throws()
        {
            var endpoint = new IncomingLinkEndpoint(Substitute.For <IEntity>());

            Should.Throw <NotSupportedException>(() => endpoint.OnDisposition(null));
        }