Esempio n. 1
0
        public async Task Publish_Event_CriticalHandlerThrow_Should_NotCallNextHandlers()
        {
            var evt        = new CriticalEvent();
            var cfgBuilder =
                new InMemoryEventBusConfigurationBuilder();
            var bus = new InMemoryEventBus(cfgBuilder.Build());

            (await bus.PublishEventAsync(evt)).IsSuccess.Should().BeTrue();

            evt.HandlerData.Should().Be("AB");
        }
Esempio n. 2
0
        public async Task Publish_Event_CriticalHandlerThrow_Should_BeTheOnlyOneRetried_If_RetryStrategy_IsDefined()
        {
            var evt        = new CriticalEvent();
            var cfgBuilder =
                new InMemoryEventBusConfigurationBuilder()
                .SetRetryStrategy(1, 3);
            var bus = new InMemoryEventBus(cfgBuilder.Build());

            (await bus.PublishEventAsync(evt)).IsSuccess.Should().BeTrue();

            evt.HandlerData.Should().Be("ABBBC");
            evt.NbTries.Should().Be(3);
        }
Esempio n. 3
0
        public async Task InMemoryEventBus_Configuration_ParallelDispatch()
        {
            var cfgBuilder =
                new InMemoryEventBusConfigurationBuilder()
                .AllowParallelDispatchFor <ParallelEvent>();

            var b = new InMemoryEventBus(cfgBuilder.Build());

            var evt = new ParallelEvent();

            (await b.PublishEventAsync(evt).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            evt.ThreadsInfos.Should().HaveCount(2);
        }
Esempio n. 4
0
        public async Task InMemoryEventBus_Configuration_RetryStrategy_CallbackNoInvoked()
        {
            bool callbackCalled = false;
            var  cfgBuilder     =
                new InMemoryEventBusConfigurationBuilder()
                .SetRetryStrategy(100, 3)
                .DefineErrorCallback((e, ctx) => callbackCalled = true);

            var b = new InMemoryEventBus(cfgBuilder.Build());

            (await b.PublishEventAsync(new TestRetryEvent()).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            callbackCalled.Should().BeFalse();
        }
Esempio n. 5
0
        /// <summary>
        /// Configure the system to use InMemory Event bus for dipsatching events, with the provided configuration.
        /// </summary>
        /// <param name="bootstrapper">Bootstrapper instance.</param>
        /// <param name="configurationBuilderAction">Action to apply on builder.</param>
        /// <param name="excludedEventsDLLs">DLLs name to exclude from auto-configuration into IoC
        /// (IAutoRegisterType will be ineffective).</param>
        /// <returns>Bootstrapper Instance.</returns>
        public static Bootstrapper UseInMemoryEventBus(this Bootstrapper bootstrapper, Action <InMemoryEventBusConfigurationBuilder> configurationBuilderAction,
                                                       params string[] excludedEventsDLLs)
        {
            if (configurationBuilderAction == null)
            {
                throw new ArgumentNullException(nameof(configurationBuilderAction));
            }

            var builder = new InMemoryEventBusConfigurationBuilder();

            configurationBuilderAction(builder);

            return(UseInMemoryEventBus(bootstrapper, builder.Build(), excludedEventsDLLs));
        }
Esempio n. 6
0
        public async Task InMemoryEventBus_Configuration_RetryStrategy_WhenDispatchParallel()
        {
            bool callbackCalled = false;
            var  cfgBuilder     =
                new InMemoryEventBusConfigurationBuilder()
                .SetRetryStrategy(100, 3)
                .DefineErrorCallback((e, ctx) => callbackCalled = true)
                .AllowParallelDispatchFor <ParallelEvent>();

            var b = new InMemoryEventBus(cfgBuilder.Build());

            var evt = new ParallelEvent()
            {
                RetryMode = true
            };

            (await b.PublishEventAsync(evt).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            callbackCalled.Should().BeFalse();
            evt.ThreadsInfos.Should().HaveCount(2);
        }
Esempio n. 7
0
        public async Task InMemoryEventBus_Configuration_DispatchIfClause()
        {
            TestIfEventHandler.ResetData();
            var cfgBuilder =
                new InMemoryEventBusConfigurationBuilder()
                .DispatchOnlyIf <TestIfEvent>(e => e.Data > 1);

            var b = new InMemoryEventBus(cfgBuilder.Build());

            TestIfEventHandler.Data.Should().Be(0);

            (await b.PublishEventAsync(new TestIfEvent {
                Data = 1
            }).ConfigureAwait(false)).IsSuccess.Should().BeFalse();

            TestIfEventHandler.Data.Should().Be(0);

            (await b.PublishEventAsync(new TestIfEvent {
                Data = 10
            }).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            TestIfEventHandler.Data.Should().Be(10);
        }