Example #1
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));
        }
Example #2
0
        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());
        }
Example #3
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();
        }
Example #4
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");
        }