Esempio n. 1
0
        public async Task NotifyFail_can_handle_closed_connections([Frozen] IRabbitMqConfiguration configuration, RabbitMqBusEngine sut, string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, string messageId, Guid correlationId, FirstTestCommand command, ShutdownEventArgs shutdownEventArgs)
        {
            sut.SubscribeToCommand <FirstTestCommand>();

            var sequence = await sut.StartAsync().ConfigureAwait(false);

            var encoding = Encoding.UTF8;

            IBasicProperties properties = new BasicProperties
            {
                MessageId       = messageId,
                ContentEncoding = encoding.WebName,
                Headers         = new Dictionary <string, object>
                {
                    ["Nybus:MessageId"]     = encoding.GetBytes(messageId),
                    ["Nybus:MessageType"]   = encoding.GetBytes(DescriptorName(command.GetType())),
                    ["Nybus:CorrelationId"] = correlationId.ToByteArray()
                }
            };

            var body = configuration.Serializer.SerializeObject(command, encoding);

            var incomingMessages = sequence.DumpInList();

            sut.Consumers.First().Value.HandleBasicDeliver(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);

            Mock.Get(configuration.ConnectionFactory.CreateConnection().CreateModel()).Setup(p => p.BasicNack(It.IsAny <ulong>(), It.IsAny <bool>(), It.IsAny <bool>())).Throws(new AlreadyClosedException(shutdownEventArgs));

            await sut.NotifyFailAsync(incomingMessages.First());

            Mock.Get(configuration.ConnectionFactory.CreateConnection().CreateModel()).Verify(p => p.BasicNack(deliveryTag, It.IsAny <bool>(), It.IsAny <bool>()));
        }