public async Task SaveAndPublish_publishes_events() { // Arrange var user = new FakeUser(id: Guid.NewGuid(), username: Guid.NewGuid().ToString()); string operationId = Guid.NewGuid().ToString(); var correlationId = Guid.NewGuid(); string contributor = Guid.NewGuid().ToString(); user.ChangeUsername(username: Guid.NewGuid().ToString()); ISqlEventPublisher eventPublisher = Mock.Of <ISqlEventPublisher>(); var sut = new SqlEventSourcedRepository <FakeUser>( Mock.Of <ISqlEventStore>(), eventPublisher, FakeUser.Factory); // Act await sut.SaveAndPublish(user, operationId, correlationId, contributor); // Assert Mock.Get(eventPublisher).Verify( x => x.FlushPendingEvents(user.Id, default), Times.Once()); }
public SqlEventSourcedRepository( ISqlEventStore eventStore, ISqlEventPublisher eventPublisher, Func <Guid, IEnumerable <IDomainEvent>, T> entityFactory) { _eventStore = eventStore ?? throw new ArgumentNullException(nameof(eventStore)); _eventPublisher = eventPublisher ?? throw new ArgumentNullException(nameof(eventPublisher)); _entityFactory = entityFactory ?? throw new ArgumentNullException(nameof(entityFactory)); }
public SqlEventSourcedRepository( ISqlEventStore eventStore, ISqlEventPublisher eventPublisher, IMementoStore mementoStore, Func <Guid, IEnumerable <IDomainEvent>, T> entityFactory, Func <Guid, IMemento, IEnumerable <IDomainEvent>, T> mementoEntityFactory) : this(eventStore, eventPublisher, entityFactory) { _mementoStore = mementoStore ?? throw new ArgumentNullException(nameof(mementoStore)); _mementoEntityFactory = mementoEntityFactory ?? throw new ArgumentNullException(nameof(mementoEntityFactory)); }
public void TestInitialize() { fixture = new Fixture().Customize(new AutoMoqCustomization()); eventStore = Mock.Of <ISqlEventStore>(); eventPublisher = Mock.Of <ISqlEventPublisher>(); mementoStore = Mock.Of <IMementoStore>(); sut = new SqlEventSourcedRepository <FakeUser>( eventStore, eventPublisher, mementoStore, FakeUser.Factory, FakeUser.Factory); }
public void SaveAndPublish_does_not_publish_events_if_fails_to_save_events() { // Arrange var user = new FakeUser(id: Guid.NewGuid(), username: Guid.NewGuid().ToString()); string operationId = Guid.NewGuid().ToString(); var correlationId = Guid.NewGuid(); string contributor = Guid.NewGuid().ToString(); user.ChangeUsername(username: Guid.NewGuid().ToString()); ISqlEventStore eventStore = Mock.Of <ISqlEventStore>(); Mock.Get(eventStore) .Setup( x => x.SaveEvents <FakeUser>( It.IsAny <IEnumerable <IDomainEvent> >(), operationId, correlationId, contributor, default)) .Throws <InvalidOperationException>(); ISqlEventPublisher eventPublisher = Mock.Of <ISqlEventPublisher>(); var sut = new SqlEventSourcedRepository <FakeUser>( eventStore, eventPublisher, FakeUser.Factory); // Act Func <Task> action = () => sut.SaveAndPublish(user, operationId, correlationId, contributor); // Assert action.ShouldThrow <InvalidOperationException>(); Mock.Get(eventPublisher).Verify( x => x.FlushPendingEvents(user.Id, It.IsAny <CancellationToken>()), Times.Never()); }