public async Task Commit_ShouldCommitAndDisposeAllPendingTransactions() { var wrappedTransactionMocks = new List <Mock <IWrappedTransaction> >(); var createTransactionMock = new Mock <Func <IEventStoreConnection, string, long, Task <IWrappedTransaction> > >(); createTransactionMock .Setup(x => x(_eventStoreConnectionMock.Object, "some_id", 0)) .ReturnsAsync(() => { var wrappedTransactionMock = new Mock <IWrappedTransaction>(); wrappedTransactionMocks.Add(wrappedTransactionMock); return(wrappedTransactionMock.Object); }); var transaction = new EventStoreTransaction <string, object>( connection: _eventStoreConnectionMock.Object, jsonSerializerSettings: _jsonSerializerSettings, createTransaction: createTransactionMock.Object); await transaction.StoreEvents("some_id", 1, new object[] { new EventA(), new EventB() }); await transaction.StoreEvents("some_id", 1, new object[] { new EventA(), new EventB() }); await transaction.StoreEvents("some_id", 1, new object[] { new EventA(), new EventB() }); wrappedTransactionMocks.Should().HaveCount(3); wrappedTransactionMocks[0].Verify(x => x.Rollback(), Times.Never); wrappedTransactionMocks[1].Verify(x => x.Rollback(), Times.Never); wrappedTransactionMocks[2].Verify(x => x.Rollback(), Times.Never); await transaction.Commit(); wrappedTransactionMocks[0].Verify(x => x.CommitAsync(), Times.Once); wrappedTransactionMocks[1].Verify(x => x.CommitAsync(), Times.Once); wrappedTransactionMocks[2].Verify(x => x.CommitAsync(), Times.Once); wrappedTransactionMocks[0].Verify(x => x.Rollback(), Times.Never); wrappedTransactionMocks[1].Verify(x => x.Rollback(), Times.Never); wrappedTransactionMocks[2].Verify(x => x.Rollback(), Times.Never); wrappedTransactionMocks[0].Verify(x => x.Dispose(), Times.Once); wrappedTransactionMocks[1].Verify(x => x.Dispose(), Times.Once); wrappedTransactionMocks[2].Verify(x => x.Dispose(), Times.Once); // Dispose shouldn't have any side effect transaction.Dispose(); wrappedTransactionMocks[0].Verify(x => x.CommitAsync(), Times.Once); wrappedTransactionMocks[1].Verify(x => x.CommitAsync(), Times.Once); wrappedTransactionMocks[2].Verify(x => x.CommitAsync(), Times.Once); wrappedTransactionMocks[0].Verify(x => x.Rollback(), Times.Never); wrappedTransactionMocks[1].Verify(x => x.Rollback(), Times.Never); wrappedTransactionMocks[2].Verify(x => x.Rollback(), Times.Never); wrappedTransactionMocks[0].Verify(x => x.Dispose(), Times.Once); wrappedTransactionMocks[1].Verify(x => x.Dispose(), Times.Once); wrappedTransactionMocks[2].Verify(x => x.Dispose(), Times.Once); }
private void ValidateAllEvent(IEnumerator <long> idEnumerator, IEnumerator <IDomainEvent <int> > evtEnumerator) { idEnumerator.MoveNext(); evtEnumerator.MoveNext(); try { do { var evt = evtEnumerator.Current; _tran.ValidateEvent(idEnumerator.Current, evt); } while (idEnumerator.MoveNext() && evtEnumerator.MoveNext()); _tran.Commit(); } catch { _tran.Rollback(); } }
void SaveEventsInBatch(string stream_name, int expected_version, IEnumerable <Event> events, IEventSerializer serializer) { EventStoreTransaction trasaction = connection_ .StartTransaction(stream_name, expected_version); EventData[] serialized_events = Serialize(events, serializer).ToArray(); int position = 0; while (position < serialized_events.Length) { var page_events = serialized_events .Skip(position) .Take(kWritePageSize); trasaction.Write(page_events); position += kWritePageSize; } trasaction.Commit(); }
public WriteResult Commit() { return(_transaction.Commit()); }
public void Commit() { _transaction.Commit(); }