protected override void beforeEach()
        {
            theEnvelope = ObjectMother.Envelope();
            theInvoker  = MockFor <IChainInvoker>();

            theException = new EnvelopeDeserializationException("I failed!");
            theInvoker.Stub(x => x.FindChain(theEnvelope))
            .Throw(theException);
        }
        public void if_the_chain_throws_a_deserialization_continuation()
        {
            var exception = new EnvelopeDeserializationException("I blew up!");

            theInvoker.Expect(x => x.ExecuteChain(theEnvelope, theChain))
            .Throw(exception);

            ClassUnderTest.Handle(theEnvelope)
            .ShouldBeOfType <DeserializationFailureContinuation>()
            .Exception.ShouldBeTheSameAs(exception);
        }
        public void SetUp()
        {
            theException = new EnvelopeDeserializationException("foo");
            theContext   = new TestContinuationContext();

            theEnvelope = ObjectMother.EnvelopeWithSerializationError();


            new DeserializationFailureContinuation(theException)
            .Execute(theEnvelope, theContext);
        }
        public object Deserialize(Envelope envelope)
        {
            var contentType = envelope.ContentType ?? "application/json";

            if (contentType.IsEmpty())
            {
                throw new EnvelopeDeserializationException($"No content type can be determined for {envelope}");
            }

            if (envelope.Data == null || envelope.Data.Length == 0)
            {
                throw new EnvelopeDeserializationException("No data on the Envelope");
            }

            if (envelope.MessageType.IsNotEmpty())
            {
                var reader = ReaderFor(envelope.MessageType);
                if (reader.HasAnyReaders)
                {
                    try
                    {
                        if (reader.TryRead(envelope.ContentType, envelope.Data, out var model))
                        {
                            return(model);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw EnvelopeDeserializationException.ForReadFailure(envelope, ex);
                    }
                }
            }

            var messageType = envelope.MessageType ?? "application/json";

            if (_serializers.ContainsKey(messageType))
            {
                using (var stream = new MemoryStream(envelope.Data))
                {
                    stream.Position = 0;
                    return(_serializers[messageType].Deserialize(stream));
                }
            }

            throw new EnvelopeDeserializationException(
                      $"Unknown content-type '{contentType}' and message-type '{envelope.MessageType}'");
        }
 public DeserializationFailureContinuation(EnvelopeDeserializationException exception)
 {
     _exception = exception;
 }