public void SetUp()
        {
            mockBuilder = new MockBuilder();

            connection = mockBuilder.Connection;
            advancedBus = mockBuilder.Bus.Advanced;
        }
        public void SetUp()
        {
            eventBus = new EventBus();
            internalConsumers = new List<IInternalConsumer>();

            createConsumerCalled = 0;
            mockBuilder = new MockBuilder();

            queue = new Queue(queueName, false);
            onMessage = (body, properties, info) => Task.Factory.StartNew(() => { });

            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();

            internalConsumerFactory = MockRepository.GenerateStub<IInternalConsumerFactory>();

            internalConsumerFactory.Stub(x => x.CreateConsumer()).WhenCalled(x =>
                {
                    var internalConsumer = MockRepository.GenerateStub<IInternalConsumer>();
                    internalConsumers.Add(internalConsumer);
                    createConsumerCalled++;
                    x.ReturnValue = internalConsumer;
                }).Repeat.Any();

            consumer = new PersistentConsumer(
                queue,
                onMessage,
                persistentConnection,
                internalConsumerFactory,
                eventBus);

            AdditionalSetup();
        }
Пример #3
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            requestMessage = new TestRequestMessage();
            responseMessage = new TestResponseMessage();

            var correlationId = "";

            mockBuilder.NextModel.Stub(x => x.BasicPublish(null, null, false, null, null))
                .IgnoreArguments()
                .WhenCalled(invocation =>
                    {
                        var properties = (IBasicProperties)invocation.Arguments[3];
                        correlationId = properties.CorrelationId;
                    });

            var task = mockBuilder.Bus.RequestAsync<TestRequestMessage, TestResponseMessage>(requestMessage);

            DeliverMessage(correlationId);

            task.Wait();

            responseMessage = task.Result;
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            var queue = new Queue("test_queue", false);

            var are = new AutoResetEvent(false);
            mockBuilder.Bus.Advanced.Consume<ITestMessageInterface>(queue, (message, info) => Task.Factory.StartNew(() =>
                {
                    receivedMessage = message.Body;
                    are.Set();
                }));

            var publishedMessage = new Implementation { Text = "Hello Polymorphs!" };
            var body = new JsonSerializer(new TypeNameSerializer()).MessageToBytes(publishedMessage);
            var properties = new BasicProperties
                {
                    Type = new TypeNameSerializer().Serialize(typeof(Implementation))
                };

            mockBuilder.Consumers[0].HandleBasicDeliver(
                "consumer_tag",
                0,
                false,
                "exchange",
                "routing_key",
                properties,
                body
                );

            are.WaitOne(1000);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            exchange = advancedBus.ExchangeDeclare("my_exchange", ExchangeType.Direct, passive:true);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            var cancellation = mockBuilder.Bus.Respond<MyMessage, MyMessage>(x => new MyMessage());
            cancellation.Dispose();
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var exchange = new Exchange("my_exchange");
            advancedBus.ExchangeDelete(exchange);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var queue = new Topology.Queue("my_queue", false);
            advancedBus.QueueDelete(queue);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
//            mockBuilder = new MockBuilder(x => x.Register<IEasyNetQLogger, ConsoleLogger>());

            var autoSubscriber = new AutoSubscriber(mockBuilder.Bus, "my_app");

            autoSubscriber.Subscribe(GetType().Assembly);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            var queue = new Queue("my_queue", false);

            var cancelSubscription = mockBuilder.Bus.Advanced
                .Consume(queue, (bytes, properties, arg3) => Task.Factory.StartNew(() => { }));

            cancelSubscription.Dispose();
        }
        public void SetUp()
        {
            //mockBuilder = new MockBuilder(x => x.Register<IEasyNetQLogger, ConsoleLogger>());
            mockBuilder = new MockBuilder();

            mockBuilder.Bus.Receive("the_queue", x => x
                .Add<MyMessage>(message => deliveredMyMessage = message)
                .Add<MyOtherMessage>(message => deliveredMyOtherMessage = message));

            DeliverMessage("{ Text: \"Hello World :)\" }", "EasyNetQ.Tests.MyMessage:EasyNetQ.Tests");
            DeliverMessage("{ Text: \"Goodbye Cruel World!\" }", "EasyNetQ.Tests.MyOtherMessage:EasyNetQ.Tests");
            DeliverMessage("{ Text: \"Shoudn't get this\" }", "EasyNetQ.Tests.Unknown:EasyNetQ.Tests");
        }
