예제 #1
0
        public void PublishingSuccessfully()
        {
            const String messageId = "one-id";

            var          message     = NewMessage();
            const UInt64 deliveryTag = 0uL;
            var          model       = new Mock <IModel>();

            model.Setup(_ => _.NextPublishSeqNo).Returns(deliveryTag);
            var configuration = new EnvironmentConfiguration();
            var resolver      = new Mock <IMessageTypeResolver>();

            resolver.Setup(_ => _.Resolve <Foo>())
            .Returns(new MessageBinding(String.Empty,
                                        typeof(Foo).GetTypeInfo()));
            configuration.ResolveMessageTypeBy(resolver.Object);
            configuration.GeneratesMessageIdBy(StubNewId(messageId).Object);
            var channel = new OutboundChannelWrapper(model.Object,
                                                     configuration,
                                                     StubDateTimeProvider().Object,
                                                     null);
            var task = channel.PublishAsync(message,
                                            new Exchange("target_exchange", "direct"),
                                            String.Empty);

            channel.CallOnModelBasicAcks(new BasicAckEventArgs {
                DeliveryTag = deliveryTag
            });
            var result = Assert.IsType <SuccessfulPublishing>(task.Result);

            Assert.Equal(messageId, result.MessageId);
        }
예제 #2
0
        public void InitializationOfAmqpStuff()
        {
            const String queueName    = "queue_name";
            const String exchangeName = "exchange_name";
            const String routingKey   = "routing_key";

            var configuration = new EnvironmentConfiguration();

            configuration.GeneratesMessageIdBy(new Mock <INewId>().Object);
            configuration.ResolveMessageTypeBy(new Mock <IMessageTypeResolver>().Object);

            var model             = new Mock <IModel>();
            var connectionBuilder = StubConnectionBuilder(model);
            var broker            = new BrokerWrapper(connectionBuilder.Object, model.Object, configuration);
            var consumer          = new FakeConsumer(_ => Task.Factory.StartNew(() => { }));
            var queue             = broker.DeclareQueue(queueName);
            var exchange          = broker.DeclareDirectExchange(exchangeName);

            broker.DeclareExchangeBinding(exchange, queue, routingKey);
            broker.SubscribeByAtLeastOnce(queue, _ => { _.Consumes(consumer); });
            broker.Connect();
            model.Verify(_ => _.QueueDeclare(queueName,
                                             false,
                                             false,
                                             false,
                                             It.IsAny <IDictionary <String, Object> >()));
            model.Verify(_ => _.ExchangeDeclare(exchangeName,
                                                "direct",
                                                false,
                                                false,
                                                It.IsAny <IDictionary <String, Object> >()));
            model.Verify(_ => _.QueueBind(queueName,
                                          exchangeName,
                                          routingKey,
                                          It.IsAny <IDictionary <String, Object> >()));
        }