private void WriteGivens(EventCentricTestSpecification specification) { if (specification.Givens.Length == 0) { return; } _writer.WriteLine("Given"); WriteFacts(specification.Givens); }
/// <summary> /// Initializes a new instance of the <see cref="EventCentricTestResult"/> class. /// </summary> /// <param name="specification">The specification.</param> /// <param name="state">The state.</param> /// <param name="actualEvents">The actual events.</param> /// <param name="actualException">The actual exception.</param> internal EventCentricTestResult( EventCentricTestSpecification specification, TestResultState state, Optional <Fact[]> actualEvents, Optional <Exception> actualException) { Specification = specification; _state = state; ButEvents = actualEvents; ButException = actualException; }
private async Task <EventCentricTestResult> RunAsync(EventCentricTestSpecification spec) { var position = await _factWriter.PersistFacts(spec.Givens); var handleCommand = _handlerResolver.ResolveHandlerFor(spec.When); var result = await Catch.Exception(async() => await handleCommand(spec.When)); if (result.HasValue) { return(spec.Fail(result.Value)); } var actualEvents = await _factReader.RetrieveFacts(position); return(actualEvents.SequenceEqual(spec.Thens, new WrappedFactComparerEqualityComparer(_comparer)) ? spec.Pass(actualEvents) : spec.Fail(actualEvents)); }
private void WriteThens(EventCentricTestSpecification specification) { _writer.WriteLine("Then"); WriteFacts(specification.Thens); }
private void WriteWhen(EventCentricTestSpecification 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(EventCentricTestSpecification specification) { WriteGivens(specification); WriteWhen(specification); WriteThens(specification); }
/// <summary> /// Determines whether the specified <see cref="EventCentricTestSpecification" /> is equal to this instance. /// </summary> /// <param name="other">The <see cref="EventCentricTestSpecification" /> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="EventCentricTestSpecification" /> is equal to this instance; otherwise, <c>false</c>. /// </returns> protected bool Equals(EventCentricTestSpecification other) => Equals(Givens, other.Givens) && Equals(When, other.When) && Equals(Thens, other.Thens);
public EventCentricTestResult Run(EventCentricTestSpecification specification) => RunAsync(specification).GetAwaiter().GetResult();