Esempio n. 1
0
        public MockBuilder(string connectionString, Action <IServiceRegister> registerServices)
        {
            for (int i = 0; i < 10; i++)
            {
                channelPool.Push(MockRepository.GenerateStub <IModel>());
            }

            connectionFactory.Stub(x => x.CreateConnection()).Return(connection);
            connectionFactory.Stub(x => x.Next()).Return(false);
            connectionFactory.Stub(x => x.Succeeded).Return(true);
            connectionFactory.Stub(x => x.CurrentHost).Return(new HostConfiguration
            {
                Host = Host,
                Port = PortNumber
            });
            connectionFactory.Stub(x => x.Configuration).Return(new ConnectionConfiguration
            {
                VirtualHost = VirtualHost,
            });

            connection.Stub(x => x.IsOpen).Return(true);

            connection.Stub(x => x.CreateModel()).WhenCalled(i =>
            {
                // Console.Out.WriteLine("\n\nMockBuilder - creating model\n{0}\n\n\n", new System.Diagnostics.StackTrace().ToString());

                var channel   = channelPool.Pop();
                i.ReturnValue = channel;
                channels.Add(channel);
                channel.Stub(x => x.CreateBasicProperties()).Return(basicProperties);
                channel.Stub(x => x.IsOpen).Return(true);
                channel.Stub(x => x.BasicConsume(null, false, null, null, null))
                .IgnoreArguments()
                .WhenCalled(consumeInvokation =>
                {
                    var queueName   = (string)consumeInvokation.Arguments[0];
                    var consumerTag = (string)consumeInvokation.Arguments[2];
                    var consumer    = (IBasicConsumer)consumeInvokation.Arguments[4];

                    ConsumerQueueNames.Add(queueName);
                    consumer.HandleBasicConsumeOk(consumerTag);
                    consumers.Add(consumer);
                }).Return("");
            });

            bus = RabbitHutch.CreateBus(connectionString, x =>
            {
                registerServices(x);
                x.Register(_ => connectionFactory);
                x.Register(_ => logger);
            });

            bus.ShouldNotBeNull();
            bus.Advanced.ShouldNotBeNull();
            bus.Advanced.Container.ShouldNotBeNull();
        }
Esempio n. 2
0
        public MockBuilder(string connectionString, Action <IServiceRegister> registerServices)
        {
            for (int i = 0; i < 10; i++)
            {
                channelPool.Push(Substitute.For <IModel>());
            }

            connectionFactory.CreateConnection().Returns(connection);
            connectionFactory.Next().Returns(false);
            connectionFactory.Succeeded.Returns(true);
            connectionFactory.CurrentHost.Returns(new HostConfiguration
            {
                Host = Host,
                Port = PortNumber
            });
            connectionFactory.Configuration.Returns(new ConnectionConfiguration
            {
                VirtualHost = VirtualHost,
            });

            connection.IsOpen.Returns(true);

            connection.CreateModel().Returns(i =>
            {
                var channel = channelPool.Pop();
                channels.Add(channel);
                channel.CreateBasicProperties().Returns(basicProperties);
                channel.IsOpen.Returns(true);
                channel.BasicConsume(null, false, null, true, false, null, null)
                .ReturnsForAnyArgs(consumeInvokation =>
                {
                    var queueName   = (string)consumeInvokation[0];
                    var consumerTag = (string)consumeInvokation[2];
                    var consumer    = (IBasicConsumer)consumeInvokation[6];

                    ConsumerQueueNames.Add(queueName);
                    consumer.HandleBasicConsumeOk(consumerTag);
                    consumers.Add(consumer);
                    return(string.Empty);
                });

                return(channel);
            });

            bus = RabbitHutch.CreateBus(connectionString, x =>
            {
                registerServices(x);
                x.Register(_ => connectionFactory);
                x.Register(_ => logger);
            });

            bus.ShouldNotBeNull();
            bus.Advanced.ShouldNotBeNull();
            bus.Advanced.Container.ShouldNotBeNull();
        }
Esempio n. 3
0
        public MockBuilder(string connectionString, Action <IServiceRegister> registerServices)
        {
            for (var i = 0; i < 10; i++)
            {
                channelPool.Push(Substitute.For <IModel, IRecoverable>());
            }

            connectionFactory.CreateConnection(Arg.Any <IList <AmqpTcpEndpoint> >()).Returns(connection);
            connection.IsOpen.Returns(true);
            connection.Endpoint.Returns(new AmqpTcpEndpoint("localhost"));

            connection.CreateModel().Returns(i =>
            {
                var channel = channelPool.Pop();
                channels.Add(channel);
                channel.CreateBasicProperties().Returns(basicProperties);
                channel.IsOpen.Returns(true);
                channel.BasicConsume(null, false, null, true, false, null, null)
                .ReturnsForAnyArgs(consumeInvocation =>
                {
                    var queueName   = (string)consumeInvocation[0];
                    var consumerTag = (string)consumeInvocation[2];
                    var consumer    = (IBasicConsumer)consumeInvocation[6];

                    ConsumerQueueNames.Add(queueName);
                    consumer.HandleBasicConsumeOk(consumerTag);
                    consumers.Add(consumer);
                    return(string.Empty);
                });
                channel.QueueDeclare(null, true, false, false, null)
                .ReturnsForAnyArgs(queueDeclareInvocation =>
                {
                    var queueName = (string)queueDeclareInvocation[0];

                    return(new QueueDeclareOk(queueName, 0, 0));
                });

                return(channel);
            });

            bus = RabbitHutch.CreateBus(connectionString, x =>
            {
                registerServices(x);
                x.Register(connectionFactory);
            });

            bus.Should().NotBeNull();
            bus.Advanced.Should().NotBeNull();
            bus.Advanced.Container.Should().NotBeNull();
        }