Ejemplo n.º 1
0
 /// <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)
 {
     return
         (Equals(_givens, other._givens) &&
          Equals(_when, other._when) &&
          Equals(_throws, other._throws));
 }
Ejemplo n.º 2
0
        public async Task <ExceptionCentricTestResult> Run(ExceptionCentricTestSpecification 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 = _factRecorder.GetFacts().Skip(specification.Givens.Length).ToArray();

            return(new ExceptionCentricTestResult(specification,
                                                  optionalException.HasValue &&
                                                  !_comparer.Compare(specification.Throws, optionalException.Value).Any()
                    ? TestResultState.Passed
                    : TestResultState.Failed,
                                                  optionalException, then));
        }
Ejemplo n.º 3
0
 void WriteThrows(ExceptionCentricTestSpecification specification)
 {
     _writer.WriteLine("Throws");
     _writer.Indent++;
     _writer.WriteLine("[{0}] {1}", specification.Throws.GetType().Name, specification.Throws.Message);
     _writer.Indent--;
 }
Ejemplo n.º 4
0
 /// <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;
     _actualException = actualException;
     _actualEvents    = actualEvents;
 }
Ejemplo n.º 5
0
        void WriteGivens(ExceptionCentricTestSpecification specification)
        {
            if (specification.Givens.Length == 0)
            {
                return;
            }

            _writer.WriteLine("Given");
            WriteFacts(specification.Givens);
        }
Ejemplo n.º 6
0
 void WriteWhen(ExceptionCentricTestSpecification specification)
 {
     _writer.WriteLine("When");
     WriteMessage(specification.When);
 }
Ejemplo n.º 7
0
 /// <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);
 }