/// <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 ExceptionCentricAggregateConstructorTestResult Run(ExceptionCentricAggregateConstructorTestSpecification specification) { if (specification == null) throw new ArgumentNullException("specification"); IAggregateRootEntity sut = null; var result = Catch.Exception(() => sut = specification.SutFactory()); if (!result.HasValue) { if (sut.HasChanges()) { #if NET20 return specification.Fail(new List<object>(sut.GetChanges()).ToArray()); #else return specification.Fail(sut.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> sutConstructor = () => (IAggregateRootEntity)null; var throws = new Exception(); _sut = new ExceptionCentricAggregateConstructorTestSpecification( sutConstructor, throws); }
/// <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 ExceptionCentricAggregateConstructorTestResult( ExceptionCentricAggregateConstructorTestSpecification 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 ExceptionCentricAggregateConstructorTestResult( ExceptionCentricAggregateConstructorTestSpecification specification, TestResultState state, Optional <Exception> actualException, Optional <object[]> actualEvents) { _specification = specification; _state = state; _actualException = actualException; _actualEvents = actualEvents; }
public void RunReturnsExpectedResultWhenPassed() { var specification = new ExceptionCentricAggregateConstructorTestSpecification( () => new PassCase(), 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 ExceptionCentricAggregateConstructorTestSpecification( () => new FailExceptionCase(), 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 UsingDefaultCtorReturnsInstanceWithExpectedProperties() { Func <IAggregateRootEntity> sutConstructor = () => (IAggregateRootEntity)null; var throws = new Exception(); var sut = new ExceptionCentricAggregateConstructorTestSpecification( sutConstructor, throws); Assert.That(sut.SutFactory, Is.SameAs(sutConstructor)); Assert.That(sut.Throws, Is.SameAs(throws)); }
public void RunReturnsExpectedResultWhenFailedBecauseNoExceptionOccurred() { var specification = new ExceptionCentricAggregateConstructorTestSpecification( () => new FailNoExceptionCase(), 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)); }
/// <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 ExceptionCentricAggregateConstructorTestResult Run(ExceptionCentricAggregateConstructorTestSpecification specification) { if (specification == null) throw new ArgumentNullException("specification"); IAggregateRootEntity sut = null; var result = Catch.Exception(() => sut = specification.SutFactory()); if (!result.HasValue) { if (sut.HasChanges()) { return specification.Fail(sut.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 ExceptionCentricAggregateConstructorTestResult Run(ExceptionCentricAggregateConstructorTestSpecification specification) { if (specification == null) { throw new ArgumentNullException("specification"); } IAggregateRootEntity sut = null; var result = Catch.Exception(() => sut = specification.SutFactory()); if (!result.HasValue) { if (sut.HasChanges()) { #if NET20 return(specification.Fail(new List <object>(sut.GetChanges()).ToArray())); #else return(specification.Fail(sut.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> sutConstructor = () => (IAggregateRootEntity)null; var throws = new Exception(); _sut = new ExceptionCentricAggregateConstructorTestSpecification( sutConstructor, throws); }
public void UsingDefaultCtorReturnsInstanceWithExpectedProperties() { Func<IAggregateRootEntity> sutConstructor = () => (IAggregateRootEntity)null; var throws = new Exception(); var sut = new ExceptionCentricAggregateConstructorTestSpecification( sutConstructor, throws); Assert.That(sut.SutFactory, Is.SameAs(sutConstructor)); Assert.That(sut.Throws, Is.SameAs(throws)); }