private void WriteThrows(ExceptionCentricTestSpecification specification) { _writer.WriteLine("Throws"); _writer.Indent++; _writer.WriteLine("[{0}] {1}", specification.Throws.GetType().Name, specification.Throws.Message); _writer.Indent--; }
private void WriteGivens(ExceptionCentricTestSpecification specification) { if (specification.Givens.Length == 0) { return; } _writer.WriteLine("Given"); WriteFacts(specification.Givens); }
/// <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 ExceptionCentricTestResult( ExceptionCentricTestSpecification specification, TestResultState state, Optional <Exception> actualException, Optional <Fact[]> actualEvents) { Specification = specification; _state = state; ButException = actualException; ButEvents = actualEvents; }
private async Task <ExceptionCentricTestResult> RunAsync(ExceptionCentricTestSpecification spec) { var position = await _factWriter.PersistFacts(spec.Givens); var handleCommand = _handlerResolver.ResolveHandlerFor(spec.When); var result = await Catch.Exception(async() => await handleCommand(spec.When)); var actualEvents = await _factReader.RetrieveFacts(position); if (!result.HasValue) { return(actualEvents.Any() ? spec.Fail(actualEvents) : spec.Fail()); } var actualException = result.Value; return(_comparer.Compare(spec.Throws, actualException).Any() ? spec.Fail(actualException) : spec.Pass(actualException)); }
/// <summary> /// Determines whether the specified <see cref="ExceptionCentricTestSpecification" /> is equal to this instance. /// </summary> /// <param name="other">The <see cref="ExceptionCentricTestSpecification" /> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="ExceptionCentricTestSpecification" /> is equal to this instance; otherwise, <c>false</c>. /// </returns> protected bool Equals(ExceptionCentricTestSpecification other) => Equals(Givens, other.Givens) && Equals(When, other.When) && Equals(Throws, other.Throws);
public ExceptionCentricTestResult Run(ExceptionCentricTestSpecification specification) => RunAsync(specification).GetAwaiter().GetResult();
private void WriteWhen(ExceptionCentricTestSpecification specification) { _writer.WriteLine("When"); WriteMessage(specification.When); }
/// <summary> /// Writes the specified test specification. /// </summary> /// <param name="specification">The test specification to write.</param> public void Write(ExceptionCentricTestSpecification specification) { WriteGivens(specification); WriteWhen(specification); WriteThrows(specification); }