Esempio n. 1
0
        /// <summary>
        /// Runs the specified test specification.
        /// </summary>
        /// <param name="specification">The test specification to run.</param>
        /// <returns>
        /// The result of running the test specification.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="specification"/> is <c>null</c>.</exception>
        public EventCentricAggregateFactoryTestResult Run(EventCentricAggregateFactoryTestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }
            var sut = specification.SutFactory();

            sut.Initialize(specification.Givens);
            IAggregateRootEntity factoryResult = null;
            var result = Catch.Exception(() => factoryResult = specification.When(sut));

            if (result.HasValue)
            {
                return(specification.Fail(result.Value));
            }
#if NET20
            var actualEvents = new List <object>(factoryResult.GetChanges()).ToArray();
            if (!actualEvents.SequenceEqual(specification.Thens, new WrappedEventComparerEqualityComparer(_comparer)))
            {
                return(specification.Fail(actualEvents));
            }
#else
            var actualEvents = factoryResult.GetChanges().ToArray();
            if (!actualEvents.SequenceEqual(specification.Thens, new WrappedEventComparerEqualityComparer(_comparer)))
            {
                return(specification.Fail(actualEvents));
            }
#endif
            return(specification.Pass());
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateBuilder"/> class.
 /// </summary>
 /// <param name="instance">The aggregate instance to copy data from.</param>
 internal AggregateBuilder(Aggregate instance)
 {
     _identifier      = instance.Identifier;
     _expectedVersion = instance.ExpectedVersion;
     _root            = instance.Root;
     _partition       = instance.Partition;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateBuilder"/> class.
 /// </summary>
 public AggregateBuilder()
 {
     _partition = Aggregate.DefaultPartition;
     _identifier = null;
     _expectedVersion = Int32.MinValue;
     _root = null;
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateBuilder"/> class.
 /// </summary>
 public AggregateBuilder()
 {
     _partition       = Aggregate.DefaultPartition;
     _identifier      = null;
     _expectedVersion = Int32.MinValue;
     _root            = null;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateBuilder"/> class.
 /// </summary>
 /// <param name="instance">The aggregate instance to copy data from.</param>
 internal AggregateBuilder(Aggregate instance)
 {
     _identifier = instance.Identifier;
     _expectedVersion = instance.ExpectedVersion;
     _root = instance.Root;
     _partition = instance.Partition;
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="identifier">The aggregate identifier.</param>
 /// <param name="expectedVersion">The expected aggregate version.</param>
 /// <param name="root">The aggregate root entity.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="identifier"/> is null.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="root"/> is null.</exception>
 public Aggregate(string identifier, int expectedVersion, IAggregateRootEntity root)
 {
     if (identifier == null)
         throw new ArgumentNullException("identifier");
     if (root == null)
         throw new ArgumentNullException("root");
     _identifier = identifier;
     _expectedVersion = expectedVersion;
     _root = root;
 }
Esempio n. 7
0
        private static Dictionary <string, object> PrepareHeaders(IAggregateRootEntity aggregate, Action <IDictionary <string, object> > updateHeaders)
        {
            var headers = new Dictionary <string, object>();

            headers[AggregateTypeHeader] = aggregate.GetType().FullName;
            if (updateHeaders != null)
            {
                updateHeaders(headers);
            }

            return(headers);
        }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="identifier">The aggregate identifier.</param>
 /// <param name="expectedVersion">The expected aggregate version.</param>
 /// <param name="root">The aggregate root entity.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="identifier"/> is null.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="root"/> is null.</exception>
 public Aggregate(string identifier, int expectedVersion, IAggregateRootEntity root)
 {
     if (identifier == null)
     {
         throw new ArgumentNullException("identifier");
     }
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     _identifier      = identifier;
     _expectedVersion = expectedVersion;
     _root            = root;
 }
Esempio n. 9
0
        /// <summary>
        /// Runs the specified test specification.
        /// </summary>
        /// <param name="specification">The test specification to run.</param>
        /// <returns>
        /// The result of running the test specification.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="specification"/> is <c>null</c>.</exception>
        public ExceptionCentricAggregateFactoryTestResult Run(ExceptionCentricAggregateFactoryTestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException(nameof(specification));
            }
            var sut = specification.SutFactory();

            sut.Initialize(specification.Givens);
            IAggregateRootEntity factoryResult = null;
            var result = Catch.Exception(() => factoryResult = specification.When(sut));

            if (!result.HasValue)
            {
                if (factoryResult.HasChanges())
                {
#if NET20
                    return(specification.Fail(new List <object>(factoryResult.GetChanges()).ToArray()));
#else
                    return(specification.Fail(factoryResult.GetChanges().ToArray()));
#endif
                }
                return(specification.Fail());
            }
            var actualException = result.Value;
#if NET20
            using (var enumerator = _comparer.Compare(actualException, specification.Throws).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    return(specification.Fail(actualException));
                }
            }
#else
            if (_comparer.Compare(actualException, specification.Throws).Any())
            {
                return(specification.Fail(actualException));
            }
#endif
            return(specification.Pass());
        }
Esempio n. 10
0
        /// <summary>
        /// Runs the specified test specification.
        /// </summary>
        /// <param name="specification">The test specification to run.</param>
        /// <returns>
        /// The result of running the test specification.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="specification"/> is <c>null</c>.</exception>
        public EventCentricAggregateConstructorTestResult Run(EventCentricAggregateConstructorTestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException(nameof(specification));
            }
            IAggregateRootEntity sut = null;
            var result = Catch.Exception(() => sut = specification.SutFactory());

            if (result.HasValue)
            {
                return(specification.Fail(result.Value));
            }
#if NET20
            var actualEvents = new List <object>(sut.GetChanges()).ToArray();
#else
            var actualEvents = sut.GetChanges().ToArray();
#endif
            if (!actualEvents.SequenceEqual(specification.Thens, new WrappedEventComparerEqualityComparer(_comparer)))
            {
                return(specification.Fail(actualEvents));
            }
            return(specification.Pass());
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="Aggregate" /> class.
 /// </summary>
 /// <param name="identifier">The aggregate identifier.</param>
 /// <param name="expectedVersion">The expected aggregate version.</param>
 /// <param name="root">The aggregate root entity.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="identifier" /> is null.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="root" /> is null.</exception>
 public Aggregate(string identifier, int expectedVersion, IAggregateRootEntity root)
 {
     Identifier      = identifier ?? throw new ArgumentNullException(nameof(identifier));
     ExpectedVersion = expectedVersion;
     Root            = root ?? throw new ArgumentNullException(nameof(root));
 }
Esempio n. 12
0
 /// <summary>
 ///     Captures the aggregate root entity of the aggregate.
 /// </summary>
 /// <param name="value">The aggregate root entity value.</param>
 /// <returns>An <see cref="AggregateBuilder" /> instance.</returns>
 public AggregateBuilder WithRoot(IAggregateRootEntity value)
 {
     Root = value;
     return(this);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateBuilder"/> class.
 /// </summary>
 public AggregateBuilder()
 {
     _identifier      = null;
     _expectedVersion = Int32.MinValue;
     _root            = null;
 }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="identifier">The aggregate identifier.</param>
 /// <param name="expectedVersion">The expected aggregate version.</param>
 /// <param name="root">The aggregate root entity.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="identifier"/> is null.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="root"/> is null.</exception>
 public Aggregate(string identifier, int expectedVersion, IAggregateRootEntity root)
     : this(DefaultPartition, identifier, expectedVersion, root)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="identifier">The aggregate identifier.</param>
 /// <param name="expectedVersion">The expected aggregate version.</param>
 /// <param name="root">The aggregate root entity.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="identifier"/> is null.</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="root"/> is null.</exception>
 public Aggregate(string identifier, int expectedVersion, IAggregateRootEntity root)
     : this(DefaultPartition, identifier, expectedVersion, root)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateBuilder"/> class.
 /// </summary>
 public AggregateBuilder()
 {
     _identifier = null;
     _expectedVersion = Int32.MinValue;
     _root = null;
 }
 /// <summary>
 /// Captures the aggregate root entity of the aggregate.
 /// </summary>
 /// <param name="value">The aggregate root entity value.</param>
 /// <returns>An <see cref="AggregateBuilder"/> instance.</returns>
 public AggregateBuilder WithRoot(IAggregateRootEntity value)
 {
     _root = value;
     return this;
 }