Пример #12
0
        public void SetUp()
        {
            typeNameSerializer = new TypeNameSerializer();
            var customConventions = new Conventions(typeNameSerializer)
            {
                ExchangeNamingConvention = x => "CustomExchangeNamingConvention",
                QueueNamingConvention = (x, y) => "CustomQueueNamingConvention",
                TopicNamingConvention = x => "CustomTopicNamingConvention"
            };

            mockBuilder = new MockBuilder(x => x.Register<IConventions>(_ => customConventions));
            mockBuilder.Bus.Publish(new TestMessage());
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            requestMessage = new TestRequestMessage();

            mockBuilder.NextModel.Stub(x => x.BasicPublish(null, null, false, false, null, null))
                       .IgnoreArguments()
                       .WhenCalled(invocation =>
                       {
                           var properties = (IBasicProperties)invocation.Arguments[4];
                           _correlationId = properties.CorrelationId;
                       });
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            advancedBus = mockBuilder.Bus.Advanced;
            queue = advancedBus.QueueDeclare(
                "my_queue", 
                passive: false, 
                durable: false, 
                exclusive: true,
                autoDelete: true,
                perQueueTtl: 1000,
                expires: 2000);
        }
Пример #15
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder("host=localhost;timeout=1");

            mockBuilder.NextModel
                .Stub(x => x.ExchangeDeclare(null, null, false, false, null))
                .IgnoreArguments()
                .WhenCalled(x =>
                    {
                        var args = new ShutdownEventArgs(ShutdownInitiator.Peer, 320, 
                            "CONNECTION_FORCED - Closed via management plugin");
                        throw new OperationInterruptedException(args);
                    });
        }
Пример #16
0
        public void SetUp()
        {
            var conventions = new Conventions(new TypeNameSerializer())
                {
                    ConsumerTagConvention = () => consumerTag
                };

            mockBuilder = new MockBuilder(x => x
                .Register<IConventions>(_ => conventions)
                //.Register<IEasyNetQLogger>(_ => new ConsoleLogger())
                );

            mockBuilder.Bus.Subscribe<MyMessage>(subscriptionId, message => { });
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            var queue = new Queue("my_queue", false);

            mockBuilder.Bus.Advanced.Consume(queue, (bytes, properties, arg3) => Task.Factory.StartNew(() => { }));

            var are = new AutoResetEvent(false);
            mockBuilder.EventBus.Subscribe<ConsumerModelDisposedEvent>(x => are.Set());

            mockBuilder.Consumers[0].HandleBasicCancel("consumer_tag");

            are.WaitOne(500);
        }
Пример #18
0
        protected void SetUp()
        {
            ConsumerErrorStrategy = MockRepository.GenerateStub<IConsumerErrorStrategy>();

            IConventions conventions = new Conventions(new TypeNameSerializer())
                {
                    ConsumerTagConvention = () => ConsumerTag
                };
            MockBuilder = new MockBuilder(x => x
                    .Register(_ => conventions)
                    .Register(_ => ConsumerErrorStrategy)
                    //.Register<IEasyNetQLogger>(_ => new ConsoleLogger())
                );

            AdditionalSetUp();
        }
Пример #19
0
        public void SetUp()
        {
            var customConventions = new Conventions
            {
                ExchangeNamingConvention = x => "CustomExchangeNamingConvention",
                QueueNamingConvention = (x, y) => "CustomQueueNamingConvention",
                TopicNamingConvention = x => "CustomTopicNamingConvention"
            };

            mockBuilder = new MockBuilder(x => x.Register<IConventions>(_ => customConventions));

            using (var publishChannel = mockBuilder.Bus.OpenPublishChannel())
            {
                publishChannel.Publish(new TestMessage());
            }
        }
