Ejemplo n.º 1
0
        public void ApplyContext(ISendContext <TRequest> context, Uri responseAddress)
        {
            context.SetRequestId(_requestId);
            context.SetSourceAddress(responseAddress);
            context.SendResponseTo(responseAddress);
            context.SendFaultTo(responseAddress);

            _contextActions.Each(x => x(context));
        }
        protected void TestSerialization <T>(T message)
            where T : class
        {
            byte[] data;
            var    serializer = new TSerializer();

            _sourceUri      = new Uri("loopback://localhost/source");
            _responseUri    = new Uri("loopback://localhost/response");
            _faultUri       = new Uri("loopback://localhost/fault");
            _destinationUri = new Uri("loopback://localhost/destination");
            _retryCount     = 69;

            using (var output = new MemoryStream())
            {
                ISendContext <T> context = message.ToSendContext();
                context.SetSourceAddress(_sourceUri);
                context.SendResponseTo(_responseUri);
                context.SendFaultTo(_faultUri);
                context.SetDestinationAddress(_destinationUri);
                context.SetRetryCount(_retryCount);

                serializer.Serialize(output, context);

                data = output.ToArray();
            }

            // Trace.WriteLine(Encoding.UTF8.GetString(data));

            using (MemoryStream input = new MemoryStream(data))
            {
                IReceiveContext context = ReceiveContext.FromBodyStream(input);
                serializer.Deserialize(context);

                IConsumeContext <T> messageContext;
                context.TryGetContext <T>(out messageContext).ShouldBeTrue();

                messageContext.ShouldNotBeNull();
                message.Equals(messageContext.Message).ShouldBeTrue();
                message.ShouldNotBeTheSameAs(messageContext.Message);


                Assert.AreEqual(_retryCount, context.RetryCount);
                Assert.AreEqual(_sourceUri, context.SourceAddress);
                Assert.AreEqual(_responseUri, context.ResponseAddress);
                Assert.AreEqual(_faultUri, context.FaultAddress);
                Assert.AreEqual(_destinationUri, context.DestinationAddress);
                //			Assert.AreEqual(message.GetType().ToMessageName(), CurrentMessage.Headers.MessageType);
            }
        }