public void Create_InboundMessage_MessageReplaced()
        {
            var inboundMessage = new InboundMessage
            {
                Message = 1,
            };

            var newInboundMessage = InboundMessageHelper.CreateNewInboundMessage(2, inboundMessage);

            newInboundMessage.Message.Should().Be(2);
        }
Exemple #2
0
        private IInboundMessage HandleChunkedMessage(IInboundMessage message, IServiceProvider serviceProvider)
        {
            if (!(message.Message is MessageChunk chunk))
            {
                return(message);
            }

            var joinedMessage = serviceProvider.GetRequiredService <ChunkConsumer>().JoinIfComplete(chunk);

            if (joinedMessage == null)
            {
                return(null);
            }

            var deserializedJoinedMessage = message.Endpoint.Serializer.Deserialize(joinedMessage);

            return(InboundMessageHelper.CreateNewInboundMessage(deserializedJoinedMessage, message));
        }
        private static IInboundMessage DeserializeIfNeeded(IInboundMessage message)
        {
            if (message is IInboundBatch batch)
            {
                return(new InboundBatch(
                           batch.Id,
                           batch.Messages.Select(DeserializeIfNeeded),
                           batch.Endpoint));
            }

            if (message.Message is byte[])
            {
                return(InboundMessageHelper.CreateNewInboundMessage(
                           Deserialize(message),
                           message));
            }

            return(message);
        }
        public void Create_InboundMessage_ValuesPreserved()
        {
            var inboundMessage = new InboundMessage
            {
                Message        = 1,
                Endpoint       = TestEndpoint.Default,
                FailedAttempts = 3,
                Offset         = new TestOffset("a", "b"),
                MustUnwrap     = true
            };

            inboundMessage.Headers.Add("h1", "h1");
            inboundMessage.Headers.Add("h2", "h2");

            var newInboundMessage = InboundMessageHelper.CreateNewInboundMessage(2, inboundMessage);

            newInboundMessage.Endpoint.Should().BeEquivalentTo(inboundMessage.Endpoint);
            newInboundMessage.FailedAttempts.Should().Be(inboundMessage.FailedAttempts);
            newInboundMessage.Offset.Should().BeEquivalentTo(inboundMessage.Offset);
            newInboundMessage.MustUnwrap.Should().Be(inboundMessage.MustUnwrap);
            newInboundMessage.Headers.Should().BeEquivalentTo(inboundMessage.Headers);
        }