Exemplo n.º 1
0
 /// <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)
 {
     return
         (Equals(Givens, other.Givens) &&
          Equals(When, other.When) &&
          Equals(Thens, other.Thens));
 }
        public async Task <EventCentricTestResult> Run(EventCentricTestSpecification specification)
        {
            var methodInfo = _handler.GetType().GetMethods().Single(
                mi => {
                var parameters = mi.GetParameters();
                return(mi.IsPublic &&
                       mi.ReturnType == typeof(ValueTask) &&
                       parameters.Length == 2 &&
                       parameters[0].ParameterType == specification.When.GetType() &&
                       parameters[1].ParameterType == typeof(CancellationToken));
            });

            ValueTask Handler(object o, CancellationToken ct) => (ValueTask)methodInfo.Invoke(_handler, new[] { o, ct }) !;

            _factRecorder.Record(specification.Givens);

            Optional <Exception> optionalException = Optional <Exception> .Empty;

            try {
                await Handler(specification.When, CancellationToken.None);
            } catch (Exception ex) {
                optionalException = ex;
            }

            var then = await _factRecorder.GetFacts().Skip(specification.Givens.Length).ToArrayAsync();

            return(new EventCentricTestResult(specification,
                                              !optionalException.HasValue &&
                                              specification.Thens.SequenceEqual(then, new FactEqualityComparer(_comparer))
                    ? TestResultState.Passed
                    : TestResultState.Failed,
                                              then, optionalException));
        }
Exemplo n.º 3
0
 /// <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;
     _actualEvents    = actualEvents;
     _actualException = actualException;
 }
Exemplo n.º 4
0
        void WriteGivens(EventCentricTestSpecification specification)
        {
            if (specification.Givens.Length == 0)
            {
                return;
            }

            _writer.WriteLine("Given");
            WriteFacts(specification.Givens);
        }
Exemplo n.º 5
0
 void WriteThens(EventCentricTestSpecification specification)
 {
     _writer.WriteLine("Then");
     WriteFacts(specification.Thens);
 }
Exemplo n.º 6
0
 void WriteWhen(EventCentricTestSpecification specification)
 {
     _writer.WriteLine("When");
     WriteMessage(specification.When);
 }
Exemplo n.º 7
0
 /// <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);
 }