public void Find_should_return_hydrated_entity_when_it_has_snapsot_and_no_later_events() { var entityId = Guid.NewGuid(); var snapshot = new MementoOriginator.Memento { SourceId = entityId, Version = 3, Value = 30 }; var eventStoreMock = new Mock <IEventStore>(); eventStoreMock.Setup(eventStore => eventStore.Load(entityId, snapshot.Version + 1)).Returns(Enumerable.Empty <Commit>); var snapshotStoreMock = new Mock <ISnapshotStore>(); snapshotStoreMock.Setup(snapshotStore => snapshotStore.Get(entityId, int.MaxValue)).Returns(() => snapshot); var repository = new EventSourcedRepository <MementoOriginator>(eventStoreMock.Object, snapshotStoreMock.Object); var entity = repository.Find(entityId); entity.Id.Should().Be(entityId); entity.Version.Should().Be(snapshot.Version); entity.Value.Should().Be(snapshot.Value); }
public void Find_should_return_hydrated_entity_when_it_has_snapsot_and_events() { var entityId = Guid.NewGuid(); var snapshot = new MementoOriginator.Memento { SourceId = entityId, Version = 3, Value = 30 }; var events = new IEvent[] { new CorrectEventSourced.Updated { SourceId = entityId, SourceVersion = snapshot.Version + 1, Value = 40 }, new CorrectEventSourced.Updated { SourceId = entityId, SourceVersion = snapshot.Version + 2, Value = 50 } }; var commit = new Commit { Id = Guid.NewGuid(), SourceId = entityId, Changes = events }; var snapshotStoreMock = new Mock <ISnapshotStore>(); snapshotStoreMock.Setup(snapshotStore => snapshotStore.Get(entityId, int.MaxValue)).Returns(() => snapshot); var eventStoreMock = new Mock <IEventStore>(); eventStoreMock.Setup(eventStore => eventStore.Load(entityId, snapshot.Version + 1)).Returns(new[] { commit }); var repository = new EventSourcedRepository <MementoOriginator>(eventStoreMock.Object, snapshotStoreMock.Object); var entity = repository.Find(entityId); entity.Id.Should().Be(entityId); entity.Version.Should().Be(events.Last().SourceVersion); entity.Value.Should().Be(events.OfType <CorrectEventSourced.Updated>().Last().Value); }