public void ThrowsException_WhenGettingAggregateRootByIdAndThereAreNoEvents() { A.CallTo(() => this.eventStream.ReplayAsync()).Returns(EventHistory.Create()); Func <Task> action = async() => { await this.testee .GetByIdAsync <MyDynamicEventSourcedAggregateRoot>(this.aggregateId) .ConfigureAwait(false); }; action.ShouldThrow <AggregateRootNotFoundException>(); }
public async Task CanGetAggregateRootById_ByReplayingAllEvents() { var eventHistory = EventHistory.Create(new ValueEvent(0), new ValueEvent(11), new ValueEvent(22)); A.CallTo(() => this.eventStream.ReplayAsync()).Returns(eventHistory); var aggregateRoot = await this.testee .GetByIdAsync <MyDynamicEventSourcedAggregateRoot>(this.aggregateId) .ConfigureAwait(false); aggregateRoot.Version.Should().Be(2); aggregateRoot.Value.Should().Be(22); }
public async Task CanGetAggregateRootById_ByReplayingAllEventsFromSnapshot() { var snapshot = new MySnapshot(22).WithVersion(2); var eventsSinceSnapshot = EventHistory.Create(new ValueEvent(33), new ValueEvent(44)); A.CallTo(() => this.eventStream.HasSnapshotAsync()).Returns(true); A.CallTo(() => this.eventStream.GetLatestSnapshotAsync()).Returns(snapshot); A.CallTo(() => this.eventStream.ReplayAsyncFromSnapshot(snapshot)).Returns(eventsSinceSnapshot); var aggregateRoot = await this.testee .GetByIdAsync <MyDynamicEventSourcedAggregateRoot>(this.aggregateId) .ConfigureAwait(false); aggregateRoot.Version.Should().Be(4); aggregateRoot.Value.Should().Be(44); }
/// <summary> /// Initializes a new instance of the <see cref="EventSourcedAggregateRootFixture{TAggregateRoot}"/> class. /// </summary> protected EventSourcedAggregateRootFixture() { this.create = Activator.CreateInstance <TAggregateRoot>; this.execute = aggregate => { }; this.eventHistory = EventHistory.Create(); }