Exemplo n.º 1
0
        /// <inheritdoc />
        public override Task InvokeAsync(OutgoingMessageContext context, Func <Task> next)
        {
            switch (context.Message.GetIntent())
            {
            case MessageIntent.Command:
                CreateCommandEnvelope(
                    context.Message as ICommand,
                    context.Configuration,
                    context.CreateEnvelope);
                break;

            case MessageIntent.Event:
                CreateEventEnvelopes(
                    context.Message as IEvent,
                    context.Configuration,
                    context.CreateEnvelope);
                break;

            case MessageIntent.SubscriptionMessage:
                CreateSubscriptionMessageEnvelope(
                    context.Message as SubscriptionMessage,
                    context.Configuration,
                    context.CreateEnvelope);
                break;

            case MessageIntent.Unknown:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(Task.CompletedTask);
        }
        public void ShouldExposeMessage()
        {
            var message = A.Fake <IMessage>();

            var testee = new OutgoingMessageContext(message, A.Fake <IHavePipelineConfiguration>());

            testee.Message.Should().Be(message);
        }
        public void ShouldExposePipelineConfiguration()
        {
            var pipelineConfiguration = A.Fake <IHavePipelineConfiguration>();

            var testee = new OutgoingMessageContext(A.Fake <IMessage>(), pipelineConfiguration);

            testee.Configuration.Should().Be(pipelineConfiguration);
        }
        public void IsPipelineContext()
        {
            var testee = new OutgoingMessageContext(
                A.Fake <IMessage>(),
                A.Fake <IHavePipelineConfiguration>());

            testee.Should().BeAssignableTo <PipelineContext>();
        }
Exemplo n.º 5
0
        private Task InvokeOutgoingMessageStepsAsync(OutgoingMessageContext context)
        {
            if (!this.outgoingMessageSteps.Any())
            {
                return(Task.CompletedTask);
            }

            var nextStep = this.outgoingMessageSteps.Dequeue();

            return(nextStep.InvokeAsync(context, () => this.InvokeOutgoingMessageStepsAsync(context)));
        }
        public void CanCreateEnvelope()
        {
            var message = A.Fake <IMessage>();
            var pipelineConfiguration = A.Fake <IHavePipelineConfiguration>();

            A.CallTo(() => pipelineConfiguration.LocalEndpointAddress).Returns(new EndpointAddress("sender"));

            var testee = new OutgoingMessageContext(message, pipelineConfiguration);

            testee.CreateEnvelope(new EndpointAddress("recipient"));

            testee.Envelopes.Should().HaveCount(1);
            testee.Envelopes.Should().Contain(e => IsValidEnvelope(e, message));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Invokes the pipeline
        /// </summary>
        /// <param name="message">The message</param>
        public virtual async Task InvokeAsync(IMessage message)
        {
            if (this.configuration.LocalEndpointAddress == null)
            {
                throw new JitneyConfigurationException(ExceptionMessages.LocalEndpointAddressNotDefined);
            }

            var messageContext = new OutgoingMessageContext(message, this.configuration);

            await this.InvokeOutgoingMessageStepsAsync(messageContext).ConfigureAwait(false);

            if (!messageContext.Envelopes.Any())
            {
                return;
            }

            var outgoingEnvelopeTasks = messageContext.Envelopes
                                        .Select(envelope => new OutgoingEnvelopeContext(envelope, this.configuration))
                                        .Select(this.InvokeOutgoingEnvelopeStepsAsync);

            await Task.WhenAll(outgoingEnvelopeTasks).ConfigureAwait(false);
        }
 public override Task InvokeAsync(OutgoingMessageContext context, Func <Task> next)
 {
     context.CreateEnvelope(new EndpointAddress("recipient"));
     this.HasBeenCalled = true;
     return(Task.CompletedTask);
 }