public async Task Find_restores_aggregate_using_memento_if_found() { // Arrange var user = new FakeUser(id: Guid.NewGuid(), username: Guid.NewGuid().ToString()); IMemento memento = user.SaveToMemento(); user.ChangeUsername(username: Guid.NewGuid().ToString()); IMementoStore mementoStore = Mock.Of <IMementoStore>(); Mock.Get(mementoStore) .Setup(x => x.Find <FakeUser>(user.Id, default)) .ReturnsAsync(memento); ISqlEventStore eventStore = Mock.Of <ISqlEventStore>(); Mock.Get(eventStore) .Setup(x => x.LoadEvents <FakeUser>(user.Id, 1, default)) .ReturnsAsync(user.FlushPendingEvents().Skip(1)) .Verifiable(); var sut = new SqlEventSourcedRepository <FakeUser>( eventStore, Mock.Of <ISqlEventPublisher>(), mementoStore, FakeUser.Factory, FakeUser.Factory); // Act FakeUser actual = await sut.Find(user.Id, default); // Assert Mock.Get(eventStore).Verify(); actual.ShouldBeEquivalentTo(user); }
public async Task Find_restores_aggregate_using_memento_if_found() { // Arrange var user = fixture.Create <FakeUser>(); IMemento memento = user.SaveToMemento(); user.ChangeUsername(fixture.Create("username")); Mock.Get(mementoStore) .Setup(x => x.Find <FakeUser>(user.Id, CancellationToken.None)) .ReturnsAsync(memento); Mock.Get(eventStore) .Setup( x => x.LoadEvents <FakeUser>(user.Id, 1, CancellationToken.None)) .ReturnsAsync(user.PendingEvents.Skip(1)) .Verifiable(); // Act FakeUser actual = await sut.Find(user.Id, CancellationToken.None); // Assert Mock.Get(eventStore).Verify(); actual.ShouldBeEquivalentTo( user, opts => opts.Excluding(x => x.PendingEvents)); }
public async Task Find_restores_aggregate_using_memento_if_found() { // Arrange FakeUser user = _fixture.Create <FakeUser>(); IMemento memento = user.SaveToMemento(); user.ChangeUsername("foo"); Mock.Get(_mementoStore) .Setup(x => x.Find <FakeUser>(user.Id, CancellationToken.None)) .ReturnsAsync(memento); Mock.Get(_eventStore) .Setup( x => x.LoadEvents <FakeUser>(user.Id, 1, CancellationToken.None)) .ReturnsAsync(user.FlushPendingEvents().Skip(1)) .Verifiable(); // Act FakeUser actual = await _sut.Find(user.Id, CancellationToken.None); // Assert Mock.Get(_eventStore).Verify(); actual.ShouldBeEquivalentTo(user); }
public async Task Find_restores_aggregate_from_events() { // Arrange FakeUser user = _fixture.Create <FakeUser>(); user.ChangeUsername(_fixture.Create("username")); Mock.Get(_eventStore) .Setup( x => x.LoadEvents <FakeUser>(user.Id, 0, CancellationToken.None)) .ReturnsAsync(user.FlushPendingEvents()) .Verifiable(); var sut = new SqlEventSourcedRepository <FakeUser>( _eventStore, _eventPublisher, FakeUser.Factory); // Act FakeUser actual = await sut.Find(user.Id, CancellationToken.None); // Assert Mock.Get(_eventStore).Verify(); actual.ShouldBeEquivalentTo(user); }
public async Task Find_restores_aggregate() { var user = fixture.Create <FakeUser>(); user.ChangeUsername("foo"); Mock.Get(eventStore) .Setup(x => x.LoadEvents <FakeUser>(user.Id, 0, CancellationToken.None)) .ReturnsAsync(user.PendingEvents); FakeUser actual = await sut.Find(user.Id, CancellationToken.None); actual.ShouldBeEquivalentTo(user, opts => opts.Excluding(x => x.PendingEvents)); }
public async Task Find_restores_aggregate() { FakeUser user = _fixture.Create <FakeUser>(); user.ChangeUsername("foo"); Mock.Get(_eventStore) .Setup(x => x.LoadEvents <FakeUser>(user.Id, 0, CancellationToken.None)) .ReturnsAsync(user.FlushPendingEvents()); FakeUser actual = await _sut.Find(user.Id, CancellationToken.None); actual.ShouldBeEquivalentTo(user); }
public async Task Find_restores_aggregate_from_events() { // Arrange var user = fixture.Create <FakeUser>(); user.ChangeUsername(fixture.Create("username")); Mock.Get(eventStore) .Setup( x => x.LoadEvents <FakeUser>(user.Id, 0, CancellationToken.None)) .ReturnsAsync(user.PendingEvents) .Verifiable(); // Act FakeUser actual = await sut.Find(user.Id, CancellationToken.None); // Assert Mock.Get(eventStore).Verify(); actual.ShouldBeEquivalentTo( user, opts => opts.Excluding(x => x.PendingEvents)); }