예제 #1
0
파일: Program.cs 프로젝트: sputier/CQELight
        private static DispatcherConfiguration GetCoreDispatcherConfiguration()
        {
            var configurationBuilder = new DispatcherConfigurationBuilder();

            configurationBuilder
            .ForAllEvents()
            .UseBus <InMemoryEventBus>()
            .HandleErrorWith(e =>
            {
                System.Console.ForegroundColor = ConsoleColor.DarkRed;
                System.Console.WriteLine("An error has been raised during event dispatch : " + e);
                System.Console.ForegroundColor = ConsoleColor.White;
            })
            .SerializeWith <JsonDispatcherSerializer>();
            configurationBuilder
            .ForAllCommands()
            .UseBus <InMemoryCommandBus>()
            .HandleErrorWith(e =>
            {
                System.Console.ForegroundColor = ConsoleColor.DarkRed;
                System.Console.WriteLine("An error has been raised during command dispatch : " + e);
                System.Console.ForegroundColor = ConsoleColor.White;
            })
            .SerializeWith <JsonDispatcherSerializer>();
            return(configurationBuilder.Build());
        }
예제 #2
0
        public void CoreDispatcherConfigurationBuilder_ForAllEvents_SingleBus_AsExpected()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

            cfgBuilder
            .ForAllEvents()
            .UseBus <InMemoryEventBus>()
            .HandleErrorWith(e => _error = e.ToString())
            .SerializeWith <JsonDispatcherSerializer>();

            var cfg = cfgBuilder.Build();

            cfg.EventDispatchersConfiguration.Should().HaveCount(ReflectionTools.GetAllTypes()
                                                                 .Count(t => typeof(IDomainEvent).IsAssignableFrom(t) && t.IsClass));
            var dispatch = cfg.EventDispatchersConfiguration.First(t => t.EventType == typeof(TestDomainEvent));

            dispatch.Should().NotBeNull();
            dispatch.EventType.Should().Be(typeof(TestDomainEvent));
            dispatch.BusesTypes.Should().HaveCount(1);
            dispatch.ErrorHandler.Should().NotBeNull();
            dispatch.Serializer.Should().NotBeNull();

            var dispatcher = dispatch.BusesTypes.First();

            dispatcher.Should().Be(typeof(InMemoryEventBus));
        }
예제 #3
0
        public void CoreDispatcherConfigurationBuilder_ValidateStrict_Error()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

            cfgBuilder
            .ForEvent <TestDomainEvent>()
            .HandleErrorWith(e => _error = e.ToString())
            .SerializeWith <JsonDispatcherSerializer>();

            var c = cfgBuilder.Build(true);

            c.ValidateStrict().Should().BeFalse();
        }
예제 #4
0
        public void CoreDispatcherConfigurationBuilder_ValidateStrict_AsExpected()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

            cfgBuilder
            .ForAllEvents()
            .UseAllAvailableBuses()
            .HandleErrorWith(e => _error = e.ToString())
            .SerializeWith <JsonDispatcherSerializer>();

            var cfg = cfgBuilder.Build(true);

            cfg.ValidateStrict().Should().BeTrue();
        }
예제 #5
0
        public async Task BaseDispatcher_PublishCommandAsync_Should_Keep_Result_Info()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

            cfgBuilder
            .ForCommand <TestResultCommand>()
            .UseBuses(typeof(FakeResultDataBus));

            var dispatcher = new BaseDispatcher(cfgBuilder.Build());

            var result = await dispatcher.DispatchCommandAsync(new TestResultCommand());

            result.Should().BeOfType <Result <string> >();
        }
예제 #6
0
        /// <summary>
        /// Setting up system dispatching configuration with the following configuration.
        /// All manually created dispatchers will be created using their own configuration if speciffied,
        /// or the one specified here. If this method is not called, default configuration will be used for
        /// all dispatchers.
        /// Configuration passed here will be applied to CoreDispatcher as well.
        /// There's no need to call "Build" at the end of this method.
        /// </summary>
        /// <param name="dispatcherConfigurationAction">Fluent configuration to apply.</param>
        /// <returns>Instance of the boostraper</returns>
        public Bootstrapper ConfigureDispatcher(Action <DispatcherConfigurationBuilder> dispatcherConfigurationAction)
        {
            if (dispatcherConfigurationAction == null)
            {
                throw new ArgumentNullException(nameof(dispatcherConfigurationAction));
            }

            var builder = new DispatcherConfigurationBuilder();

            dispatcherConfigurationAction(builder);

            var configuration = builder.Build();

            return(ConfigureDispatcher(configuration));
        }
        public async Task CoreDispatcher_PublishEventAsync_SecurityCritical_On()
        {
            var cfg = new DispatcherConfigurationBuilder();

            cfg.ForEvent <TestEvent>().IsSecurityCritical();
            var config = cfg.Build();

            var          evt           = new TestEvent();
            IDomainEvent callbackEvent = null;

            CoreDispatcher.OnEventDispatched += (s) =>
            {
                callbackEvent = s;
                return(Task.CompletedTask);
            };

            await new BaseDispatcher(config).PublishEventAsync(evt).ConfigureAwait(false);
            ReferenceEquals(evt, callbackEvent).Should().BeFalse();
        }
예제 #8
0
        public async Task BaseDispatcher_PublishCommandAsync_WithResult_Should_Enter_InGoodPath_DependingOfResult()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

            cfgBuilder
            .ForCommand <TestCommand>()
            .UseBuses(typeof(FakeFailResultBus), typeof(FakeOkResultBus));

            var dispatcher = new BaseDispatcher(cfgBuilder.Build());

            bool successCalled = false;
            bool failureCalled = false;

            (await dispatcher.DispatchCommandAsync(new TestCommand()))
            .OnSuccess(() => successCalled = true)
            .OnFailure(() => failureCalled = true);

            successCalled.Should().BeFalse();
            failureCalled.Should().BeTrue();
        }
예제 #9
0
        public async Task PublishEventRange_NoSequence_Should_Respect_Order_SameAggregateId()
        {
            var aggId  = Guid.NewGuid();
            var data   = new DataHolder();
            var events = new Queue <IDomainEvent>();

            events.Enqueue(new EventOne(data, aggId));
            events.Enqueue(new EventTwo(data, aggId));
            events.Enqueue(new EventThree(data, aggId));

            var builder = new DispatcherConfigurationBuilder();

            builder
            .ForAllEvents()
            .UseBus <InMemoryEventBus>();
            var dispatcher = new BaseDispatcher(builder.Build());

            await dispatcher.PublishEventsRangeAsync(events);

            data.Data[aggId].Should().Be("123");
        }
예제 #10
0
        public void CoreDispatcherConfigurationBuilder_ForEvent_SingleBus_AsExpected()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

            cfgBuilder
            .ForEvent <TestDomainEvent>()
            .UseBus <InMemoryEventBus>()
            .HandleErrorWith(e => _error = e.ToString())
            .SerializeWith <JsonDispatcherSerializer>();

            var cfg = cfgBuilder.Build();

            cfg.EventDispatchersConfiguration.Should().HaveCount(1);
            var dispatch = cfg.EventDispatchersConfiguration.First();

            dispatch.EventType.Should().Be(typeof(TestDomainEvent));
            dispatch.BusesTypes.Should().HaveCount(1);
            dispatch.ErrorHandler.Should().NotBeNull();
            dispatch.Serializer.Should().NotBeNull();

            var dispatcher = dispatch.BusesTypes.First();

            dispatcher.Should().Be(typeof(InMemoryEventBus));
        }