Пример #20
0
        public void SetUp()
        {
            var conventions = new Conventions
            {
                RpcExchangeNamingConvention = () => "rpc_exchange",
                RpcReturnQueueNamingConvention = () => "rpc_return_queue",
                ConsumerTagConvention = () => "the_consumer_tag"
            };

            mockBuilder = new MockBuilder(x => x
                .Register<IEasyNetQLogger>(_ => new ConsoleLogger())
                .Register<IConventions>(_ => conventions)
                );

            AdditionalSetup();
        }
Пример #21
0
        protected void SetUp()
        {
            ConsumerErrorStrategy = MockRepository.GenerateStub<IConsumerErrorStrategy>();
            ConsumerErrorStrategy.Stub(x => x.PostExceptionAckStrategy()).Return(PostExceptionAckStrategy.ShouldAck);

            IConventions conventions = new Conventions
                {
                    ConsumerTagConvention = () => ConsumerTag
                };
            MockBuilder = new MockBuilder(x => x
                    .Register(_ => conventions)
                    .Register(_ => ConsumerErrorStrategy)
                    //.Register<IEasyNetQLogger>(_ => new ConsoleLogger())
                );

            AdditionalSetUp();
        }
Пример #22
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder(x =>
                x.Register<Func<string>>(_ => () => correlationId));

            mockBuilder.NextModel.Stub(x =>
                x.BasicPublish(null, null, false, false, null, null))
                    .IgnoreArguments()
                    .Callback<string, string, bool, bool, IBasicProperties, byte[]>((e, r, m, i, p, b) =>
                    {
                        body = b;
                        properties = p;
                        return true;
                    });

            var message = new MyMessage { Text = "Hiya!" };
            mockBuilder.Bus.Publish(message);
        }
Пример #23
0
        public void SetUp()
        {
            var conventions = new Conventions
            {
                ConsumerTagConvention = () => consumerTag
            };

            mockBuilder = new MockBuilder(x => x
                .Register<IConventions>(_ => conventions)
                //.Register<IEasyNetQLogger>(_ => new ConsoleLogger())
                );

            var autoResetEvent = new AutoResetEvent(false);
            var handlerExecutionContext = (HandlerRunner)mockBuilder.ServiceProvider.Resolve<IHandlerRunner>();
            handlerExecutionContext.SynchronisationAction = () => autoResetEvent.Set();

            mockBuilder.Bus.Subscribe<MyMessage>(subscriptionId, message =>
            {
                deliveredMessage = message;
            });

            const string text = "Hello there, I am the text!";
            originalMessage = new MyMessage { Text = text };

            var body = new JsonSerializer().MessageToBytes(originalMessage);

            // deliver a message
            mockBuilder.Consumers[0].HandleBasicDeliver(
                consumerTag,
                deliveryTag,
                false, // redelivered
                typeName,
                "#",
                new BasicProperties
                {
                    Type = typeName,
                    CorrelationId = correlationId
                },
                body);

            // wait for the subscription thread to handle the message ...
            autoResetEvent.WaitOne(1000);
        }
Пример #24
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder(x =>
                x.Register<ICorrelationIdGenerationStrategy>(_ => new StaticCorrelationIdGenerationStrategy(correlationId)));

            mockBuilder.NextModel.Stub(x =>
                x.BasicPublish(null, null, false, null, null))
                    .IgnoreArguments()
                    .Callback<string, string, bool, IBasicProperties, byte[]>((e, r, m, p, b) =>
                    {
                        body = b;
                        properties = p;
                        return true;
                    });

            var message = new MyMessage { Text = "Hiya!" };
            mockBuilder.Bus.Publish(message);
            WaitForMessageToPublish();
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            var message = new MyImplementation
                {
                    Text = "Hello Polymorphs!",
                    NotInInterface = "Hi"
                };

            mockBuilder.NextModel.Stub(x => x.BasicPublish(null, null, false, false, null, null))
                .IgnoreArguments()
                .WhenCalled(x =>
                    {
                        properties = (IBasicProperties) x.Arguments[4];
                        publishedMessage = (byte[]) x.Arguments[5];
                    });

            mockBuilder.Bus.Publish<IMyMessageInterface>(message);
        }
