예제 #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 ExceptionCentricAggregateQueryTestResult Run(ExceptionCentricAggregateQueryTestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }

            var sut = specification.SutFactory();

            sut.Initialize(specification.Givens);

            object queryResult = null;
            var    result      = Catch.Exception(() => queryResult = specification.When(sut));

            if (!result.HasValue)
            {
                return(sut.HasChanges()
                    ? specification.Fail(sut.GetChanges().ToArray())
                    : specification.Fail(queryResult));
            }

            var actualException = result.Value;

            if (_comparer.Compare(actualException, specification.Throws).Any())
            {
                return(specification.Fail(actualException));
            }

            return(sut.HasChanges()
                ? specification.Fail(sut.GetChanges().ToArray())
                : specification.Pass());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionCentricTestResult"/> class.
 /// </summary>
 /// <param name="specification">The specification.</param>
 /// <param name="state">The state.</param>
 /// <param name="actualException">The actual exception.</param>
 /// <param name="actualEvents">The actual events.</param>
 /// <param name="actualResult">The actual result.</param>
 internal ExceptionCentricAggregateQueryTestResult(
     ExceptionCentricAggregateQueryTestSpecification specification, TestResultState state,
     Optional <Exception> actualException,
     Optional <object[]> actualEvents,
     Optional <object> actualResult)
 {
     Specification = specification;
     _state        = state;
     ButException  = actualException;
     ButEvents     = actualEvents;
     ButResult     = actualResult;
 }