public async Task SaveEvents_does_not_insert_pending_event_entities_if_fails_to_insert_correlation_entities()
        {
            // Arrange
            var fixture = new Fixture();
            var user    = new FakeUser(Guid.NewGuid(), fixture.Create <string>());

            user.ChangeUsername(fixture.Create <string>());
            IList <IDomainEvent> domainEvents = user.FlushPendingEvents().ToList();
            var correlationId = Guid.NewGuid();

            var batch = new TableBatchOperation();

            batch.Insert(new TableEntity
            {
                PartitionKey = AggregateEntity.GetPartitionKey(typeof(FakeUser), user.Id),
                RowKey       = Correlation.GetRowKey(correlationId),
            });
            await s_eventTable.ExecuteBatchAsync(batch);

            // Act
            Func <Task> action = () => _sut.SaveEvents <FakeUser>(domainEvents, correlationId: correlationId);

            // Assert
            action.ShouldThrow <DuplicateCorrelationException>();
            string filter = PendingEvent.GetFilter(typeof(FakeUser), user.Id);
            var    query  = new TableQuery <PendingEvent> {
                FilterString = filter
            };
            IEnumerable <PendingEvent> actual = await s_eventTable.ExecuteQuerySegmentedAsync(query, default);

            actual.Should().BeEmpty();
        }
示例#2
0
        public void Create_sets_PartitionKey_correctly()
        {
            Type sourceType    = new Fixture().Create <Type>();
            var  sourceId      = Guid.NewGuid();
            var  correlationId = Guid.NewGuid();

            var actual = Correlation.Create(sourceType, sourceId, correlationId);

            actual.PartitionKey.Should().Be(AggregateEntity.GetPartitionKey(sourceType, sourceId));
        }
示例#3
0
        public void GetPartitionKey_returns_combination_of_source_type_name_and_source_id()
        {
            IFixture fixture    = new Fixture().Customize(new AutoMoqCustomization());
            Type     sourceType = fixture.Create <IEventSourced>().GetType();
            Guid     sourceId   = fixture.Create <Guid>();

            string actual = AggregateEntity.GetPartitionKey(sourceType, sourceId);

            actual.Should().Be($"{sourceType.Name}-{sourceId:n}");
        }
示例#4
0
        public Task FlushPendingEvents <T>(
            Guid sourceId,
            CancellationToken cancellationToken = default)
            where T : class, IEventSourced
        {
            if (sourceId == Guid.Empty)
            {
                throw new ArgumentException(
                          $"{sourceId} cannot be empty.", nameof(sourceId));
            }

            string partition = AggregateEntity.GetPartitionKey(typeof(T), sourceId);

            return(Flush(partition, cancellationToken));
        }
        public void Create_sets_PartitionKey_correctly()
        {
            IFixture        fixture     = new Fixture();
            Type            sourceType  = fixture.Create <Type>();
            SomeDomainEvent domainEvent = fixture.Create <SomeDomainEvent>();

            TestContext.WriteLine($"SourceId: {domainEvent.SourceId}");
            fixture.Inject <IDomainEvent>(domainEvent);

            var actual = PersistentEvent.Create(
                sourceType,
                fixture.Create <Envelope <IDomainEvent> >(),
                new JsonMessageSerializer());

            actual.PartitionKey.Should().Be(AggregateEntity.GetPartitionKey(sourceType, domainEvent.SourceId));
        }