Пример #26
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder(x =>
                x.Register<Func<string>>(_ => () => correlationId));

            using (var channel = mockBuilder.Bus.OpenPublishChannel())
            {
                mockBuilder.Channels[0].Stub(x =>
                    x.BasicPublish(null, null, null, null))
                        .IgnoreArguments()
                        .Callback<string, string, IBasicProperties, byte[]>((e, r, p, b) =>
                        {
                            body = b;
                            properties = p;
                            return true;
                        });

                var message = new MyMessage { Text = "Hiya!" };
                channel.Publish(message);
            }
        }
Пример #27
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            mockBuilder.NextModel.Stub(x => x.ExchangeDeclare(null, null, false, false, null))
                .IgnoreArguments()
                .WhenCalled(x =>
                    {
                        arguments = x.Arguments[4] as IDictionary;
                    });

            exchange = advancedBus.ExchangeDeclare(
                "my_exchange",
                ExchangeType.Direct,
                false,
                false,
                true,
                true,
                "my.alternate.exchange");
        }
Пример #28
0
        public void SetUp()
        {
            var conventions = new Conventions(new TypeNameSerializer())
            {
                ConsumerTagConvention = () => consumerTag
            };

            consumerErrorStrategy = MockRepository.GenerateStub<IConsumerErrorStrategy>();
            consumerErrorStrategy.Stub(x => x.HandleConsumerError(null, null))
                .IgnoreArguments()
                .WhenCalled(i =>
                {
                    basicDeliverEventArgs = (ConsumerExecutionContext)i.Arguments[0];
                    raisedException = (Exception) i.Arguments[1];
                }).Return(AckStrategies.Ack);

            mockBuilder = new MockBuilder(x => x
                .Register<IConventions>(_ => conventions)
                .Register(_ => consumerErrorStrategy)
                //.Register<IEasyNetQLogger>(_ => new ConsoleLogger())
                );

            mockBuilder.Bus.Subscribe<MyMessage>(subscriptionId, message =>
            {
                throw originalException;
            });

            const string text = "Hello there, I am the text!";
            originalMessage = new MyMessage { Text = text };

            var body = new JsonSerializer(new TypeNameSerializer()).MessageToBytes(originalMessage);

            // deliver a message
            mockBuilder.Consumers[0].HandleBasicDeliver(
                consumerTag,
                deliveryTag,
                false, // redelivered
                typeName,
                "#",
                new BasicProperties
                {
                    Type = typeName,
                    CorrelationId = correlationId
                },
                body);

            // wait for the subscription thread to handle the message ...
            var autoResetEvent = new AutoResetEvent(false);
            mockBuilder.EventBus.Subscribe<AckEvent>(x => autoResetEvent.Set());
            autoResetEvent.WaitOne(1000);
        }
Пример #29
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var exchange = new Exchange("my_exchange");
            var queue = new Topology.Queue("my_queue", false);
            binding = advancedBus.Bind(exchange, queue, "my_routing_key");
            advancedBus.BindingDelete(binding);
        }
Пример #30
0
        public void SetUp()
        {
            var customConventions = new Conventions(new TypeNameSerializer())
            {
                RpcExchangeNamingConvention = () => "CustomRpcExchangeName",
                RpcRoutingKeyNamingConvention = messageType => "CustomRpcRoutingKeyName"
            };

            mockBuilder = new MockBuilder(x => x.Register<IConventions>(_ => customConventions));

            mockBuilder.Bus.Respond<TestMessage, TestMessage>(t => new TestMessage());
        }