public async Task SerializeAsync_InheritedBinaryFileMessage_RawContentProduced()
        {
            var message = new InheritedBinaryFileMessage
            {
                Content = new MemoryStream(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 })
            };
            var headers = new MessageHeaderCollection();

            var result = await new BinaryFileMessageSerializer()
                         .SerializeAsync(message, headers, MessageSerializationContext.Empty);

            result.Should().BeEquivalentTo(message.Content);
        }
        public async Task SerializeDeserializeAsync_HardcodedType_CorrectlyDeserialized()
        {
            var message = new InheritedBinaryFileMessage
            {
                Content = new MemoryStream(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 })
            };
            var headers = new MessageHeaderCollection();

            var serializer = new BinaryFileMessageSerializer <InheritedBinaryFileMessage>();
            var serialized = await serializer.SerializeAsync(message, headers, MessageSerializationContext.Empty);

            var(deserialized, _) = await serializer
                                   .DeserializeAsync(serialized, headers, MessageSerializationContext.Empty);

            var message2 = deserialized as BinaryFileMessage;

            message2.Should().NotBeNull();
            message2.Should().BeEquivalentTo(message);
        }
        public async Task HandleAsync_InheritedBinaryFileMessage_RawContentProduced()
        {
            var message = new InheritedBinaryFileMessage
            {
                Content = new MemoryStream(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 })
            };
            var envelope = new OutboundEnvelope(message, null, TestProducerEndpoint.GetDefault());

            IOutboundEnvelope?result = null;

            await new BinaryFileHandlerProducerBehavior().HandleAsync(
                new ProducerPipelineContext(
                    envelope,
                    Substitute.For <IProducer>(),
                    Substitute.For <IServiceProvider>()),
                context =>
            {
                result = context.Envelope;
                return(Task.CompletedTask);
            });

            result.Should().NotBeNull();
            result !.RawMessage.Should().BeEquivalentTo(message.Content);
        }