/// <summary>
 /// Initializes a new instance of the <see cref="AsyncRepository{TAggregateRoot}"/> class.
 /// </summary>
 /// <param name="rootFactory">The aggregate root entity factory.</param>
 /// <param name="unitOfWork">The unit of work to interact with.</param>
 /// <param name="connection">The event store connection to use.</param>
 /// <param name="configuration">The event store configuration to use.</param>
 /// <param name="reader">The snapshot reader to use.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="rootFactory"/> or <paramref name="unitOfWork"/> or <paramref name="connection"/> or <paramref name="configuration"/> or <paramref name="reader"/> is null.</exception>
 public AsyncSnapshotableRepository(Func <TAggregateRoot> rootFactory, ConcurrentUnitOfWork unitOfWork,
                                    IEventStoreConnection connection, EventReaderConfiguration configuration,
                                    IAsyncSnapshotReader reader)
 {
     if (rootFactory == null)
     {
         throw new ArgumentNullException("rootFactory");
     }
     if (unitOfWork == null)
     {
         throw new ArgumentNullException("unitOfWork");
     }
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     if (configuration == null)
     {
         throw new ArgumentNullException("configuration");
     }
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     _rootFactory   = rootFactory;
     _unitOfWork    = unitOfWork;
     _connection    = connection;
     _configuration = configuration;
     _reader        = reader;
 }
Esempio n. 2
0
        public IdempotentCommandHandlerModuleProcessor(
            Func <IAddresses> getAddresses,
            ConcurrentUnitOfWork concurrentUnitOfWork,
            IPersistentLocalIdGenerator persistentLocalIdGenerator,
            Func <IStreamStore> getStreamStore,
            EventMapping eventMapping,
            EventSerializer eventSerializer,
            AddressProvenanceFactory addressProvenanceFactory,
            CrabAddressProvenanceFactory crabProvenanceFactory,
            AddressPersistentLocalIdentifierProvenanceFactory addressPersistentLocalIdentifierProvenanceFactory)
        {
            _getAddresses         = getAddresses;
            _concurrentUnitOfWork = concurrentUnitOfWork;
            _provenanceFactory    = crabProvenanceFactory.CreateFrom;
            _addressPersistentLocalIdProvenanceFactory = addressPersistentLocalIdentifierProvenanceFactory.CreateFrom;

            _addressCommandHandlerModule = new AddressCommandHandlerModule(
                _getAddresses,
                () => concurrentUnitOfWork,
                persistentLocalIdGenerator,
                getStreamStore,
                eventMapping,
                eventSerializer,
                addressProvenanceFactory,
                crabProvenanceFactory,
                addressPersistentLocalIdentifierProvenanceFactory);
        }
Esempio n. 3
0
        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}")}");
                }
            }
        }
