/// <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> internal ExceptionCentricAggregateFactoryTestResult( ExceptionCentricAggregateFactoryTestSpecification specification, TestResultState state, Optional <Exception> actualException, Optional <object[]> actualEvents) { _specification = specification; _state = state; _actualException = actualException; _actualEvents = actualEvents; }
/// <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> internal ExceptionCentricAggregateFactoryTestResult( ExceptionCentricAggregateFactoryTestSpecification specification, TestResultState state, Optional<Exception> actualException, Optional<object[]> actualEvents) { _specification = specification; _state = state; _actualException = actualException; _actualEvents = actualEvents; }
public void SetUp() { Func <IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var givens = new[] { new object(), new object() }; Func <IAggregateRootEntity, IAggregateRootEntity> when = _ => new AggregateRootEntityStub(); var throws = new Exception(); _sut = new ExceptionCentricAggregateFactoryTestSpecification( sutFactory, givens, when, throws); }
public void RunReturnsExpectedResultWhenPassed() { var specification = new ExceptionCentricAggregateFactoryTestSpecification( () => new PassCase(), new object[0], _ => ((PassCase)_).Pass(), PassCase.TheException); 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 RunReturnsExpectedResultWhenFailedBecauseOfDifferentException() { var specification = new ExceptionCentricAggregateFactoryTestSpecification( () => new FailExceptionCase(), new object[0], _ => ((FailExceptionCase)_).Fail(), FailExceptionCase.TheExpectedException); var result = _sut.Run(specification); Assert.That(result.Passed, Is.False); Assert.That(result.Failed, Is.True); Assert.That(result.ButEvents, Is.EqualTo(Optional<object[]>.Empty)); Assert.That(result.ButException, Is.EqualTo(new Optional<Exception>(FailExceptionCase.TheActualException))); }
public void RunReturnsExpectedResultWhenFailedBecauseNoExceptionOccurred() { var specification = new ExceptionCentricAggregateFactoryTestSpecification( () => new FailNoExceptionCase(), new object[0], _ => ((FailNoExceptionCase)_).Fail(), FailNoExceptionCase.TheExpectedException); var result = _sut.Run(specification); Assert.That(result.Passed, Is.False); Assert.That(result.Failed, Is.True); 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 = _ => new AggregateRootEntityStub(); var throws = new Exception(); var sut = new ExceptionCentricAggregateFactoryTestSpecification( sutFactory, givens, when, throws); Assert.That(sut.SutFactory, Is.SameAs(sutFactory)); Assert.That(sut.Givens, Is.EquivalentTo(givens)); Assert.That(sut.When, Is.SameAs(when)); Assert.That(sut.Throws, Is.SameAs(throws)); }
/// <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(); }
public void SetUp() { Func<IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var givens = new[] { new object(), new object() }; Func<IAggregateRootEntity, IAggregateRootEntity> when = _ => new AggregateRootEntityStub(); var throws = new Exception(); _sut = new ExceptionCentricAggregateFactoryTestSpecification( sutFactory, givens, when, throws); }
public void UsingDefaultCtorReturnsInstanceWithExpectedProperties() { Func<IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var givens = new[] { new object(), new object() }; Func<IAggregateRootEntity, IAggregateRootEntity> when = _ => new AggregateRootEntityStub(); var throws = new Exception(); var sut = new ExceptionCentricAggregateFactoryTestSpecification( sutFactory, givens, when, throws); Assert.That(sut.SutFactory, Is.SameAs(sutFactory)); Assert.That(sut.Givens, Is.EquivalentTo(givens)); Assert.That(sut.When, Is.SameAs(when)); Assert.That(sut.Throws, Is.SameAs(throws)); }