/// <summary>
        /// Verifies a set of events being appended to the stream.
        /// </summary>
        /// <param name="aggregate">Aggregate to verify events appended to it's stream for.</param>
        /// <param name="expectedVersion">
        /// The expected version used when calling <see cref="AppendToStreamAsync{TIdentity,TAggregate}"/>. See
        /// <see cref="CurrentVersion{TIdentity,TAggregate}"/> for obtaining the current version of a stream.
        /// </param>
        /// <param name="verification">The events to verify and assert.</param>
        /// <typeparam name="TIdentity">Type of ID of the aggregate.</typeparam>
        /// <typeparam name="TAggregate">Type of aggregate.</typeparam>
        /// <exception cref="InvalidOperationException">
        /// No calls to <see cref="AppendToStreamAsync{TIdentity,TAggregate}"/> matching the expected was found.
        /// </exception>
        /// <remarks>
        /// The order of events configured in the <paramref name="verification"/>, must match the expected order of the
        /// events appended by a previous call to <see cref="AppendToStreamAsync{TIdentity,TAggregate}"/>.
        /// </remarks>
        public void VerifyAppendToStream <TIdentity, TAggregate>(
            Aggregate <TIdentity, TAggregate> aggregate,
            long expectedVersion,
            Func <EventAssertionsBuilder, EventAssertionsBuilder> verification
            ) where TAggregate : Aggregate <TIdentity, TAggregate>
        {
            var evb = new EventAssertionsBuilder();

            verification(evb);

            var append = _appends
                         .FirstOrDefault(app => Matches(typeof(TAggregate), aggregate.Id !, expectedVersion, app, evb));

            if (append == null)
            {
                var ev = ExpectedVersionString(expectedVersion);

                throw new InvalidOperationException(
                          $"No append matching the assertions specified was found.{Environment.NewLine}" +
                          $"{Environment.NewLine}" +
                          $"Expected an append matching:{Environment.NewLine}" +
                          $"\tAppendToStreamAsync({aggregate.Id}, <configuration>, {ev}, {evb}){Environment.NewLine}" +
                          $"{Environment.NewLine}" +
                          $"Recorded appends:{Environment.NewLine}" +
                          $"{string.Join(Environment.NewLine, _appends.Select(app => $"\t{app}"))}{Environment.NewLine}"
                          );
            }
        }
        private bool Matches(Type aggregateType, object id, long expectedVersion, Append append, EventAssertionsBuilder evb)
        {
            if (append.AggregateType != aggregateType || !Equals(id, append.Id) || expectedVersion != append.ExpectedVersion)
            {
                return(false);
            }

            if (append.PendingEvents.Count != evb.Assertions.Count)
            {
                return(false);
            }

            for (var i = 0; i < append.PendingEvents.Count; i++)
            {
                var pendingEvent   = append.PendingEvents[i];
                var eventAssertion = evb.Assertions[i];
                if (eventAssertion.EventType != pendingEvent.Type)
                {
                    return(false);
                }

                eventAssertion.Assertions(pendingEvent, _serializer);
            }

            return(true);
        }