Esempio n. 4
0
        public IdempotentCommandHandlerModuleProcessor(
            Func <IParcels> getParcels,
            IParcelFactory parcelFactory,
            ConcurrentUnitOfWork concurrentUnitOfWork,
            Func <IStreamStore> getStreamStore,
            EventMapping eventMapping,
            EventSerializer eventSerializer,
            ParcelProvenanceFactory provenanceFactory)
        {
            _getParcels           = getParcels;
            _parcelFactory        = parcelFactory;
            _concurrentUnitOfWork = concurrentUnitOfWork;
            _provenanceFactory    = provenanceFactory.CreateFrom;

            var fixGrar1475ProvenanceFactory = new FixGrar1475ProvenanceFactory();

            _fixGrar1475ProvenanceFactory = fixGrar1475ProvenanceFactory.CreateFrom;

            var fixGrar1637ProvenanceFactory = new FixGrar1637ProvenanceFactory();

            _fixGrar1637ProvenanceFactory = fixGrar1637ProvenanceFactory.CreateFrom;

            _parcelCommandHandlerModule = new ParcelCommandHandlerModule(
                getParcels,
                parcelFactory,
                () => concurrentUnitOfWork,
                getStreamStore,
                eventMapping,
                eventSerializer,
                provenanceFactory,
                fixGrar1475ProvenanceFactory,
                fixGrar1637ProvenanceFactory);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="AsyncRepository{TAggregateRoot}" /> class.
 /// </summary>
 /// <param name="rootFactory">The aggregate root entity factory.</param>
 /// <param name="unitOfWork">The unit of work to interact with.</param>
 /// <param name="connection">The event store connection to use.</param>
 /// <param name="configuration">The event store configuration to use.</param>
 /// <exception cref="System.ArgumentNullException">
 ///     Thrown when the <paramref name="rootFactory" /> or
 ///     <paramref name="unitOfWork" /> or <paramref name="connection" /> or <paramref name="configuration" /> is null.
 /// </exception>
 public AsyncRepository(Func <TAggregateRoot> rootFactory, ConcurrentUnitOfWork unitOfWork,
                        IEventStoreConnection connection, EventReaderConfiguration configuration)
 {
     RootFactory   = rootFactory ?? throw new ArgumentNullException(nameof(rootFactory));
     UnitOfWork    = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
     Connection    = connection ?? throw new ArgumentNullException(nameof(connection));
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
Esempio n. 6
0
 public void SetUp()
 {
     _store             = new InMemoryStreamStore(() => DateTime.UtcNow);
     _unitOfWork        = new ConcurrentUnitOfWork();
     _factory           = AggregateRootEntityStub.Factory;
     _eventDeserializer = new EventDeserializer(SimpleJson.DeserializeObject);
     _eventMapping      = new EventMapping(new Dictionary <string, Type>());
 }
 public void SetUp()
 {
     _connection = EmbeddedEventStore.Instance.Connection;
     _reader = AsyncSnapshotReaderFactory.Create();
     _configuration = EventReaderConfigurationFactory.Create();
     _unitOfWork = new ConcurrentUnitOfWork();
     _factory = SnapshotableAggregateRootEntityStub.Factory;
 }
Esempio n. 8
0
 public void SetUp()
 {
     _connection    = EmbeddedEventStore.Connection;
     _reader        = AsyncSnapshotReaderFactory.Create();
     _configuration = EventReaderConfigurationFactory.Create();
     _unitOfWork    = new ConcurrentUnitOfWork();
     _factory       = SnapshotableAggregateRootEntityStub.Factory;
 }
Esempio n. 9
0
 public void Setup()
 {
     _aggregate1 = AggregateStubs.Create(new ChangedAggregateRootEntityStub());
     _aggregate2 = AggregateStubs.Create(new ChangedAggregateRootEntityStub());
     _sut        = new ConcurrentUnitOfWork();
     _sut.Attach(_aggregate1);
     _sut.Attach(_aggregate2);
 }
 public RepositoryScenarioBuilder(EventMapping eventMapping, EventDeserializer eventDeserializer)
 {
     _eventStore         = new InMemoryStreamStore(() => DateTime.UtcNow);
     _unitOfWork         = new ConcurrentUnitOfWork();
     _eventStoreSchedule = new List <Action <IStreamStore> >();
     _unitOfWorkSchedule = new List <Action <ConcurrentUnitOfWork> >();
     _eventMapping       = eventMapping;
     _eventDeserializer  = eventDeserializer;
 }
Esempio n. 11
0
 public Repository(
     Func <TAggregateRoot> factory,
     ConcurrentUnitOfWork unitOfWork,
     IStreamStore eventStore,
     EventMapping eventMapping,
     EventDeserializer eventDeserializer)
     : base(factory, unitOfWork, eventStore, eventMapping, eventDeserializer)
 {
 }
 public RepositoryScenarioBuilder(IStreamStore connection)
 {
     _unitOfWork                   = new UnitOfWork();
     _connection                   = connection;
     _concurrentUnitOfWork         = new ConcurrentUnitOfWork();
     _eventStoreSchedule           = new List <Action <IStreamStore> >();
     _unitOfWorkSchedule           = new List <Action <UnitOfWork> >();
     _concurrentUnitOfWorkSchedule = new List <Action <ConcurrentUnitOfWork> >();
     _deserializer                 = new EventDeserializer();
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="AsyncRepository{TAggregateRoot}" /> class.
 /// </summary>
 /// <param name="rootFactory">The aggregate root entity factory.</param>
 /// <param name="unitOfWork">The unit of work to interact with.</param>
 /// <param name="connection">The event store connection to use.</param>
 /// <param name="configuration">The event store configuration to use.</param>
 /// <param name="reader">The snapshot reader to use.</param>
 /// <exception cref="System.ArgumentNullException">
 ///     Thrown when the <paramref name="rootFactory" /> or
 ///     <paramref name="unitOfWork" /> or <paramref name="connection" /> or <paramref name="configuration" /> or
 ///     <paramref name="reader" /> is null.
 /// </exception>
 public AsyncSnapshotableRepository(Func <TAggregateRoot> rootFactory, ConcurrentUnitOfWork unitOfWork,
                                    IEventStoreConnection connection, EventReaderConfiguration configuration,
                                    IAsyncSnapshotReader reader)
 {
     _rootFactory   = rootFactory ?? throw new ArgumentNullException(nameof(rootFactory));
     _unitOfWork    = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
     _connection    = connection ?? throw new ArgumentNullException(nameof(connection));
     _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _reader        = reader ?? throw new ArgumentNullException(nameof(reader));
 }
 public RepositoryScenarioBuilder()
 {
     _connection = EmbeddedEventStore.Connection;
     _unitOfWork = new UnitOfWork();
     _concurrentUnitOfWork = new ConcurrentUnitOfWork();
     _eventReaderConfiguration = EventReaderConfigurationFactory.Create();
     _snapshotReaderConfiguration = SnapshotReaderConfigurationFactory.Create();
     _eventStoreSchedule = new List<Action<IEventStoreConnection>>();
     _unitOfWorkSchedule = new List<Action<UnitOfWork>>();
     _concurrentUnitOfWorkSchedule = new List<Action<ConcurrentUnitOfWork>>();
 }
Esempio n. 15
0
 public RepositoryScenarioBuilder()
 {
     _connection                   = EmbeddedEventStore.Instance.Connection;
     _unitOfWork                   = new UnitOfWork();
     _concurrentUnitOfWork         = new ConcurrentUnitOfWork();
     _eventReaderConfiguration     = EventReaderConfigurationFactory.Create();
     _snapshotReaderConfiguration  = SnapshotReaderConfigurationFactory.Create();
     _eventStoreSchedule           = new List <Action <IEventStoreConnection> >();
     _unitOfWorkSchedule           = new List <Action <UnitOfWork> >();
     _concurrentUnitOfWorkSchedule = new List <Action <ConcurrentUnitOfWork> >();
 }
 public AsyncRepository(
     Func <TAggregateRoot> rootFactory,
     ConcurrentUnitOfWork unitOfWork,
     IStreamStore eventStore,
     IEventDeserializer deserializer)
 {
     RootFactory       = rootFactory ?? throw new ArgumentNullException(nameof(rootFactory));
     UnitOfWork        = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
     EventStore        = eventStore ?? throw new ArgumentNullException(nameof(eventStore));
     EventDeserializer = deserializer ?? throw new ArgumentNullException(nameof(deserializer));
 }
Esempio n. 17
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);
 }
        public IdempotentCommandHandlerModuleProcessor(
            Func <IStreetNames> getStreetNames,
            ConcurrentUnitOfWork concurrentUnitOfWork,
            Func <IStreamStore> getStreamStore,
            EventMapping eventMapping,
            EventSerializer eventSerializer,
            StreetNameProvenanceFactory provenanceFactory)
        {
            _getStreetNames       = getStreetNames;
            _concurrentUnitOfWork = concurrentUnitOfWork;
            _provenanceFactory    = provenanceFactory.CreateFrom;

            _streetNameCommandHandlerModule = new StreetNameCommandHandlerModule(
                getStreetNames,
                () => concurrentUnitOfWork,
                getStreamStore,
                eventMapping,
                eventSerializer,
                provenanceFactory);
        }
Esempio n. 19
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);
 }
        private async Task InitProjections()
        {
            IEventStoreConnection esConnection = await GetEsConnection();

            Func <IBucket> getBucket = GetCouchbaseBucket();

            Func <string, Task <Aggregate> > getProductAggregate = async streamId =>
            {
                var defaultSerializer    = new DefaultEventDeserializer();
                var concurrentUnitOfWork = new ConcurrentUnitOfWork();

                var productRepository = new AsyncRepository <Product>(
                    Product.Factory,
                    concurrentUnitOfWork,
                    esConnection,
                    new EventReaderConfiguration(
                        new SliceSize(500),
                        defaultSerializer,
                        new TypedStreamNameResolver(typeof(Product), s_sGetStreamName),
                        new NoStreamUserCredentialsResolver()));

                await productRepository.GetAsync(streamId);

                return(concurrentUnitOfWork.GetChanges().First());
            };

            await ProjectionManagerBuilder.With
            .Connection(esConnection)
            .Deserializer(new DefaultEventDeserializer())
            .CheckpointStore(new CouchbaseCheckpointStore(getBucket))
            .Snaphotter(
                new EventStoreSnapshotter <Aggregate, ProductSnapshot>(
                    getProductAggregate,
                    () => esConnection,
                    e => e.Event.EventNumber > 0 && e.Event.EventNumber % 5 == 0,
                    stream => $"{stream}-Snapshot",
                    s_sNow))
            .Projections(
                ProjectorDefiner.For <ProductProjection>()
                ).Activate(getBucket);
        }
        private static async Task CreateSnapshot(
            ISnapshotable snapshotSupport,
            SnapshotStrategyContext context,
            IStreamStore streamStore,
            ConcurrentUnitOfWork uow,
            EventMapping eventMapping,
            EventSerializer eventSerializer,
            CancellationToken ct)
        {
            if (!snapshotSupport.Strategy.ShouldCreateSnapshot(context))
            {
                return;
            }

            var snapshot = snapshotSupport.TakeSnapshot();

            if (snapshot == null)
            {
                throw new InvalidOperationException("Snapshot missing.");
            }

            var snapshotContainer = new SnapshotContainer
            {
                Data = eventSerializer.SerializeObject(snapshot),
                Info =
                {
                    Type     = eventMapping.GetEventName(snapshot.GetType()),
                    Position = context.SnapshotPosition
                }
            };

            await streamStore.AppendToStream(
                uow.GetSnapshotIdentifier(context.Aggregate.Identifier),
                ExpectedVersion.Any,
                new NewStreamMessage(
                    Deterministic.Create(Deterministic.Namespaces.Events, $"snapshot-{context.SnapshotPosition}"),
                    $"SnapshotContainer<{snapshotContainer.Info.Type}>",
                    eventSerializer.SerializeObject(snapshotContainer)),
                ct);
        }
