示例#1
0
        public void GivenAnInstanceWhenNoChangesArePendingThenAllPropertiesAreSerialized()
        {
            var expectedId = Guid.NewGuid();
            var original   = new SerializableEventCentricAggregateRoot(expectedId);

            original.MarkChangesAsCommitted();

            SerializableEventCentricAggregateRoot deserialized = original.Clone();

            Assert.Equal(original, deserialized);
            Assert.NotSame(original, deserialized);

            Assert.Empty(deserialized.GetUncommittedChanges());
            Assert.Equal(expectedId, deserialized.Id);
            Assert.Equal(original.GetHashCode(), deserialized.GetHashCode());
        }
        public void GivenEventsStartingFromAPreviouslyCommittedVersionThenTheHydratedAggregateMatchesTheOriginal()
        {
            const ulong ExpectedVersionNumer = 4;

            var original = new SerializableEventCentricAggregateRoot();
            var context  = new SerializableMessage();

            _ = original.ApplyChanges(context, times: 1);

            SerializableEventCentricAggregateRoot hydrated = original.Clone();

            IEnumerable <DomainEvent> events = original.ApplyChanges(context);

            hydrated.LoadFromHistory(events);

            Assert.Equal(original, hydrated);
            Assert.Equal(original.Value, hydrated.Value);
            Assert.Equal(ExpectedVersionNumer, hydrated.Version.Number);
        }
示例#3
0
        public void GivenAnInstanceWhenChangesArePendingThenAllPropertiesAreSerialized()
        {
            var expectedId = Guid.NewGuid();
            var value      = Guid.NewGuid();
            var context    = new SerializableMessage();
            var request    = new SetRequest(context, value);
            var original   = new SerializableEventCentricAggregateRoot(expectedId);

            original.Set(request);

            SerializableEventCentricAggregateRoot deserialized = original.Clone();

            Assert.Equal(original, deserialized);
            Assert.NotSame(original, deserialized);

            Assert.Equal(original.GetUncommittedChanges(), deserialized.GetUncommittedChanges());
            Assert.Equal(expectedId, deserialized.Id);
            Assert.Equal(original.GetHashCode(), deserialized.GetHashCode());
        }