public void TestThatObjectPersistsQueries() { _dispatcher.AfterCompleting(1); var persistAccess = _persistInterest.AfterCompleting(1); var person = new Person("Tom Jones", 85); var source = new Test1Source(); _objectStore.Persist(person, new List <Test1Source> { source }, _persistInterest); var persistSize = persistAccess.ReadFrom <int>("size"); Assert.Equal(1, persistSize); Assert.Equal(person, persistAccess.ReadFrom <int, object>("object", 0)); var query = MapQueryExpression.Using <Person>("find", MapQueryExpression.Map("id", person.PersistenceId)); var queryAccess = _queryResultInterest.AfterCompleting(1); _objectStore.QueryObject(query, _queryResultInterest, null); var querySize = queryAccess.ReadFrom <int>("size"); Assert.Equal(1, querySize); Assert.Equal(person, queryAccess.ReadFrom <int, object>("object", 0)); Assert.Equal(1, _dispatcher.DispatchedCount()); var dispatched = _dispatcher.GetDispatched()[0]; ValidateDispatchedState(person, dispatched); var dispatchedEntries = dispatched.Entries; Assert.Single(dispatchedEntries); var entry = dispatchedEntries[0]; Assert.NotNull(entry.Id); Assert.Equal(source.GetType().AssemblyQualifiedName, entry.TypeName); Assert.Equal(Metadata.NullMetadata(), entry.Metadata); }
public void TestThatJournalAppendsOneEvent() { var interest = new MockAppendResultInterest <Test1Source, SnapshotState>(); _dispatcher.AfterCompleting(1); interest.AfterCompleting(1); var source = new Test1Source(); var streamName = "123"; var streamVersion = 1; _journal.Append <Test1Source, SnapshotState>(streamName, streamVersion, source, interest, _object); Assert.Equal(1, interest.ReceivedAppendsSize); var entries = interest.Entries; var journalData = entries.First(); Assert.NotNull(journalData); Assert.Equal(streamName, journalData.StreamName); Assert.Equal(streamVersion, journalData.StreamVersion); Assert.Equal(Result.Success, journalData.Result); Assert.False(journalData.Snapshot.IsPresent); var sourceList = journalData.Sources; Assert.Single(sourceList); Assert.Equal(source, sourceList.First()); Assert.Equal(1, _dispatcher.DispatchedCount()); var dispatched = _dispatcher.GetDispatched()[0]; Assert.NotEqual(new DateTimeOffset(), dispatched.CreatedOn); Assert.False(dispatched.State.IsPresent); Assert.NotNull(dispatched.Id); var dispatchedEntries = dispatched.Entries; Assert.Single(dispatchedEntries); }