Пример #1
0
        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);
        }
Пример #2
0
        private IConnection CreateConnection(RabbitMQ.Client.IConnection connection,
                                             IModel outboundModel)
        {
            var builder = new ConsumedMessageBuilder(_configuration.SerializationConfiguration,
                                                     _configuration.MessageTypeResolver);
            var outboundChannel = _configuration.OutboundChannelBuilder(outboundModel,
                                                                        _configuration);
            var consumers = _promises.Select(_ =>
            {
                var model = CreateInboundModel(connection,
                                               _configuration.PrefetchSize,
                                               _configuration.PrefetchCount);
                var consumer = _(builder).BuildConsumer(new InboundChannel(model),
                                                        outboundChannel);
                return(new { Model = model, Consumer = consumer });
            })
                            .ToList();

            foreach (var consumer in consumers)
            {
                consumer.Consumer.Declare(consumer.Model);
            }

            return(new Connection(connection,
                                  consumers.Select(_ => _.Consumer),
                                  outboundChannel,
                                  _configuration));
        }
Пример #3
0
        public void MissingContentType()
        {
            const String contentType = "application/null";
            var          serializationConfiguration = new SerializationConfigurationWrapper(NullSerializer.Instance);
            var          resolver = new Mock <IMessageTypeResolver>();
            var          builder  = new ConsumedMessageBuilder(serializationConfiguration, resolver.Object);
            var          message  = builder.Build(new BasicDeliverEventArgs
            {
                BasicProperties = new BasicProperties {
                    ContentType = contentType
                }
            });

            Assert.IsType <UnsupportedMessage>(message);
        }
Пример #4
0
        public void ExceptionOnResolve()
        {
            const String type = "fake-type";
            var          serializationConfiguration = new SerializationConfiguration();
            var          resolver = new Mock <IMessageTypeResolver>();

            resolver.Setup(_ => _.Resolve(It.Is <ConsumedMessageContext>(__ => __.MessageType == type)))
            .Throws <Exception>();
            var builder = new ConsumedMessageBuilder(serializationConfiguration, resolver.Object);
            var message = builder.Build(new BasicDeliverEventArgs
            {
                BasicProperties = new BasicProperties {
                    Type = type
                }
            });

            Assert.IsType <UnresolvedMessage>(message);
        }
Пример #5
0
        public IConnection Connect()
        {
            var connection    = _connectionBuilder.CreateConnection(_configuration.EndpointUri);
            var outboundModel = connection.CreateModel();

            foreach (var exchange in _exchanges)
            {
                exchange.Declare(outboundModel);
            }

            foreach (var queue in _queues)
            {
                queue.Declare(outboundModel);
            }

            foreach (var binding in _bindings)
            {
                binding.Declare(outboundModel);
            }

            var builder = new ConsumedMessageBuilder(_configuration.SerializationConfiguration,
                                                     _configuration.MessageTypeResolver);
            var outboundChannel = _configuration.OutboundChannelBuilder(outboundModel, _configuration);
            var consumers       = _promises.Select(_ =>
            {
                var model = CreateInboundModel(connection,
                                               _configuration.PrefetchSize,
                                               _configuration.PrefetchCount);
                var consumer = _(builder).BuildConsumer(new InboundChannel(model),
                                                        outboundChannel);
                return(new { Model = model, Consumer = consumer });
            })
                                  .ToList();

            foreach (var consumer in consumers)
            {
                consumer.Consumer.Declare(consumer.Model);
            }

            return(new Connection(connection,
                                  consumers.Select(_ => _.Consumer),
                                  outboundChannel,
                                  _configuration));
        }