Exemple #1
0
        private void Verify(Action <ISetup> verifyLast)
        {
            Debug.Assert(verifyLast != null);
            Debug.Assert(this.parts.Count > 1);

            try
            {
                foreach (var part in this.parts.Take(this.parts.Count - 1))
                {
                    part.Verify(recursive: false);
                }
                verifyLast(this.parts.Last());
            }
            catch (MockException error) when(error.IsVerificationError)
            {
                throw MockException.FromInnerMockOf(this, error);
            }
        }
Exemple #2
0
        /// <summary>
        ///   Verifies this setup and those of its inner mock (if present and known).
        /// </summary>
        /// <param name="recursive">
        ///   Specifies whether recursive verification should be performed.
        /// </param>
        /// <param name="predicate">
        ///   Specifies which setups should be verified.
        /// </param>
        /// <param name="error">
        ///   If this setup or any of its inner mock (if present and known) failed verification,
        ///   this <see langword="out"/> parameter will receive a <see cref="MockException"/> describing the verification error(s).
        /// </param>
        /// <returns>
        ///   <see langword="true"/> if verification succeeded without any errors;
        ///   otherwise, <see langword="false"/>.
        /// </returns>
        public bool TryVerify(bool recursive, Func <ISetup, bool> predicate, out MockException error)
        {
            MockException e;

            // verify this setup:
            if (!this.TryVerifySelf(out e) && e.IsVerificationError)
            {
                error = e;
                return(false);
            }

            // optionally verify setups of inner mock (if present and known):
            if (recursive && this.ReturnsInnerMock(out var innerMock) && !innerMock.TryVerify(predicate, out e) && e.IsVerificationError)
            {
                error = MockException.FromInnerMockOf(this, e);
                return(false);
            }

            error = null;
            return(true);
        }
Exemple #3
0
        /// <summary>
        ///   Verifies this setup and those of its inner mock (if present and known).
        /// </summary>
        /// <param name="recursive">
        ///   Specifies whether recursive verification should be performed.
        /// </param>
        /// <param name="predicate">
        ///   Specifies which setups should be verified.
        /// </param>
        /// <param name="verifiedMocks">
        ///   The set of mocks that have already been verified.
        /// </param>
        /// <exception cref="MockException">
        ///   This setup or any of its inner mock (if present and known) failed verification.
        /// </exception>
        internal void Verify(bool recursive, Func <ISetup, bool> predicate, HashSet <Mock> verifiedMocks)
        {
            // verify this setup:
            this.VerifySelf();

            // optionally verify setups of inner mock (if present and known):
            if (recursive)
            {
                try
                {
                    foreach (var innerMock in this.InnerMocks)
                    {
                        innerMock.Verify(predicate, verifiedMocks);
                    }
                }
                catch (MockException error) when(error.IsVerificationError)
                {
                    throw MockException.FromInnerMockOf(this, error);
                }
            }
        }