/// <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 ResultCentricAggregateQueryTestResult Run(ResultCentricAggregateQueryTestSpecification specification) { if (specification == null) throw new ArgumentNullException("specification"); var sut = specification.SutFactory(); sut.Initialize(specification.Givens); object queryResult = null; var result = Catch.Exception(() => queryResult = specification.When(sut)); if (result.HasValue) { return specification.Fail(result.Value); } #if NET20 using (var enumerator = _comparer.Compare(queryResult, specification.Then).GetEnumerator()) { if (enumerator.MoveNext()) { return specification.Fail(queryResult); } } #else if (_comparer.Compare(queryResult, specification.Then).Any()) { return specification.Fail(queryResult); } #endif if (sut.HasChanges()) { #if NET20 return specification.Fail(new List<object>(sut.GetChanges())); #else return specification.Fail(sut.GetChanges().ToArray()); #endif } return specification.Pass(); }
/// <summary> /// Initializes a new instance of the <see cref="ResultCentricAggregateQueryTestResult"/> class. /// </summary> /// <param name="specification">The specification.</param> /// <param name="state">The state.</param> /// <param name="actualResult">The actual result.</param> /// <param name="actualException">The actual exception.</param> /// <param name="actualEvents">The actual events.</param> internal ResultCentricAggregateQueryTestResult(ResultCentricAggregateQueryTestSpecification specification, TestResultState state, Optional <object> actualResult, Optional <Exception> actualException, Optional <object[]> actualEvents) { _specification = specification; _state = state; _actualResult = actualResult; _actualException = actualException; _actualEvents = actualEvents; }
/// <summary> /// Initializes a new instance of the <see cref="ResultCentricAggregateQueryTestResult"/> class. /// </summary> /// <param name="specification">The specification.</param> /// <param name="state">The state.</param> /// <param name="actualResult">The actual result.</param> /// <param name="actualException">The actual exception.</param> /// <param name="actualEvents">The actual events.</param> internal ResultCentricAggregateQueryTestResult(ResultCentricAggregateQueryTestSpecification specification, TestResultState state, Optional<object> actualResult, Optional<Exception> actualException, Optional<object[]> actualEvents) { _specification = specification; _state = state; _actualResult = actualResult; _actualException = actualException; _actualEvents = actualEvents; }
public void SetUp() { Func <IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var givens = new[] { new object(), new object() }; var result = new object(); Func <IAggregateRootEntity, object> when = _ => result; var then = result; _sut = new ResultCentricAggregateQueryTestSpecification( sutFactory, givens, when, then); }
public void RunReturnsExpectedResultWhenPassed() { var specification = new ResultCentricAggregateQueryTestSpecification( () => new PassCase(), new object[0], _ => ((PassCase)_).Pass(), PassCase.TheResult); 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)); Assert.That(result.ButResult, Is.EqualTo(Optional<int>.Empty)); }
public void RunReturnsExpectedResultWhenFailedBecauseDifferentResult() { var specification = new ResultCentricAggregateQueryTestSpecification( () => new FailResultCase(), new object[0], _ => ((FailResultCase)_).Fail(), FailResultCase.TheExpectedResult); 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)); Assert.That(result.ButResult, Is.EqualTo(new Optional<int>(FailResultCase.TheActualResult))); }
public void RunReturnsExpectedResultWhenFailedBecauseDifferentResult() { var specification = new ResultCentricAggregateQueryTestSpecification( () => new FailResultCase(), new object[0], _ => ((FailResultCase)_).Fail(), FailResultCase.TheExpectedResult); 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)); Assert.That(result.ButResult, Is.EqualTo(new Optional <int>(FailResultCase.TheActualResult))); }
public void RunReturnsExpectedResultWhenPassed() { var specification = new ResultCentricAggregateQueryTestSpecification( () => new PassCase(), new object[0], _ => ((PassCase)_).Pass(), PassCase.TheResult); 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)); Assert.That(result.ButResult, Is.EqualTo(Optional <int> .Empty)); }
public void UsingDefaultCtorReturnsInstanceWithExpectedProperties() { Func <IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var givens = new[] { new object(), new object() }; var result = new object(); Func <IAggregateRootEntity, object> when = _ => result; var then = result; var sut = new ResultCentricAggregateQueryTestSpecification( sutFactory, givens, when, then); Assert.That(sut.SutFactory, Is.SameAs(sutFactory)); Assert.That(sut.Givens, Is.EquivalentTo(givens)); Assert.That(sut.When, Is.SameAs(when)); Assert.That(sut.Then, Is.SameAs(then)); }
/// <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 ResultCentricAggregateQueryTestResult Run(ResultCentricAggregateQueryTestSpecification specification) { if (specification == null) throw new ArgumentNullException("specification"); var sut = specification.SutFactory(); sut.Initialize(specification.Givens); object queryResult = null; var result = Catch.Exception(() => queryResult = specification.When(sut)); if (result.HasValue) { return specification.Fail(result.Value); } if (_comparer.Compare(queryResult, specification.Then).Any()) { return specification.Fail(queryResult); } if (sut.HasChanges()) { return specification.Fail(sut.GetChanges().ToArray()); } 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 ResultCentricAggregateQueryTestResult Run(ResultCentricAggregateQueryTestSpecification specification) { if (specification == null) { throw new ArgumentNullException(nameof(specification)); } var sut = specification.SutFactory(); sut.Initialize(specification.Givens); object queryResult = null; var result = Catch.Exception(() => queryResult = specification.When(sut)); if (result.HasValue) { return(specification.Fail(result.Value)); } #if NET20 using (var enumerator = _comparer.Compare(queryResult, specification.Then).GetEnumerator()) { if (enumerator.MoveNext()) { return(specification.Fail(queryResult)); } } #else if (_comparer.Compare(queryResult, specification.Then).Any()) { return(specification.Fail(queryResult)); } #endif if (sut.HasChanges()) { #if NET20 return(specification.Fail(new List <object>(sut.GetChanges()))); #else return(specification.Fail(sut.GetChanges().ToArray())); #endif } return(specification.Pass()); }
public void UsingDefaultCtorReturnsInstanceWithExpectedProperties() { Func<IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var givens = new[] { new object(), new object() }; var result = new object(); Func<IAggregateRootEntity, object> when = _ => result; var then = result; var sut = new ResultCentricAggregateQueryTestSpecification( sutFactory, givens, when, then); Assert.That(sut.SutFactory, Is.SameAs(sutFactory)); Assert.That(sut.Givens, Is.EquivalentTo(givens)); Assert.That(sut.When, Is.SameAs(when)); Assert.That(sut.Then, Is.SameAs(then)); }
public void SetUp() { Func<IAggregateRootEntity> sutFactory = () => (IAggregateRootEntity)null; var givens = new[] { new object(), new object() }; var result = new object(); Func<IAggregateRootEntity, object> when = _ => result; var then = result; _sut = new ResultCentricAggregateQueryTestSpecification( sutFactory, givens, when, then); }