/// <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 ExceptionCentricAggregateCommandTestResult Run(ExceptionCentricAggregateCommandTestSpecification 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) { 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 FailReturnsExpectedResult() { var result = _sut.Fail(); Assert.That(result.Specification, Is.SameAs(_sut)); 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 ExceptionCentricAggregateCommandTestResult Run(ExceptionCentricAggregateCommandTestSpecification 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) { 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 ExceptionCentricAggregateCommandTestResult Run(ExceptionCentricAggregateCommandTestSpecification 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) { 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()); }