Beispiel #1
0
 public ProductCommandHandlers(
     GetStreamName getStreamName,
     AsyncRepository <Product> repository,
     AsyncSnapshotableRepository <Product> snapshotableRepository,
     Now now) : base(getStreamName, repository, snapshotableRepository, now)
 {
 }
Beispiel #2
0
        public static async Task UpdateWhen <T>(this AsyncSnapshotableRepository <T> repo, string identifier, Now now, Func <T, Task> when) where T : IAggregateRootEntity, ISnapshotable
        {
            T aggregate = await repo.GetAsync(identifier);

            await when(aggregate);

            await AppendToStream <T>(repo.UnitOfWork, repo.Connection, now, repo.Configuration.StreamNameResolver);
        }
Beispiel #3
0
 public CommandHandlerBase(
     GetStreamName getStreamName,
     AsyncRepository <T> repository,
     AsyncSnapshotableRepository <T> snapshotableRepository,
     Now now)
 {
     _repository             = repository;
     _now                    = now;
     _getStreamName          = getStreamName;
     _snapshotableRepository = snapshotableRepository;
 }
Beispiel #4
0
 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();
         EmbeddedEventStore.Connection.AppendToStreamAsync(
             _model.KnownIdentifier,
             ExpectedVersion.Any,
             new EventData(
                 Guid.NewGuid(),
                 typeof(EventStub).AssemblyQualifiedName,
                 false,
                 stream.ToArray(),
                 new byte[0])).Wait();
     }
     _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.Connection,
         EventReaderConfigurationFactory.CreateWithResolver(_resolver),
         _reader);
 }
Beispiel #5
0
 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(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);
 }
Beispiel #6
0
            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 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 AddVariantToProductCommandHandler(Now now, AsyncSnapshotableRepository <Product> snapshotableRepository)
 {
     _now = now;
     _snapshotableRepository = snapshotableRepository;
 }
 public AddContentToProductCommandHandler(AsyncSnapshotableRepository <Product> snapshotableRepository, Now now)
 {
     _snapshotableRepository = snapshotableRepository;
     _now = now;
 }
 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);
 }