예제 #1
0
        public async Task A_consumer_is_being_tested()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <MyConsumer>();
            builder.RegisterGeneric(typeof(ValidatorFilter <>));

            builder.RegisterType <AValidator>()
            .As <IValidator <A> >();

            builder.RegisterType <ConsumerConfigurationObserver>()
            .SingleInstance();

            _container = builder.Build();

            _observer = _container.Resolve <ConsumerConfigurationObserver>();

            _harness = new InMemoryTestHarness();
            _harness.OnConfigureBus += ConfigureBus;
            _consumer = _harness.Consumer(new ScopeConsumerFactory <MyConsumer>(new AutofacConsumerScopeProvider(new SingleLifetimeScopeProvider(_container),
                                                                                                                 "message", (b, ct) =>
            {
            })));

            await _harness.Start();
        }
예제 #2
0
        public void Should_invoke_the_observers_for_each_consumer_and_message_type()
        {
            var observer = new ConsumerConfigurationObserver();

            var bus = Bus.Factory.CreateUsingInMemory(cfg =>
            {
                cfg.ConnectConsumerConfigurationObserver(observer);

                cfg.ReceiveEndpoint("hello", e =>
                {
                    e.UseRetry(x => x.Immediate(1));

                    e.Consumer <MyConsumer>(x =>
                    {
                        x.Message <PingMessage>(m => m.UseExecute(context => Console.WriteLine("Hello")));
                        x.Message <PongMessage>(m => m.UseExecute(context => Console.WriteLine("Hello")));
                        x.ConsumerMessage <PingMessage>(m => m.UseExecute(context =>
                        {
                        }));

                        x.UseExecuteAsync(context => TaskUtil.Completed);
                    });
                });
            });

            Assert.That(observer.ConsumerTypes.Contains(typeof(MyConsumer)));
            Assert.That(observer.MessageTypes.Contains(Tuple.Create(typeof(MyConsumer), typeof(PingMessage))));
            Assert.That(observer.MessageTypes.Contains(Tuple.Create(typeof(MyConsumer), typeof(PongMessage))));
        }
예제 #3
0
        public async Task A_consumer_is_being_tested()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <MyConsumer>();
            builder.RegisterGeneric(typeof(ValidatorFilter <>));

            builder.RegisterType <AValidator>()
            .As <IValidator <A> >();

            builder.RegisterType <ConsumerConfigurationObserver>()
            .SingleInstance();

            _container = builder.Build();

            _observer = _container.Resolve <ConsumerConfigurationObserver>();

            _harness = new InMemoryTestHarness();
            _harness.OnConfigureBus += ConfigureBus;
            _consumer = _harness.Consumer(new AutofacConsumerFactory <MyConsumer>(_container, "message"));

            await _harness.Start();

            Console.WriteLine(_harness.Bus.GetProbeResult().ToJsonString());
        }
예제 #4
0
        public void Should_invoke_the_observers_for_regular_consumer_and_message_type()
        {
            var observer = new ConsumerConfigurationObserver();

            var bus = Bus.Factory.CreateUsingInMemory(cfg =>
            {
                cfg.ConnectConsumerConfigurationObserver(observer);

                cfg.ReceiveEndpoint("hello", e =>
                {
                    e.UseRetry(x => x.Immediate(1));

                    e.Consumer <MyConsumer>();
                });
            });

            Assert.That(observer.ConsumerTypes.Contains(typeof(MyConsumer)));
            Assert.That(observer.MessageTypes.Contains(Tuple.Create(typeof(MyConsumer), typeof(PingMessage))));
            Assert.That(observer.MessageTypes.Contains(Tuple.Create(typeof(MyConsumer), typeof(PongMessage))));
        }