/// <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 ResultCentricAggregateQueryTestResult Run(ResultCentricAggregateQueryTestSpecification 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 specification.Fail(result.Value);
            }
#if NET20
            using (var enumerator = _comparer.Compare(queryResult, specification.Then).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    return specification.Fail(queryResult);
                }
            }
#else
            if (_comparer.Compare(queryResult, specification.Then).Any())
            {
                return specification.Fail(queryResult);
            }
#endif
            if (sut.HasChanges())
            {
#if NET20
                return specification.Fail(new List<object>(sut.GetChanges()));
#else
                return specification.Fail(sut.GetChanges().ToArray());
#endif
            }
            return specification.Pass();
        }
示例#2
0
        public void PassReturnsExpectedResult()
        {
            var result = _sut.Pass();

            Assert.That(result.Specification, Is.SameAs(_sut));
            Assert.That(result.Passed, Is.True);
            Assert.That(result.Failed, Is.False);
            Assert.That(result.ButResult, Is.EqualTo(Optional <object> .Empty));
            Assert.That(result.ButEvents, Is.EqualTo(Optional <object[]> .Empty));
            Assert.That(result.ButException, Is.EqualTo(Optional <Exception> .Empty));
        }
 /// <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 ResultCentricAggregateQueryTestResult Run(ResultCentricAggregateQueryTestSpecification 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 specification.Fail(result.Value);
     }
     if (_comparer.Compare(queryResult, specification.Then).Any())
     {
         return specification.Fail(queryResult);
     }
     if (sut.HasChanges())
     {
         return specification.Fail(sut.GetChanges().ToArray());
     }
     return specification.Pass();
 }
示例#4
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 ResultCentricAggregateQueryTestResult Run(ResultCentricAggregateQueryTestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException(nameof(specification));
            }
            var sut = specification.SutFactory();

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

            if (result.HasValue)
            {
                return(specification.Fail(result.Value));
            }
#if NET20
            using (var enumerator = _comparer.Compare(queryResult, specification.Then).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    return(specification.Fail(queryResult));
                }
            }
#else
            if (_comparer.Compare(queryResult, specification.Then).Any())
            {
                return(specification.Fail(queryResult));
            }
#endif
            if (sut.HasChanges())
            {
#if NET20
                return(specification.Fail(new List <object>(sut.GetChanges())));
#else
                return(specification.Fail(sut.GetChanges().ToArray()));
#endif
            }
            return(specification.Pass());
        }