private static async Task <IRawInboundEnvelope> HandleAsync(IRawInboundEnvelope envelope) { if (envelope.Endpoint.Serializer is BinaryFileMessageSerializer || envelope.Endpoint.Serializer.GetType().IsGenericType&& envelope.Endpoint.Serializer.GetType().GetGenericTypeDefinition() == typeof(BinaryFileMessageSerializer <>)) { return(envelope); } var messageType = SerializationHelper.GetTypeFromHeaders(envelope.Headers, false); if (messageType == null || !typeof(IBinaryFileMessage).IsAssignableFrom(messageType)) { return(envelope); } var(deserializedObject, deserializedType) = await BinaryFileMessageSerializer.Default.DeserializeAsync( envelope.RawMessage, envelope.Headers, MessageSerializationContext.Empty) .ConfigureAwait(false); // Create typed message for easier specific subscription return(SerializationHelper.CreateTypedInboundEnvelope(envelope, deserializedObject, deserializedType)); }
public void CreateTypedInboundEnvelope_EnvelopeReturned() { var endpoint = TestConsumerEndpoint.GetDefault(); var rawEnvelope = new RawInboundEnvelope( Array.Empty <byte>(), new[] { new MessageHeader("one", "1"), new MessageHeader("two", "2") }, endpoint, "test", new TestOffset()); var message = new TestEventOne(); var envelope = SerializationHelper.CreateTypedInboundEnvelope(rawEnvelope, message, typeof(TestEventOne)); envelope.Should().BeOfType <InboundEnvelope <TestEventOne> >(); envelope.As <InboundEnvelope <TestEventOne> >().Message.Should().Be(message); envelope.Headers.Should().ContainSingle(header => header.Name == "one" && header.Value == "1"); envelope.Headers.Should().ContainSingle(header => header.Name == "two" && header.Value == "2"); envelope.Endpoint.Should().Be(endpoint); }