Ejemplo n.º 1
0
        public void Published_event_gets_handled()
        {
            RollbackHandlerRegistry.ImplProvider = new TestImplProv();

            var sem = new SemaphoreSlim(0, 1);
            var bus = new RabbitMqEventBus(new RabbitMqSettings()
            {
                ConnectionString = TestContextUtils.GetParameterOrDefault("rabbitmq-connection-string", "host=localhost"),
            }, Mock.Of <ILogger <RabbitMqEventBus> >());

            var toPublish = new TestAppEvent(new CorrelationId("111"), new TestEvent());

            var handler = new TestHandler(new AppEventRabbitMQBuilder(), (ev) =>
            {
                ev.Should().BeEquivalentTo(toPublish);
                sem.Release();
            });


            var stubImplProvider = new Mock <IImplProvider>();

            stubImplProvider.Setup(provider => provider.Get(typeof(TestHandler)))
            .Returns(handler);
            bus.InitSubscribers("Test.IntegrationTests", stubImplProvider.Object);

            bus.Publish(toPublish);

            if (!sem.Wait(TimeSpan.FromSeconds(60)))
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 2
0
        public void RollbackHandler_gets_called_once()
        {
            int called          = 0;
            var sem             = new SemaphoreSlim(0, 1);
            var toPublish       = new TestAppEvent(new CorrelationId("123"), new TestEvent(), new TestCommandBase());
            var rollbackHandler = new TestCommandRollbackHandler(new Action <IAppEvent <Event> >(ev =>
            {
                called++;
                Assert.IsTrue(CheckRollbackAppEvent(ev));
                sem.Release();
            }));

            rollbackHandler.Throws = true;

            RollbackHandlerRegistry.ImplProvider = new TestImplProv();
            RollbackHandlerRegistry.RegisterCommandRollbackHandler(nameof(TestCommandBase), provider => rollbackHandler);

            var bus = new RabbitMqEventBus(new RabbitMqSettings()
            {
                ConnectionString = TestContextUtils.GetParameterOrDefault("rabbitmq-connection-string", "host=localhost"),
            }, Mock.Of <ILogger <RabbitMqEventBus> >());

            var handler = new TestHandler(new AppEventRabbitMQBuilder(), null);

            handler.Throws = true;

            bus.InitSubscribers(new[]
            {
                new RabbitMqEventConsumerFactory(() => handler, "test"),
            });

            bus.Publish(toPublish);

            if (!sem.Wait(TimeSpan.FromSeconds(60)))
            {
                Assert.Fail();
            }
            ;
            Thread.Sleep(10);

            called.Should()
            .Be(1);
        }