コード例 #1
0
        public async Task Handles_Do_Not_Raise_Events_Again_When_Events_Are_Being_Replayed()
        {
            // Given
            var store = new TestEventStore();

            _easyEvents.Configure(new EasyEventsConfiguration
            {
                Store          = store,
                HandlerFactory = type =>
                {
                    if (type == typeof(IEventHandler <RaisesAnotherEvent>))
                    {
                        return(new RaisesAnotherEventHandler(_easyEvents));
                    }
                    return(new NullEventHandler());
                }
            });
            await _easyEvents.RaiseEventAsync(new RaisesAnotherEvent());

            // When
            _easyEvents.ReplayAllEventsAsync().Wait();

            // Then
            store.Events.Count.ShouldBe(2);
            store.Events[0].ShouldBeOfType <RaisesAnotherEvent>();
            store.Events[1].ShouldBeOfType <NullEvent>();
        }
コード例 #2
0
        public async Task Processors_Do_Not_Raise_Events_Again_When_Replaying_Events()
        {
            // Given
            var store = new TestEventStore();

            _easyEvents.Configure(new EasyEventsConfiguration
            {
                Store          = store,
                HandlerFactory = type => new SimpleTextEventHandler(new List <SimpleTextEvent>())
            });

            _easyEvents.AddProcessorForStream("TestStream", async(s, e) =>
            {
                // Processor that raises another event
                await _easyEvents.RaiseEventAsync(new SimpleTextEvent("Raised by processor", "AnotherStream"));
            });

            // When
            await _easyEvents.RaiseEventAsync(new SimpleTextEvent("Raised by test"));

            // Then
            await _easyEvents.ReplayAllEventsAsync();

            store.Events.Count.ShouldBe(2);
            ((SimpleTextEvent)store.Events[0]).SomeTestValue.ShouldBe("Raised by test");
            ((SimpleTextEvent)store.Events[1]).SomeTestValue.ShouldBe("Raised by processor");
        }
コード例 #3
0
        public async Task Handlers_Can_Raise_New_Events_During_Normal_Operation()
        {
            // Given
            var store = new TestEventStore();

            _easyEvents.Configure(new EasyEventsConfiguration
            {
                Store          = store,
                HandlerFactory = type =>
                {
                    if (type == typeof(IEventHandler <RaisesAnotherEvent>))
                    {
                        return(new RaisesAnotherEventHandler(_easyEvents));
                    }
                    return(new NullEventHandler());
                }
            });

            // When
            await _easyEvents.RaiseEventAsync(new RaisesAnotherEvent());

            // Then
            store.Events[0].ShouldBeOfType <RaisesAnotherEvent>();
            store.Events[1].ShouldBeOfType <NullEvent>();
        }