public void DeserializeThrows()
        {
            const String type        = "fake-type";
            const String contentType = "application/null";
            var          body        = new Byte[] { };
            var          args        = new BasicDeliverEventArgs
            {
                Body            = body,
                BasicProperties = new BasicProperties
                {
                    ContentType = contentType,
                    Type        = type
                }
            };
            var context     = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
            var runtimeType = typeof(Foo);
            var serializer  = new Mock <ISerializer>();

            serializer.Setup(_ => _.Deserialize(body, runtimeType, new UTF8Encoding(true)))
            .Throws(new Exception("boom"));
            var serializationConfiguration = new SerializationConfigurationWrapper(serializer.Object);
            var resolver = new Mock <IMessageTypeResolver>();

            resolver.Setup(_ => _.Resolve(context)).Returns(new MessageBinding(type, runtimeType));
            var builder = new ConsumedMessageBuilder(serializationConfiguration, resolver.Object);
            var message = builder.Build(args);

            Assert.IsType <CorruptedMessage>(message);
        }
Example #2
0
        public void CannotResolve()
        {
            const String source = "urn:message:no-resolve";
            var          args   = new BasicDeliverEventArgs {
                BasicProperties = new BasicProperties {
                    Type = source
                }
            };
            var context  = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
            var type     = typeof(Foo);
            var resolver = new MessageBindingResolver(type.Assembly);

            Assert.IsType <EmptyMessageBinding>(resolver.Resolve(context));
        }
Example #3
0
        public void Resolve()
        {
            const String source = "urn:message:foo";
            var          args   = new BasicDeliverEventArgs {
                BasicProperties = new BasicProperties {
                    Type = source
                }
            };
            var context  = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
            var type     = typeof(Foo);
            var resolver = new MessageBindingResolver(type.Assembly);
            var binding  = resolver.Resolve(context);

            Assert.Equal(source, binding.RawName);
            Assert.Equal(type, binding.RuntimeType);
        }
Example #4
0
        public void Default()
        {
            const String typeName = "Carrot.Tests.Foo";
            var          args     = new BasicDeliverEventArgs {
                BasicProperties = new BasicProperties {
                    Type = typeName
                }
            };
            var context  = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
            var resolver = new DefaultMessageTypeResolver();
            var binding  = resolver.Resolve(context);

            Assert.Equal(typeName, binding.RawName);
            Assert.Equal(typeof(Foo), binding.RuntimeType);

            var binding2 = resolver.Resolve <Foo>();

            Assert.Equal(typeName, binding2.RawName);
            Assert.Equal(typeof(Foo), binding2.RuntimeType);
        }