示例#1
0
        public async Task Find_restores_aggregate_using_memento_if_found(
            FakeUser user,
            string username)
        {
            // Arrange
            var memento = user.SaveToMemento();

            user.ChangeUsername(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
            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
            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);
        }