public RestoreGrain( IBackupArchiveLocation backupArchiveLocation, IClock clock, ICommandBus commandBus, IEventDataFormatter eventDataFormatter, IEventStore eventStore, IGrainState <RestoreState2> state, IServiceProvider serviceProvider, IStreamNameResolver streamNameResolver, IUserResolver userResolver, ISemanticLog log) { Guard.NotNull(backupArchiveLocation); Guard.NotNull(clock); Guard.NotNull(commandBus); Guard.NotNull(eventDataFormatter); Guard.NotNull(eventStore); Guard.NotNull(serviceProvider); Guard.NotNull(state); Guard.NotNull(streamNameResolver); Guard.NotNull(userResolver); Guard.NotNull(log); this.backupArchiveLocation = backupArchiveLocation; this.clock = clock; this.commandBus = commandBus; this.eventDataFormatter = eventDataFormatter; this.eventStore = eventStore; this.serviceProvider = serviceProvider; this.state = state; this.streamNameResolver = streamNameResolver; this.userResolver = userResolver; this.log = log; }
/// <summary> /// Creates an instance of the <see cref="InMemoryEventStore"/> class. /// </summary> /// <param name="settings">Settings</param> public InMemoryEventStore(InMemoryEventStoreSettings settings) { _serializer = settings.EventSerializer; _streamNameResolver = settings.StreamNameResolver; _clock = settings.Clock; _metadataFactory = settings.MetadataFactory; }
public RestoreGrain(IBackupArchiveLocation backupArchiveLocation, IClock clock, ICommandBus commandBus, IEventStore eventStore, IEventDataFormatter eventDataFormatter, IEnumerable <BackupHandler> handlers, ISemanticLog log, IStreamNameResolver streamNameResolver, IStore <string> store) { Guard.NotNull(backupArchiveLocation, nameof(backupArchiveLocation)); Guard.NotNull(clock, nameof(clock)); Guard.NotNull(commandBus, nameof(commandBus)); Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter)); Guard.NotNull(handlers, nameof(handlers)); Guard.NotNull(store, nameof(store)); Guard.NotNull(streamNameResolver, nameof(streamNameResolver)); Guard.NotNull(log, nameof(log)); this.backupArchiveLocation = backupArchiveLocation; this.clock = clock; this.commandBus = commandBus; this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.handlers = handlers; this.store = store; this.streamNameResolver = streamNameResolver; this.log = log; }
public RestoreGrain(IBackupArchiveLocation backupArchiveLocation, IClock clock, ICommandBus commandBus, IEventStore eventStore, IEventDataFormatter eventDataFormatter, IJsonSerializer serializer, ISemanticLog log, IServiceProvider serviceProvider, IStreamNameResolver streamNameResolver, IGrainState <RestoreState> state) { Guard.NotNull(backupArchiveLocation, nameof(backupArchiveLocation)); Guard.NotNull(clock, nameof(clock)); Guard.NotNull(commandBus, nameof(commandBus)); Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter)); Guard.NotNull(serializer, nameof(serializer)); Guard.NotNull(serviceProvider, nameof(serviceProvider)); Guard.NotNull(state, nameof(state)); Guard.NotNull(streamNameResolver, nameof(streamNameResolver)); Guard.NotNull(log, nameof(log)); this.backupArchiveLocation = backupArchiveLocation; this.clock = clock; this.commandBus = commandBus; this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.serializer = serializer; this.serviceProvider = serviceProvider; this.streamNameResolver = streamNameResolver; this.state = state; this.log = log; }
public void SetUp() { _model = new Model(); using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { new EventStub(1).Write(writer); } EmbeddedEventStore.Connection.AppendToStreamAsync( _model.KnownIdentifier, ExpectedVersion.NoStream, new EventData( Guid.NewGuid(), typeof(EventStub).AssemblyQualifiedName, false, stream.ToArray(), new byte[0])).Wait(); } _root = SnapshotableAggregateRootEntityStub.Factory(); _unitOfWork = new UnitOfWork(); _resolver = A.Fake <IStreamNameResolver>(); _reader = A.Fake <ISnapshotReader>(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptional(_model.KnownIdentifier)).Returns(Optional <Snapshot> .Empty); A.CallTo(() => _reader.ReadOptional(_model.UnknownIdentifier)).Returns(Optional <Snapshot> .Empty); _sut = new SnapshotableRepository <SnapshotableAggregateRootEntityStub>( () => _root, _unitOfWork, EmbeddedEventStore.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
/// <summary> /// Initializes a new instance of the <see cref="SnapshotReaderConfiguration" /> class. /// </summary> /// <param name="deserializer">The snapshot deserializer.</param> /// <param name="streamNameResolver">The snapshot stream name resolver.</param> /// <param name="streamUserCredentialsResolver">The snapshot stream user credentials resolver.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="deserializer" /> or /// <paramref name="streamNameResolver" /> or <paramref name="streamUserCredentialsResolver" /> is <c>null</c>. /// </exception> public SnapshotReaderConfiguration(ISnapshotDeserializer deserializer, IStreamNameResolver streamNameResolver, IStreamUserCredentialsResolver streamUserCredentialsResolver) { Deserializer = deserializer ?? throw new ArgumentNullException(nameof(deserializer)); StreamNameResolver = streamNameResolver ?? throw new ArgumentNullException(nameof(streamNameResolver)); StreamUserCredentialsResolver = streamUserCredentialsResolver ?? throw new ArgumentNullException(nameof(streamUserCredentialsResolver)); }
public Persistence(TKey ownerKey, Type ownerType, IEventStore eventStore, IEventDataFormatter eventDataFormatter, ISnapshotStore <object, TKey> snapshotStore, IStreamNameResolver streamNameResolver, Func <Envelope <IEvent>, Task> applyEvent) : base(ownerKey, ownerType, eventStore, eventDataFormatter, snapshotStore, streamNameResolver, PersistenceMode.EventSourcing, null, applyEvent) { }
/// <summary> /// Initializes a new instance of the <see cref="EventReaderConfiguration" /> class. /// </summary> /// <param name="sliceSize">Size of the slice to read.</param> /// <param name="deserializer">The event deserializer to use.</param> /// <param name="streamNameResolver">The stream name resolver to use.</param> /// <param name="streamUserCredentialsResolver">The stream user credentials resolver to use.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when the <paramref name="deserializer" /> or /// <paramref name="streamNameResolver" /> is <c>null</c>. /// </exception> public EventReaderConfiguration(SliceSize sliceSize, IEventDeserializer deserializer, IStreamNameResolver streamNameResolver, IStreamUserCredentialsResolver streamUserCredentialsResolver) { SliceSize = sliceSize; Deserializer = deserializer ?? throw new ArgumentNullException(nameof(deserializer)); StreamNameResolver = streamNameResolver ?? throw new ArgumentNullException(nameof(streamNameResolver)); StreamUserCredentialsResolver = streamUserCredentialsResolver ?? throw new ArgumentNullException(nameof(streamUserCredentialsResolver)); }
SnapshotReaderConfigurationBuilder( ISnapshotDeserializer deserializer, IStreamNameResolver streamNameResolver, IStreamUserCredentialsResolver streamUserCredentialsResolver) { _deserializer = deserializer; _streamNameResolver = streamNameResolver; _streamUserCredentialsResolver = streamUserCredentialsResolver; }
public Persistence(TKey ownerKey, Type ownerType, IEventStore eventStore, IEventDataFormatter eventDataFormatter, ISnapshotStore <None, TKey> snapshotStore, IStreamNameResolver streamNameResolver, HandleEvent applyEvent) : base(ownerKey, ownerType, eventStore, eventDataFormatter, snapshotStore, streamNameResolver, PersistenceMode.EventSourcing, null, applyEvent) { }
public DefaultDomainObjectRepository(IEventStore eventStore, IStreamNameResolver nameResolver, EventDataFormatter formatter) { Guard.NotNull(formatter, nameof(formatter)); Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(nameResolver, nameof(nameResolver)); this.formatter = formatter; this.eventStore = eventStore; this.nameResolver = nameResolver; }
public EventStore( IEventStoreConnection connection, IJsonEventSerializer serializer, IStreamNameResolver streamNameResolver ) { _connection = connection; _serializer = serializer; _streamNameResolver = streamNameResolver; }
public ContentVersionLoader(IEventStore eventStore, IStreamNameResolver nameResolver, EventDataFormatter formatter) { Guard.NotNull(formatter, nameof(formatter)); Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(nameResolver, nameof(nameResolver)); this.formatter = formatter; this.eventStore = eventStore; this.nameResolver = nameResolver; }
/// <summary> /// Initializes a new instance of the <see cref="SnapshotReaderConfiguration"/> class. /// </summary> /// <param name="deserializer">The snapshot deserializer.</param> /// <param name="streamNameResolver">The snapshot stream name resolver.</param> /// <param name="streamUserCredentialsResolver">The snapshot stream user credentials resolver.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="deserializer"/> or <paramref name="streamNameResolver"/> or <paramref name="streamUserCredentialsResolver"/> is <c>null</c>.</exception> public SnapshotReaderConfiguration(ISnapshotDeserializer deserializer, IStreamNameResolver streamNameResolver, IStreamUserCredentialsResolver streamUserCredentialsResolver) { if (deserializer == null) throw new ArgumentNullException("deserializer"); if (streamNameResolver == null) throw new ArgumentNullException("streamNameResolver"); if (streamUserCredentialsResolver == null) throw new ArgumentNullException("streamUserCredentialsResolver"); _deserializer = deserializer; _streamNameResolver = streamNameResolver; _streamUserCredentialsResolver = streamUserCredentialsResolver; }
public Store( IEventStore eventStore, IEventDataFormatter eventDataFormatter, IServiceProvider services, IStreamNameResolver streamNameResolver) { this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.services = services; this.streamNameResolver = streamNameResolver; }
EventReaderConfigurationBuilder( SliceSize sliceSize, IEventDeserializer deserializer, IStreamNameResolver streamNameResolver, IStreamUserCredentialsResolver streamUserCredentialsResolver) { _sliceSize = sliceSize; _deserializer = deserializer; _streamNameResolver = streamNameResolver; _streamUserCredentialsResolver = streamUserCredentialsResolver; }
public Store( ISnapshotStore <T> snapshotStore, IEventStore eventStore, IEventDataFormatter eventDataFormatter, IStreamNameResolver streamNameResolver) { this.snapshotStore = snapshotStore; this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.streamNameResolver = streamNameResolver; }
/// <summary> /// Initializes a new instance of the <see cref="EventReaderConfiguration"/> class. /// </summary> /// <param name="sliceSize">Size of the slice to read.</param> /// <param name="deserializer">The event deserializer to use.</param> /// <param name="streamNameResolver">The stream name resolver to use.</param> /// <param name="streamUserCredentialsResolver">The stream user credentials resolver to use.</param> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="deserializer"/> or <paramref name="streamNameResolver"/> is <c>null</c>.</exception> public EventReaderConfiguration(SliceSize sliceSize, IEventDeserializer deserializer, IStreamNameResolver streamNameResolver, IStreamUserCredentialsResolver streamUserCredentialsResolver) { if (deserializer == null) throw new ArgumentNullException("deserializer"); if (streamNameResolver == null) throw new ArgumentNullException("streamNameResolver"); if (streamUserCredentialsResolver == null) throw new ArgumentNullException("streamUserCredentialsResolver"); _sliceSize = sliceSize; _deserializer = deserializer; _streamNameResolver = streamNameResolver; _streamUserCredentialsResolver = streamUserCredentialsResolver; }
/// <summary> /// Initializes a new instance of the <see cref="MongoEventStore"/> class. /// </summary> /// <param name="settings">The settings to configure behaviour of the instance.</param> public MongoEventStore(MongoEventStoreSettings settings) { _database = settings.Database; _collection = settings.Collection; _events = settings.Database.GetCollection <RecordedEventDocument>(settings.Collection); _serializer = settings.EventSerializer; _logger = settings.Logger; _clock = settings.Clock; _transactionOptions = settings.TransactionOptions; _streamNameResolver = settings.StreamNameResolver; _metadataFactory = settings.MetadataFactory; }
public Store( IEventStore eventStore, IEventDataFormatter eventDataFormatter, IServiceProvider services, IStreamNameResolver streamNameResolver, Action invalidate = null, Action failed = null) { this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.failed = failed; this.invalidate = invalidate; this.services = services; this.streamNameResolver = streamNameResolver; }
public Store( ISnapshotStore <T> snapshotStore, IEventStore eventStore, IEventDataFormatter eventDataFormatter, IStreamNameResolver streamNameResolver) { Guard.NotNull(snapshotStore, nameof(snapshotStore)); Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter)); Guard.NotNull(streamNameResolver, nameof(streamNameResolver)); this.snapshotStore = snapshotStore; this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.streamNameResolver = streamNameResolver; }
public Store( IEventStore eventStore, IEventDataFormatter eventDataFormatter, IServiceProvider services, IStreamNameResolver streamNameResolver) { Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter)); Guard.NotNull(services, nameof(services)); Guard.NotNull(streamNameResolver, nameof(streamNameResolver)); this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.services = services; this.streamNameResolver = streamNameResolver; }
public void SetUp() { EmbeddedEventStore.Connection.DeleteAllStreams(); _model = new Model(); _unitOfWork = new UnitOfWork(); _resolver = A.Fake <IStreamNameResolver>(); _reader = A.Fake <ISnapshotReader>(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptional(_model.KnownIdentifier)).Returns(Optional <Snapshot> .Empty); A.CallTo(() => _reader.ReadOptional(_model.UnknownIdentifier)).Returns(Optional <Snapshot> .Empty); _sut = new SnapshotableRepository <SnapshotableAggregateRootEntityStub>( SnapshotableAggregateRootEntityStub.Factory, _unitOfWork, EmbeddedEventStore.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
public Persistence(TKey ownerKey, IEventStore eventStore, IEventDataFormatter eventDataFormatter, ISnapshotStore <TSnapshot, TKey> snapshotStore, IStreamNameResolver streamNameResolver, PersistenceMode persistenceMode, Func <TSnapshot, Task> applyState, Func <Envelope <IEvent>, Task> applyEvent) { this.ownerKey = ownerKey; this.applyState = applyState; this.applyEvent = applyEvent; this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.persistenceMode = persistenceMode; this.snapshotStore = snapshotStore; this.streamNameResolver = streamNameResolver; }
/// <summary> /// Initializes a new instance of the <see cref="SnapshotReaderConfiguration"/> class. /// </summary> /// <param name="deserializer">The snapshot deserializer.</param> /// <param name="streamNameResolver">The snapshot stream name resolver.</param> /// <param name="streamUserCredentialsResolver">The snapshot stream user credentials resolver.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="deserializer"/> or <paramref name="streamNameResolver"/> or <paramref name="streamUserCredentialsResolver"/> is <c>null</c>.</exception> public SnapshotReaderConfiguration(ISnapshotDeserializer deserializer, IStreamNameResolver streamNameResolver, IStreamUserCredentialsResolver streamUserCredentialsResolver) { if (deserializer == null) { throw new ArgumentNullException("deserializer"); } if (streamNameResolver == null) { throw new ArgumentNullException("streamNameResolver"); } if (streamUserCredentialsResolver == null) { throw new ArgumentNullException("streamUserCredentialsResolver"); } _deserializer = deserializer; _streamNameResolver = streamNameResolver; _streamUserCredentialsResolver = streamUserCredentialsResolver; }
public Persistence(TKey ownerKey, Type ownerType, IEventStore eventStore, IEventDataFormatter eventDataFormatter, ISnapshotStore <TSnapshot, TKey> snapshotStore, IStreamNameResolver streamNameResolver, PersistenceMode persistenceMode, HandleSnapshot <TSnapshot> applyState, HandleEvent applyEvent) { this.ownerKey = ownerKey; this.ownerType = ownerType; this.applyState = applyState; this.applyEvent = applyEvent; this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.persistenceMode = persistenceMode; this.snapshotStore = snapshotStore; this.streamNameResolver = streamNameResolver; }
public void SetUp() { EmbeddedEventStore.Connection.DeleteAllStreams(); _model = new Model(); _unitOfWork = new ConcurrentUnitOfWork(); _resolver = A.Fake <IStreamNameResolver>(); _reader = A.Fake <IAsyncSnapshotReader>(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptionalAsync(_model.KnownIdentifier)) .Returns(Task.FromResult(new Optional <Snapshot>(new Snapshot(100, new object())))); A.CallTo(() => _reader.ReadOptionalAsync(_model.UnknownIdentifier)) .Returns(Task.FromResult(new Optional <Snapshot>(new Snapshot(100, new object())))); _sut = new AsyncSnapshotableRepository <SnapshotableAggregateRootEntityStub>( SnapshotableAggregateRootEntityStub.Factory, _unitOfWork, EmbeddedEventStore.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
/// <summary> /// Initializes a new instance of the <see cref="EventReaderConfiguration"/> class. /// </summary> /// <param name="sliceSize">Size of the slice to read.</param> /// <param name="deserializer">The event deserializer to use.</param> /// <param name="streamNameResolver">The stream name resolver to use.</param> /// <param name="streamUserCredentialsResolver">The stream user credentials resolver to use.</param> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="deserializer"/> or <paramref name="streamNameResolver"/> is <c>null</c>.</exception> public EventReaderConfiguration(SliceSize sliceSize, IEventDeserializer deserializer, IStreamNameResolver streamNameResolver, IStreamUserCredentialsResolver streamUserCredentialsResolver) { if (deserializer == null) { throw new ArgumentNullException("deserializer"); } if (streamNameResolver == null) { throw new ArgumentNullException("streamNameResolver"); } if (streamUserCredentialsResolver == null) { throw new ArgumentNullException("streamUserCredentialsResolver"); } _sliceSize = sliceSize; _deserializer = deserializer; _streamNameResolver = streamNameResolver; _streamUserCredentialsResolver = streamUserCredentialsResolver; }
public async Task ReadEventsAsync(IStreamNameResolver streamNameResolver, Func <StoredEvent, Task> handler) { Guard.NotNull(handler, nameof(handler)); Guard.NotNull(streamNameResolver, nameof(streamNameResolver)); while (true) { var eventEntry = archive.GetEntry(ArchiveHelper.GetEventPath(readEvents)); if (eventEntry == null) { break; } using (var stream = eventEntry.Open()) { using (var textReader = new StreamReader(stream)) { using (var jsonReader = new JsonTextReader(textReader)) { var storedEvent = Serializer.Deserialize <StoredEvent>(jsonReader); storedEvent.Data.Payload = guidMapper.NewGuids(storedEvent.Data.Payload); storedEvent.Data.Metadata = guidMapper.NewGuids(storedEvent.Data.Metadata); var streamName = streamNameResolver.WithNewId(storedEvent.StreamName, guidMapper.NewGuidString); storedEvent = new StoredEvent(streamName, storedEvent.EventPosition, storedEvent.EventStreamNumber, storedEvent.Data); await handler(storedEvent); } } } readEvents++; } }
public StateFactory( IPubSub pubSub, IMemoryCache statesCache, IEventStore eventStore, IEventDataFormatter eventDataFormatter, IServiceProvider services, IStreamNameResolver streamNameResolver) { Guard.NotNull(services, nameof(services)); Guard.NotNull(eventStore, nameof(eventStore)); Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter)); Guard.NotNull(pubSub, nameof(pubSub)); Guard.NotNull(statesCache, nameof(statesCache)); Guard.NotNull(streamNameResolver, nameof(streamNameResolver)); this.eventStore = eventStore; this.eventDataFormatter = eventDataFormatter; this.pubSub = pubSub; this.services = services; this.statesCache = statesCache; this.streamNameResolver = streamNameResolver; }
public async Task SetUp() { await EmbeddedEventStore.Connection.DeleteAllStreamsAsync(); _model = new Model(); _root = SnapshotableAggregateRootEntityStub.Factory(); _unitOfWork = new ConcurrentUnitOfWork(); _unitOfWork.Attach(new Aggregate(_model.KnownIdentifier, 0, _root)); _resolver = A.Fake <IStreamNameResolver>(); _reader = A.Fake <IAsyncSnapshotReader>(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptionalAsync(_model.KnownIdentifier)) .Returns(Task.FromResult(Optional <Snapshot> .Empty)); A.CallTo(() => _reader.ReadOptionalAsync(_model.UnknownIdentifier)) .Returns(Task.FromResult(Optional <Snapshot> .Empty)); _sut = new AsyncSnapshotableRepository <SnapshotableAggregateRootEntityStub>( SnapshotableAggregateRootEntityStub.Factory, _unitOfWork, EmbeddedEventStore.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
public static SnapshotReaderConfiguration CreateWithResolver(IStreamNameResolver resolver) { return new SnapshotReaderConfiguration(new SnapshotDeserializer(), resolver, new FixedStreamUserCredentialsResolver(new UserCredentials("admin", "changeit"))); }
private static async Task AppendToStream <T>(ConcurrentUnitOfWork uow, IEventStoreConnection connection, Now now, IStreamNameResolver getStreamName) where T : IAggregateRootEntity { foreach (Aggregate aggregate in uow.GetChanges()) { EventData[] changes = aggregate.Root.GetChanges() .Select(@event => new EventData( Guid.NewGuid(), @event.GetType().TypeQualifiedName(), true, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(@event)), Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new EventMetadata { TimeStamp = now(), AggregateType = typeof(T).Name, AggregateAssemblyQualifiedName = typeof(T).AssemblyQualifiedName, IsSnapshot = false })) )).ToArray(); try { await connection.AppendToStreamAsync(getStreamName.Resolve(aggregate.Identifier), aggregate.ExpectedVersion, changes); } catch (WrongExpectedVersionException) { StreamEventsSlice page = await connection.ReadStreamEventsBackwardAsync(aggregate.Identifier, -1, 1, false); throw new WrongExpectedStreamVersionException( $"Failed to append stream {aggregate.Identifier} with expected version {aggregate.ExpectedVersion}. " + $"{(page.Status == SliceReadStatus.StreamNotFound ? "Stream not found!" : $"Current Version: {page.LastEventNumber}")}"); } } }
public void SetUp() { EmbeddedEventStore.Instance.Connection.DeleteAllStreams(); _model = new Model(); _unitOfWork = new ConcurrentUnitOfWork(); _resolver = A.Fake<IStreamNameResolver>(); _reader = A.Fake<IAsyncSnapshotReader>(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptionalAsync(_model.KnownIdentifier)) .Returns(Task.FromResult(Optional<Snapshot>.Empty)); A.CallTo(() => _reader.ReadOptionalAsync(_model.UnknownIdentifier)) .Returns(Task.FromResult(Optional<Snapshot>.Empty)); _sut = new AsyncSnapshotableRepository<SnapshotableAggregateRootEntityStub>( SnapshotableAggregateRootEntityStub.Factory, _unitOfWork, EmbeddedEventStore.Instance.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
public void SetUp() { _model = new Model(); using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream)) { new EventStub(1).Write(writer); } EmbeddedEventStore.Instance.Connection.AppendToStream( _model.KnownIdentifier, ExpectedVersion.NoStream, new EventData( Guid.NewGuid(), typeof (EventStub).AssemblyQualifiedName, false, stream.ToArray(), new byte[0])); EmbeddedEventStore.Instance.Connection.AppendToStream( _model.KnownIdentifier, ExpectedVersion.Any, new EventData( Guid.NewGuid(), typeof (EventStub).AssemblyQualifiedName, false, stream.ToArray(), new byte[0])); } _root = SnapshotableAggregateRootEntityStub.Factory(); _state = new object(); _unitOfWork = new ConcurrentUnitOfWork(); _resolver = A.Fake<IStreamNameResolver>(); _reader = A.Fake<IAsyncSnapshotReader>(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptionalAsync(_model.KnownIdentifier)) .Returns(Task.FromResult(new Optional<Snapshot>(new Snapshot(1, _state)))); A.CallTo(() => _reader.ReadOptionalAsync(_model.UnknownIdentifier)) .Returns(Task.FromResult(new Optional<Snapshot>(new Snapshot(1, _state)))); _sut = new AsyncSnapshotableRepository<SnapshotableAggregateRootEntityStub>( () => _root, _unitOfWork, EmbeddedEventStore.Instance.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
public EventReaderConfigurationBuilder UsingStreamNameResolver(IStreamNameResolver value) { return new EventReaderConfigurationBuilder(_sliceSize, _deserializer, value, _streamUserCredentialsResolver); }
public static EventStoreReadConfiguration CreateWithResolver(IStreamNameResolver resolver) { return new EventStoreReadConfiguration(new SliceSize(1), new EventDeserializer(), resolver, new FixedStreamUserCredentialsResolver(new UserCredentials("admin", "changeit"))); }
public async Task SetUp() { await EmbeddedEventStore.Connection.DeleteAllStreamsAsync(); _model = new Model(); _root = SnapshotableAggregateRootEntityStub.Factory(); _unitOfWork = new ConcurrentUnitOfWork(); _unitOfWork.Attach(new Aggregate(_model.KnownIdentifier, 0, _root)); _resolver = A.Fake<IStreamNameResolver>(); _reader = A.Fake<IAsyncSnapshotReader>(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptionalAsync(_model.KnownIdentifier)) .Returns(Task.FromResult(new Optional<Snapshot>(new Snapshot(100, new object())))); A.CallTo(() => _reader.ReadOptionalAsync(_model.UnknownIdentifier)) .Returns(Task.FromResult(new Optional<Snapshot>(new Snapshot(100, new object())))); _sut = new AsyncSnapshotableRepository<SnapshotableAggregateRootEntityStub>( SnapshotableAggregateRootEntityStub.Factory, _unitOfWork, EmbeddedEventStore.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
public async Task SetUp() { await EmbeddedEventStore.Connection.DeleteAllStreamsAsync(); _model = new Model(); _unitOfWork = new UnitOfWork(); _resolver = A.Fake<IStreamNameResolver>(); _reader = A.Fake<ISnapshotReader>(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptional(_model.KnownIdentifier)).Returns(Optional<Snapshot>.Empty); A.CallTo(() => _reader.ReadOptional(_model.UnknownIdentifier)).Returns(Optional<Snapshot>.Empty); _sut = new SnapshotableRepository<SnapshotableAggregateRootEntityStub>( SnapshotableAggregateRootEntityStub.Factory, _unitOfWork, EmbeddedEventStore.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
public void SetUp() { EmbeddedEventStore.Instance.Connection.DeleteAllStreams(); _model = new Model(); _root = SnapshotableAggregateRootEntityStub.Factory(); _unitOfWork = new UnitOfWork(); _unitOfWork.Attach(new Aggregate(_model.KnownIdentifier, 0, _root)); _resolver = A.Fake<IStreamNameResolver>(); _reader = A.Fake<ISnapshotReader>(); _state = new object(); A.CallTo(() => _resolver.Resolve(_model.KnownIdentifier)).Returns(_model.KnownIdentifier); A.CallTo(() => _resolver.Resolve(_model.UnknownIdentifier)).Returns(_model.UnknownIdentifier); A.CallTo(() => _reader.ReadOptional(_model.KnownIdentifier)) .Returns(new Optional<Snapshot>(new Snapshot(100, _state))); A.CallTo(() => _reader.ReadOptional(_model.UnknownIdentifier)) .Returns(new Optional<Snapshot>(new Snapshot(100, _state))); _sut = new SnapshotableRepository<SnapshotableAggregateRootEntityStub>( SnapshotableAggregateRootEntityStub.Factory, _unitOfWork, EmbeddedEventStore.Instance.Connection, EventReaderConfigurationFactory.CreateWithResolver(_resolver), _reader); }
public SnapshotReaderConfigurationBuilder UsingStreamNameResolver(IStreamNameResolver value) { return new SnapshotReaderConfigurationBuilder(_deserializer, value, _streamUserCredentialsResolver); }