Example #1
0
        public void GivenTheAggregateAndTheEventAggregateThenAnInstanceIsReturnedWithAllPropertiesSet()
        {
            var subject        = new SerializableAggregateRoot();
            var aggregate      = subject.ToReference();
            var eventAggregate = subject.ToReference();
            var instance       = new AggregateEventMismatchException(aggregate, eventAggregate);

            Assert.Equal(aggregate, instance.Aggregate);
            Assert.Equal(eventAggregate, instance.EventAggregate);
        }
Example #2
0
        public void GivenAnInstanceThenAllPropertiesAreSerialized()
        {
            var       subject        = new SerializableAggregateRoot();
            Reference aggregate      = subject.ToReference();
            Reference eventAggregate = subject.ToReference();
            var       original       = new AggregateEventMismatchException(aggregate, eventAggregate);
            AggregateEventMismatchException deserialized = original.Clone();

            Assert.NotSame(original, deserialized);
            Assert.Equal(original.Aggregate, deserialized.Aggregate);
            Assert.Equal(original.EventAggregate, deserialized.EventAggregate);
        }
        public void GivenAnAggregateThenAnInstanceIsReturnedWithTheAggregateReferenceSet()
        {
            var aggregate = new SerializableAggregateRoot();
            var instance  = new SerializableProjection <SerializableAggregateRoot>(aggregate);
            var expected  = aggregate.ToReference();

            Assert.Equal(expected, instance.Aggregate);
        }
        public void GivenAVersionedReferenceThatDoesNotExistsThenNoEntryIsReturned()
        {
            var aggregate = new SerializableAggregateRoot();
            var reference = aggregate.ToReference();

            bool exists = Dictionary.TryGetValue(reference, out _);

            Assert.False(exists);
        }
Example #5
0
        public void GivenAMatchingReferenceThenANegativeResponseIsReturned()
        {
            var aggregate = new SerializableAggregateRoot();
            var first     = new SerializableProjection <SerializableAggregateRoot>(aggregate);
            var second    = aggregate.ToReference();

            Assert.False(first != second);
            Assert.False(second != first);
        }
Example #6
0
        public void GivenATypedReferenceThenTheIdOfThatReferenceIsReturned()
        {
            var  aggregate = new SerializableAggregateRoot();
            var  reference = aggregate.ToReference();
            Type type      = reference;

            Assert.Equal(reference.Type, type);
            Assert.Equal(typeof(SerializableAggregateRoot), type);
        }
        public void GivenAMatchingReferenceThenAPositiveResponseIsReturned()
        {
            var aggregate = new SerializableAggregateRoot();
            var first     = new SerializableProjection <SerializableAggregateRoot>(aggregate);
            var second    = aggregate.ToReference();

            Assert.True(first == second);
            Assert.True(first.Equals(second));
            Assert.True(second == first);
        }
Example #8
0
        public void GivenAnAggregateAndAContextThenAnInstanceIsReturnedWithAllPropertiesSet()
        {
            var subject   = new SerializableAggregateRoot();
            var aggregate = subject.ToReference();
            var context   = new SerializableMessage();
            var instance  = new AggregateVersionNotFoundException <SerializableAggregateRoot>(context, aggregate);

            Assert.Equal(aggregate, instance.Aggregate);
            Assert.Equal(context, instance.Context);
        }
        public void GivenAUnTypedReferenceThenTheReferenceIsReturned()
        {
            var       aggregate = new SerializableAggregateRoot();
            Reference original  = aggregate.ToReference();

            _ = info.TryAddReference(nameof(original), original);
            Reference retrieved = info.TryGetReference(nameof(original));

            Assert.Equal(original, retrieved);
        }
Example #10
0
        public void GivenNoAggregateAndTheEventAggregateThenAnArgumentNullExceptionIsThrown()
        {
            var       subject        = new SerializableAggregateRoot();
            Reference?aggregate      = default;
            var       eventAggregate = subject.ToReference();

            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(
                () => new AggregateEventMismatchException(aggregate !, eventAggregate));

            Assert.Equal(nameof(aggregate), exception.ParamName);
        }
Example #11
0
        public void GivenAnReferenceThenTheVersionOfThatReferenceIsReturned()
        {
            var           aggregate = new SerializableAggregateRoot();
            var           reference = aggregate.ToReference();
            SignedVersion version   = reference;

            Assert.Equal(reference.Version, version);
            Assert.Equal(aggregate.Version, version);
            Assert.False(version.IsEmpty);
            Assert.True(version.IsNew);
        }
Example #12
0
        public void GivenAVersionedReferenceThatDoesNotExistThenTheEntryIsAddedWithAnUnversionedReference()
        {
            var aggregate = new SerializableAggregateRoot();
            var reference = aggregate.ToReference();

            Dictionary.Add(reference, aggregate);

            Assert.Contains(Dictionary.Values, element => element == aggregate);
            Assert.Contains(Dictionary.Keys, element => element == reference);
            Assert.DoesNotContain(Dictionary.Keys, element => element.IsVersioned);
        }
Example #13
0
        public void GivenAnAggregateAndANullReceivedVersionTheAnArgumentNullExceptionIsThrown()
        {
            var           subject   = new SerializableAggregateRoot();
            var           aggregate = subject.ToReference();
            SignedVersion?received  = default;

            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(
                () => new AggregateConflictDetectedException <SerializableAggregateRoot>(aggregate, received !));

            Assert.Equal(nameof(received), exception.ParamName);
        }
