Ejemplo n.º 1
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();
        }
        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();
        }
Ejemplo n.º 3
0
        public void CoreDispatcherConfigurationBuilder_ForAllOtherEvents_AllBuses_AsExpected()
        {
            var cfgBuilder = new DispatcherConfigurationBuilder();

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

            cfgBuilder
            .ForAllOtherEvents()
            .UseAllAvailableBuses()
            .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));

            dispatch = cfg.EventDispatchersConfiguration.First(t => t.EventType == typeof(SecondTestDomainEvent));
            dispatch.Should().NotBeNull();
            dispatch.EventType.Should().Be(typeof(SecondTestDomainEvent));
            dispatch.BusesTypes.Should().HaveSameCount(ReflectionTools.GetAllTypes().Where(t => typeof(IDomainEventBus).IsAssignableFrom(t) && t.IsClass));
            dispatch.ErrorHandler.Should().NotBeNull();
            dispatch.Serializer.Should().NotBeNull();

            dispatcher = dispatch.BusesTypes.First(t => t == typeof(InMemoryEventBus));

            dispatcher.Should().Be(typeof(InMemoryEventBus));
        }
Ejemplo n.º 4
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));
        }