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.ButEvents, Is.EqualTo(Optional <object[]> .Empty));
            Assert.That(result.ButException, Is.EqualTo(Optional <Exception> .Empty));
        }
Exemplo n.º 2
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());
        }
 /// <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("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())
         {
             return specification.Fail(factoryResult.GetChanges().ToArray());
         }
         return specification.Fail();
     }
     var actualException = result.Value;
     if (_comparer.Compare(actualException, specification.Throws).Any())
     {
         return specification.Fail(actualException);
     }
     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 ExceptionCentricAggregateFactoryTestResult Run(ExceptionCentricAggregateFactoryTestSpecification 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)
            {
                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();
        }