Esempio n. 22
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);
            }
Esempio n. 23
0
 public Parcels(ConcurrentUnitOfWork unitOfWork, IStreamStore eventStore, EventMapping eventMapping, EventDeserializer eventDeserializer)
     : base(Parcel.Factory, unitOfWork, eventStore, eventMapping, eventDeserializer)
 {
 }
 public void Setup()
 {
     _sut = new ConcurrentUnitOfWork();
 }
Esempio n. 25
0
 public Parcels(IParcelFactory parcelFactory, ConcurrentUnitOfWork unitOfWork, IStreamStore eventStore, EventMapping eventMapping, EventDeserializer eventDeserializer)
     : base(parcelFactory.Create, unitOfWork, eventStore, eventMapping, eventDeserializer)
 {
 }
Esempio n. 26
0
 public Municipalities(ConcurrentUnitOfWork unitOfWork, IStreamStore eventStore, EventMapping eventMapping, EventDeserializer eventDeserializer)
     : base(Municipality.Factory, unitOfWork, eventStore, eventMapping, eventDeserializer)
 {
 }
 public void Setup()
 {
     _aggregate = AggregateStubs.Stub1;
     _sut = new ConcurrentUnitOfWork();
     _sut.Attach(_aggregate);
 }
 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 ExampleAggregates(ConcurrentUnitOfWork unitOfWork, IStreamStore eventStore, EventMapping eventMapping, EventDeserializer eventDeserializer)
     : base(ExampleAggregate.Factory, unitOfWork, eventStore, eventMapping, eventDeserializer)
 {
 }
 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 void Setup()
 {
     _aggregate1 = AggregateStubs.Create(new ChangedAggregateRootEntityStub());
     _aggregate2 = AggregateStubs.Create(new ChangedAggregateRootEntityStub());
     _sut = new ConcurrentUnitOfWork();
     _sut.Attach(_aggregate1);
     _sut.Attach(_aggregate2);
 }
