Exemple #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());
        }
Exemple #2
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 EventCentricAggregateCommandTestResult(
     EventCentricAggregateCommandTestSpecification 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 EventCentricAggregateCommandTestResult(
     EventCentricAggregateCommandTestSpecification 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() };
            Action <IAggregateRootEntity> when = _ => { };
            var thens = new[] { new object(), new object() };

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

            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.TheEvents)));
            Assert.That(result.ButException, Is.EqualTo(Optional<Exception>.Empty));
        }
        public void RunReturnsExpectedResultWhenFailedBecauseOfDifferentContentOfEvents()
        {
            var specification = new EventCentricAggregateCommandTestSpecification(
                () => new FailEventCase(),
                new object[0],
                _ => ((FailEventCase)_).Fail(),
                new [] { new object() });

            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.TheEvents)));
            Assert.That(result.ButException, Is.EqualTo(Optional <Exception> .Empty));
        }
        public void RunReturnsExpectedResultWhenPassed()
        {
            var specification = new EventCentricAggregateCommandTestSpecification(
                () => new PassCase(),
                new object[0],
                _ => { },
                new object[0]);

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

            var sut = new EventCentricAggregateCommandTestSpecification(
                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 RunReturnsExpectedResultWhenPassed()
        {
            var specification = new EventCentricAggregateCommandTestSpecification(
                () => new PassCase(),
                new object[0],
                _ => { },
                new object[0]);

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

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

            var sut = new EventCentricAggregateCommandTestSpecification(
                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));
        }