Example #14
0
        public void GivenAnAggregateAndANullContextThenAnArgumentNullExceptionIsThrown()
        {
            var     subject   = new SerializableAggregateRoot();
            var     aggregate = subject.ToReference();
            Message?context   = default;

            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(
                () => new AggregateVersionNotFoundException <SerializableAggregateRoot>(context !, aggregate));

            Assert.Equal(nameof(context), exception.ParamName);
        }
        public void GivenAnAbstractAggregateThenAReferenceWithTheSameIdTypeAndVersionIsReturned()
        {
            var           aggregateId = Guid.NewGuid();
            AggregateRoot aggregate   = new SerializableAggregateRoot(aggregateId);

            var reference = aggregate.ToReference();

            Assert.Equal(aggregateId, reference.Id);
            Assert.Equal(aggregate.Version, reference.Version);
            Assert.Equal(typeof(SerializableAggregateRoot), reference.Type);
        }
Example #16
0
        public void GivenAVersionedReferenceThatExistThenAPositiveResponseIsReturned()
        {
            var aggregate = new SerializableAggregateRoot();
            var reference = aggregate.ToReference();
            var item      = new KeyValuePair <Reference <SerializableAggregateRoot>, SerializableAggregateRoot>(reference, aggregate);

            Dictionary.Add(item);

            bool exists = Dictionary.Contains(item);

            Assert.True(exists);
        }
Example #17
0
        public void GivenATypedUnversionedReferenceThenTheSameInstanceIsReturned()
        {
            var aggregate = new SerializableAggregateRoot();

            var       original    = aggregate.ToReference(unversioned: true);
            Reference unversioned = original.ToUnversioned();

            Assert.Equal(original, unversioned);
            Assert.Same(original, unversioned);
            Assert.False(original.IsVersioned);
            Assert.False(unversioned.IsVersioned);
        }
Example #18
0
        public void GivenAnAggregateAndAReceivedVersionTheAnInstanceIsReturnedWithAllPropertiesSet()
        {
            var           subject   = new SerializableAggregateRoot();
            var           aggregate = subject.ToReference();
            SignedVersion received  = subject.Version;

            var instance = new AggregateConflictDetectedException <SerializableAggregateRoot>(aggregate, received);

            Assert.Equal(aggregate, instance.Aggregate);
            Assert.Equal(received, instance.Received);
            Assert.Equal(SignedVersion.Empty, instance.Persisted);
        }
        public void GivenAnAggregateWhenUnversionedIsTrueThenAReferenceWithTheSameIdAndTypeIsReturned()
        {
            var aggregateId = Guid.NewGuid();
            var aggregate   = new SerializableAggregateRoot(aggregateId);

            var reference = aggregate.ToReference(unversioned: true);

            Assert.Equal(aggregateId, reference.Id);
            Assert.False(reference.IsVersioned);
            Assert.NotEqual(aggregate.Version, reference.Version);
            Assert.Equal(typeof(SerializableAggregateRoot), reference.Type);
        }
        public void GivenAnInstanceThenAllPropertiesAreSerialized()
        {
            var subject   = new SerializableAggregateRoot();
            var aggregate = subject.ToReference();
            var context   = new SerializableMessage();
            var original  = new AggregateVersionNotFoundException <SerializableAggregateRoot>(context, aggregate);
            AggregateVersionNotFoundException <SerializableAggregateRoot> deserialized = original.Clone();

            Assert.NotSame(original, deserialized);
            Assert.Equal(original.Aggregate, deserialized.Aggregate);
            Assert.Equal(original.Context, deserialized.Context);
        }
        public void GivenAUnTypedReferenceThenTheValueIsAddedWithAPrefixedName()
        {
            var       aggregate = new SerializableAggregateRoot();
            Reference reference = aggregate.ToReference();
            bool      added     = info.TryAddReference(nameof(reference), reference);
            IDictionary <string, object?> contents = info.ToDictionary();

            _ = contents.TryGetValue(nameof(reference), out object?actual);

            Assert.True(added);
            Assert.NotEmpty(contents);
            Assert.Equal(reference, actual);
        }
        protected UnversionedReferenceDictionaryTests()
        {
            FirstAggregate  = new SerializableAggregateRoot();
            SecondAggregate = new SerializableAggregateRoot();
            FirstReference  = FirstAggregate.ToReference();
            SecondReference = SecondAggregate.Id.ToReference <SerializableAggregateRoot>(version: SecondAggregate.Version.Next());

            Dictionary = new UnversionedReferenceDictionary <SerializableAggregateRoot, SerializableAggregateRoot>
            {
                { FirstReference, FirstAggregate },
                { SecondReference, SecondAggregate },
            };
        }
Example #23
0
        public void GivenAProjectionDictionaryThenAnUnversionedIsReturned()
        {
            var first  = new SerializableAggregateRoot();
            var second = new SerializableAggregateRoot();

            var versioned = new Dictionary <Reference <SerializableAggregateRoot>, SerializableProjection <SerializableAggregateRoot> >
            {
                { first.ToReference(), new SerializableProjection <SerializableAggregateRoot>(first) },
                { second.ToReference(), new SerializableProjection <SerializableAggregateRoot>(second) },
            };

            IDictionary <Reference <SerializableAggregateRoot>, SerializableProjection <SerializableAggregateRoot> > unversioned
                = versioned.ToUnversioned();

            Assert.Equal(versioned.Count, unversioned.Count);
            Assert.Contains(versioned, entry => unversioned.Contains(entry));
            Assert.DoesNotContain(unversioned, element => element.Key.IsVersioned);
        }