public void CanDispatchMultipleEventsToMultipleViews()
        {
            var firstRepository    = new MemoryRepository <string, SomeEvent>();
            var secondRepository   = new MemoryRepository <string, SomeEvent>();
            var views              = new View[] { new SomeView(firstRepository), new SomeView(secondRepository) };
            var snapshotRepository = new MemoryRepository <string, Snapshot>();
            var firstEvent         = new SomeEvent {
                Id = "test"
            };
            var secondEvent = new SomeEvent {
                Id = "test2"
            };

            using (var snapshotManager = new SnapshotManager(views, snapshotRepository, Timeout.Infinite))
            {
                // act
                snapshotManager.Dispatch(new Event {
                    SequenceNumber = 1, Payload = firstEvent
                });
                snapshotManager.Dispatch(new Event {
                    SequenceNumber = 2, Payload = secondEvent
                });

                // assert
                firstRepository.Get(firstEvent.Id).Should().Be(firstEvent);
                firstRepository.Get(secondEvent.Id).Should().Be(secondEvent);
                secondRepository.Get(firstEvent.Id).Should().Be(firstEvent);
                secondRepository.Get(secondEvent.Id).Should().Be(secondEvent);
            }
        }
        public void CanSnapshotSingleViewDuringDispatch()
        {
            var repository         = new TestRepository();
            var views              = new View[] { new SomeView(repository) };
            var snapshotRepository = new MemoryRepository <string, Snapshot>();
            var firstEvent         = new SomeEvent {
                Id = "test"
            };
            var secondEvent = new SomeEvent {
                Id = "test2"
            };

            using (var snapshotManager = new SnapshotManager(views, snapshotRepository, 20))
            {
                snapshotManager.Dispatch(new Event {
                    SequenceNumber = 1, Payload = firstEvent
                });

                // act
                var preSnapshotEvent = repository.Get(secondEvent.Id);
                repository.WaitUntilSnapshotSaveStarted();
                repository.WaitUntilSnapshotSaveEnded();
                snapshotManager.Dispatch(new Event {
                    SequenceNumber = 2, Payload = secondEvent
                });

                repository.WaitUntilSnapshotSaveEnded();
                var postSnapshotEvent = repository.Get(secondEvent.Id);

                // assert
                preSnapshotEvent.Should().BeNull();
                postSnapshotEvent.Should().Be(secondEvent);
            }
        }
        public void CanDispatchToSingleView()
        {
            var repository         = new MemoryRepository <string, SomeEvent>();
            var views              = new View[] { new SomeView(repository) };
            var snapshotRepository = new MemoryRepository <string, Snapshot>();
            var @event             = new SomeEvent {
                Id = "test"
            };

            using (var snapshotManager = new SnapshotManager(views, snapshotRepository, Timeout.Infinite))
            {
                // act
                snapshotManager.Dispatch(new Event {
                    SequenceNumber = 1, Payload = @event
                });

                // assert
                repository.Get(@event.Id).Should().Be(@event);
            }
        }