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)); }
public void Add(T aggregateRoot) => _facts.Record(aggregateRoot.Id, aggregateRoot.GetChanges());