public void GivenAnInstanceThenAllPropertiesAreSerialized()
        {
            var original = new SerializableAggregateRoot();
            SerializableAggregateRoot deserialized = original.Clone();

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

            Assert.Equal(original.Id, deserialized.Id);
            Assert.Equal(original.Version, deserialized.Version);
            Assert.Equal(original.GetHashCode(), deserialized.GetHashCode());
        }
        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 GivenAnAggregateWhenAnExistingMemberHasAHigherVersionThenAnAggregateConflictDetectedExceptionIsThrownAsync()
        {
            var saved = new SerializableAggregateRoot();

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

            await repository.SaveAsync(saved);

            SerializableAggregateRoot pending = saved.Clone();

            saved.Set();

            await repository.SaveAsync(saved);

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

            Assert.Equal(saved.Id, exception.Aggregate.Id);
            Assert.Equal(saved.Version, exception.Persisted);
        }