Пример #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 EventCentricAggregateCommandTestResult Run(EventCentricAggregateCommandTestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }
            var sut = specification.SutFactory();

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

            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>
 /// 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 EventCentricAggregateCommandTestResult Run(EventCentricAggregateCommandTestSpecification specification)
 {
     if (specification == null) throw new ArgumentNullException("specification");
     var sut = specification.SutFactory();
     sut.Initialize(specification.Givens);
     var result = Catch.Exception(() => specification.When(sut));
     if (result.HasValue)
     {
         return specification.Fail(result.Value);
     }
     var actualEvents = sut.GetChanges().ToArray();
     if (!actualEvents.SequenceEqual(specification.Thens, new WrappedEventComparerEqualityComparer(_comparer)))
     {
         return specification.Fail(actualEvents);
     }
     return specification.Pass();
 }
 public void FailEventsCanNotBeNull()
 {
     Assert.Throws <ArgumentNullException>(() => _sut.Fail((object[])null));
 }