Пример #1
0
    public async Task <TEntity> GetByIdAsync(TKey id)
    {
        var streamId     = GenerateStreamId(id);
        var streamEvents = await EventStreamReader.Read(_connection, streamId, StreamPosition.Start, 200);

        var domainEvents = DomainEventFactory.Create(streamEvents, _eventTypeResolver);

        return(AggregateFactory.Create <TEntity>(domainEvents));
    }
Пример #2
0
        public async Task UpdateMultiple(
            bool pingFirst,
            bool injectPing)
        {
            // Arrange
            var readStoreManager = Resolver.Resolve <IReadStoreManager>();
            var thingyId         = ThingyId.New;
            var thingyMessage    = Fixture.Create <ThingyMessage>();
            var pingId           = PingId.New;
            var command          = new ThingyAddMessageAndPingCommand(
                thingyId,
                thingyMessage,
                pingId,
                pingFirst);
            var metadata = new Metadata
            {
                Timestamp = DateTimeOffset.Now,
                AggregateSequenceNumber = 1,
                AggregateName           = typeof(ThingyAggregate).GetAggregateName().Value,
                AggregateId             = thingyId.Value,
                EventId = EventId.New,
            };
            var domainEvent = injectPing
                ? DomainEventFactory.Create(new ThingyPingEvent(pingId), metadata, thingyId.Value, 1)
                : DomainEventFactory.Create(new ThingyMessageAddedEvent(thingyMessage), metadata, thingyId.Value, 1);
            await readStoreManager.UpdateReadStoresAsync(
                new[] { domainEvent },
                CancellationToken.None);

            // Act
            await CommandBus.PublishAsync(command, CancellationToken.None);

            // Assert
            var returnedThingyMessages = await QueryProcessor.ProcessAsync(new ThingyGetMessagesQuery(thingyId)).ConfigureAwait(false);

            returnedThingyMessages.Should().HaveCount(1);
            var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(thingyId)).ConfigureAwait(false);

            readModel.PingsReceived.Should().Be(1);
        }