Esempio n. 32
0
 public StreetNames(ConcurrentUnitOfWork unitOfWork, IStreamStore eventStore, EventMapping eventMapping, EventDeserializer eventDeserializer)
     : base(StreetName.Factory, unitOfWork, eventStore, eventMapping, eventDeserializer)
 {
 }
Esempio n. 33
0
 public void Setup()
 {
     _sut = new ConcurrentUnitOfWork();
 }
 public PostalInformationSet(ConcurrentUnitOfWork unitOfWork, IStreamStore eventStore, EventMapping eventMapping, EventDeserializer eventDeserializer)
     : base(PostalInformation.Factory, unitOfWork, eventStore, eventMapping, eventDeserializer)
 {
 }
Esempio n. 35
0
 public void Setup()
 {
     _aggregate = AggregateStubs.Stub1;
     _sut       = new ConcurrentUnitOfWork();
     _sut.Attach(_aggregate);
 }
Esempio n. 36
0
 public Accounts(ConcurrentUnitOfWork unitOfWork, IStreamStore eventStore, EventMapping eventMapping, EventDeserializer eventDeserializer)
     : base(Account.Factory, unitOfWork, eventStore, eventMapping, eventDeserializer)
 {
 }
 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 RepositoryScenarioBuilder WithUnitOfWork(ConcurrentUnitOfWork value)
 {
     _unitOfWork = value;
     return(this);
 }