Пример #1
0
        public async Task Replays_All_Events_In_Order()
        {
            var store = new SqlServerEventStore(_conStr);

            DeleteEventsTable();

            var eventsReceived = new List <IEvent>();

            store.EventHandler = e =>
            {
                eventsReceived.Add(e);
                return(Task.CompletedTask);
            };

            // Raise some events
            await store.RaiseEventAsync(new TestEvent("Hello, World!"));

            await store.RaiseEventAsync(new TestEvent("Hello, Bob!"));

            await store.RaiseEventAsync(new TestEvent("Hello, Dave!"));

            // Pretend we haven't seen them yet
            eventsReceived.Clear();

            // Replay and check they are correct
            await store.ReplayAllEvents();

            eventsReceived[0].Stream.ShouldBe("test-stream");
            ((TestEvent)eventsReceived[0]).TestValue.ShouldBe("Hello, World!");
            eventsReceived[1].Stream.ShouldBe("test-stream");
            ((TestEvent)eventsReceived[1]).TestValue.ShouldBe("Hello, Bob!");
            eventsReceived[2].Stream.ShouldBe("test-stream");
            ((TestEvent)eventsReceived[2]).TestValue.ShouldBe("Hello, Dave!");
        }
Пример #2
0
        public async Task Raises_And_Replays_Single_Event()
        {
            var store = new SqlServerEventStore(_conStr);

            DeleteEventsTable();

            IEvent eventReceived = null;

            store.EventHandler = e =>
            {
                eventReceived = e;
                return(Task.CompletedTask);
            };

            await store.RaiseEventAsync(new TestEvent("Hello, World!"));

            eventReceived.Stream.ShouldBe("test-stream");
            ((TestEvent)eventReceived).TestValue.ShouldBe("Hello, World!");
        }