Esempio n. 1
0
        public async Task StoredEventsAreAppliedIfThereAreMissingEvents()
        {
            // Arrange
            var thingyId      = A <ThingyId>();
            var emittedEvents = new[]
            {
                ToDomainEvent(thingyId, A <ThingyPingEvent>(), 3),
                ToDomainEvent(thingyId, A <ThingyPingEvent>(), 4),
            };
            var missingEvents = new[]
            {
                ToDomainEvent(thingyId, A <ThingyPingEvent>(), 2)
            };
            var storedEvents = Enumerable.Empty <IDomainEvent <ThingyAggregate, ThingyId> >()
                               .Concat(missingEvents)
                               .Concat(emittedEvents)
                               .ToArray();

            Arrange_ReadModelStore_UpdateAsync(ReadModelEnvelope <TReadModel> .With(
                                                   thingyId.Value,
                                                   A <TReadModel>(),
                                                   1));
            _eventStoreMock.Arrange_LoadEventsAsync(storedEvents);

            // Act
            await Sut.UpdateReadStoresAsync(emittedEvents, CancellationToken.None).ConfigureAwait(false);

            // Assert
            AppliedDomainEvents.Should().HaveCount(storedEvents.Length);
            AppliedDomainEvents.ShouldAllBeEquivalentTo(storedEvents);
        }
Esempio n. 2
0
        public void UpdateAsync_RetryForOptimisticConcurrencyExceptionsAreDone()
        {
            // Arrange
            _eventStoreMock.Arrange_LoadEventsAsync();
            Arrange_EventStore_StoreAsync_ThrowsOptimisticConcurrencyException();

            // Act
            Assert.ThrowsAsync <OptimisticConcurrencyException>(async() => await Sut.UpdateAsync <ThingyAggregate, ThingyId>(
                                                                    A <ThingyId>(),
                                                                    A <ISourceId>(),
                                                                    NoOperationAsync,
                                                                    CancellationToken.None)
                                                                .ConfigureAwait(false));

            // Assert
            _eventStoreMock.Verify(
                s => s.StoreAsync <ThingyAggregate, ThingyId>(
                    It.IsAny <ThingyId>(),
                    It.IsAny <IReadOnlyCollection <IUncommittedEvent> >(),
                    It.IsAny <ISourceId>(),
                    It.IsAny <CancellationToken>()),
                Times.Exactly(6));
        }