/// <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();
        }
示例#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 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());
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventCentricTestResult"/> class.
 /// </summary>
 /// <param name="specification">The specification.</param>
 /// <param name="state">The state.</param>
 /// <param name="actualEvents">The actual events.</param>
 /// <param name="actualException">The actual exception.</param>
 internal EventCentricAggregateFactoryTestResult(
     EventCentricAggregateFactoryTestSpecification specification,
     TestResultState state,
     Optional <object[]> actualEvents,
     Optional <Exception> actualException)
 {
     _specification   = specification;
     _state           = state;
     _actualEvents    = actualEvents;
     _actualException = actualException;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventCentricTestResult"/> class.
 /// </summary>
 /// <param name="specification">The specification.</param>
 /// <param name="state">The state.</param>
 /// <param name="actualEvents">The actual events.</param>
 /// <param name="actualException">The actual exception.</param>
 internal EventCentricAggregateFactoryTestResult(
     EventCentricAggregateFactoryTestSpecification specification, 
     TestResultState state,
     Optional<object[]> actualEvents, 
     Optional<Exception> actualException)
 {
     _specification = specification;
     _state = state;
     _actualEvents = actualEvents;
     _actualException = actualException;
 }
        public void SetUp()
        {
            Func <IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null;
            var givens = new[] { new object(), new object() };
            Func <IAggregateRootEntity, IAggregateRootEntity> when = _ => null;
            var thens = new[] { new object(), new object() };

            _sut = new EventCentricAggregateFactoryTestSpecification(
                sutFactory,
                givens,
                when,
                thens);
        }
        public void RunReturnsExpectedResultWhenFailedBecauseOfNoEvents()
        {
            var specification = new EventCentricAggregateFactoryTestSpecification(
                () => new FailNoEventCase(),
                new object[0],
                _ => ((FailNoEventCase)_).Fail(),
                FailNoEventCase.TheExpectedEvents);

            var result = _sut.Run(specification);
            Assert.That(result.Passed, Is.False);
            Assert.That(result.Failed, Is.True);
            Assert.That(result.ButEvents, Is.EqualTo(new Optional<object[]>(FailNoEventCase.TheActualEvents)));
            Assert.That(result.ButException, Is.EqualTo(Optional<Exception>.Empty));
        }
示例#7
0
        public void RunReturnsExpectedResultWhenFailedBecauseOfDifferentContentOfEvents()
        {
            var specification = new EventCentricAggregateFactoryTestSpecification(
                () => new FailEventCase(),
                new object[0],
                _ => ((FailEventCase)_).Fail(),
                FailEventCase.TheExpectedEvents);

            var result = _sut.Run(specification);

            Assert.That(result.Passed, Is.False);
            Assert.That(result.Failed, Is.True);
            Assert.That(result.ButEvents, Is.EqualTo(new Optional <object[]>(FailEventCase.TheActualEvents)));
            Assert.That(result.ButException, Is.EqualTo(Optional <Exception> .Empty));
        }
示例#8
0
        public void RunReturnsExpectedResultWhenPassed()
        {
            var specification = new EventCentricAggregateFactoryTestSpecification(
                () => new PassCase(),
                new object[0],
                _ => ((PassCase)_).Pass(),
                PassCase.TheExpectedEvents);

            var result = _sut.Run(specification);

            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));
        }
        public void UsingDefaultCtorReturnsInstanceWithExpectedProperties()
        {
            Func <IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null;
            var givens = new[] { new object(), new object() };
            Func <IAggregateRootEntity, IAggregateRootEntity> when = _ => null;
            var thens = new[] { new object(), new object() };

            var sut = new EventCentricAggregateFactoryTestSpecification(
                sutFactory,
                givens,
                when,
                thens);

            Assert.That(sut.SutFactory, Is.SameAs(sutFactory));
            Assert.That(sut.Givens, Is.EquivalentTo(givens));
            Assert.That(sut.When, Is.SameAs(when));
            Assert.That(sut.Thens, Is.EquivalentTo(thens));
        }
        public void SetUp()
        {
            Func<IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null;
            var givens = new[] { new object(), new object() };
            Func<IAggregateRootEntity, IAggregateRootEntity> when = _ => null;
            var thens = new[] { new object(), new object() };

            _sut = new EventCentricAggregateFactoryTestSpecification(
                sutFactory,
                givens,
                when,
                thens);
        }
        public void UsingDefaultCtorReturnsInstanceWithExpectedProperties()
        {
            Func<IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null;
            var givens = new[] { new object(), new object() };
            Func<IAggregateRootEntity, IAggregateRootEntity> when = _ => null;
            var thens = new[] { new object(), new object() };

            var sut = new EventCentricAggregateFactoryTestSpecification(
                sutFactory,
                givens,
                when,
                thens);

            Assert.That(sut.SutFactory, Is.SameAs(sutFactory));
            Assert.That(sut.Givens, Is.EquivalentTo(givens));
            Assert.That(sut.When, Is.SameAs(when));
            Assert.That(sut.Thens, Is.EquivalentTo(thens));
        }