public void GivenAnAggregateWithNoChangesThenTheChangesMarkedAsCommittedEventIsNotRaised()
        {
            bool wasInvoked = false;
            var  aggregate  = new SerializableAggregateRoot();

            aggregate.MarkChangesAsCommitted();
            aggregate.ChangesMarkedAsCommitted += (sender, e) => wasInvoked = true;
            aggregate.MarkChangesAsCommitted();

            Assert.False(wasInvoked);
        }
Example #2
0
        public async Task GivenAVersionedReferenceAndARequestForASpecificVersionWhenMoreThanOneVersionExistsThenTheRequestedVersionIsReturnedAsync()
        {
            var           aggregate    = new SerializableAggregateRoot();
            SignedVersion firstVersion = aggregate.Version;
            var           reference    = Reference.Create(aggregate);

            aggregate.MarkChangesAsCommitted();

            var context = new SerializableMessage();

            aggregate.Set();

            _ = repository
                .Setup(repo => repo.GetAsync(
                           It.Is <Guid>(id => id == aggregate.Id),
                           It.IsAny <CancellationToken?>(),
                           It.Is <SignedVersion>(v => v == firstVersion)))
                .ReturnsAsync(aggregate);

            AggregateRoot value = await repository.Object.GetAsync(context, reference, latest : false);

            repository.Verify(
                repo => repo.GetAsync(
                    It.IsAny <Guid>(),
                    It.IsAny <CancellationToken?>(),
                    It.IsAny <SignedVersion>()),
                Times.Once);

            Assert.Equal(aggregate, value);
        }
        public void GivenANewAggregateAndAnExistingVersionThatDoesNotConflictThenNoExceptionIsThrown()
        {
            var current = new SerializableAggregateRoot();

            current.MarkChangesAsCommitted();

            SerializableAggregateRoot proposed = current.Clone();

            proposed.Set();
            proposed.MarkChangesAsCommitted();

            AggregateDoesNotConflict(proposed, currentVersion: current.Version);
        }
        public async Task GivenAnAggregateWhenAnExistingMemberHasALowerVersionThenAnAggregateConflictDetectedExceptionIsThrownAsync()
        {
            var saved = new SerializableAggregateRoot();

            IRepository <SerializableAggregateRoot> repository =
                Create <SerializableAggregateRoot>();

            await repository.SaveAsync(saved);

            SerializableAggregateRoot pending = saved.Clone();

            pending.Set();
            pending.MarkChangesAsCommitted();
            pending.Set();
            pending.MarkChangesAsCommitted();

            AggregateConflictDetectedException <SerializableAggregateRoot> exception =
                await Assert.ThrowsAsync <AggregateConflictDetectedException <SerializableAggregateRoot> >(
                    () => repository.SaveAsync(pending));

            Assert.Equal(saved.Id, exception.Aggregate.Id);
            Assert.Equal(saved.Version, exception.Persisted);
        }
        public async Task GivenANonNewAnAggregateWhenNoExistingMemberWithTheSameIdExistsThenAnAggregateConflictDetectedExceptionIsThrownAsync()
        {
            var aggregate = new SerializableAggregateRoot();

            aggregate.MarkChangesAsCommitted();
            aggregate.Set();

            IRepository <SerializableAggregateRoot> repository =
                Create <SerializableAggregateRoot>();

            AggregateConflictDetectedException <SerializableAggregateRoot> exception =
                await Assert.ThrowsAsync <AggregateConflictDetectedException <SerializableAggregateRoot> >(
                    () => repository.SaveAsync(aggregate));

            Assert.Equal(aggregate.Id, exception.Aggregate.Id);
            Assert.Equal(SignedVersion.Empty, exception.Persisted);
        }