Exemple #1
0
        internal bool TryVerify(Func <ISetup, bool> predicate, out MockException error)
        {
            foreach (Invocation invocation in this.MutableInvocations)
            {
                invocation.MarkAsVerifiedIfMatchedBy(predicate);
            }

            var errors = new List <MockException>();

            foreach (var setup in this.MutableSetups.ToArray(predicate))
            {
                if (predicate(setup) && !setup.TryVerify(recursive: true, predicate, out var e) && e.IsVerificationError)
                {
                    errors.Add(e);
                }
            }

            if (errors.Count > 0)
            {
                error = MockException.Combined(
                    errors,
                    preamble: string.Format(CultureInfo.CurrentCulture, Resources.VerificationErrorsOfMock, this));
                return(false);
            }
            else
            {
                error = null;
                return(true);
            }
        }
Exemple #2
0
        internal void Verify(Func <ISetup, bool> predicate, HashSet <Mock> verifiedMocks)
        {
            if (verifiedMocks.Add(this) == false)
            {
                // This mock has already been verified; don't verify it again.
                // (We can end up here e.g. when there are loops in the inner mock object graph.)
                return;
            }

            foreach (Invocation invocation in this.MutableInvocations)
            {
                invocation.MarkAsVerifiedIfMatchedBy(predicate);
            }

            var errors = new List <MockException>();

            foreach (var setup in this.MutableSetups.ToArray(setup => !setup.IsOverridden && !setup.IsConditional && predicate(setup)))
            {
                try
                {
                    setup.Verify(recursive: true, predicate, verifiedMocks);
                }
                catch (MockException error) when(error.IsVerificationError)
                {
                    errors.Add(error);
                }
            }

            if (errors.Count > 0)
            {
                throw MockException.Combined(
                          errors,
                          preamble: string.Format(CultureInfo.CurrentCulture, Resources.VerificationErrorsOfMock, this));
            }
        }
Exemple #3
0
        internal bool TryVerify(Func <ISetup, bool> predicate, HashSet <Mock> verifiedMocks, out MockException error)
        {
            if (verifiedMocks.Add(this) == false)
            {
                // This mock has already been verified; don't verify it again.
                // (We can end up here e.g. when there are loops in the inner mock object graph.)
                error = null;
                return(true);
            }

            foreach (Invocation invocation in this.MutableInvocations)
            {
                invocation.MarkAsVerifiedIfMatchedBy(predicate);
            }

            var errors = new List <MockException>();

            foreach (var setup in this.MutableSetups.ToArray(predicate))
            {
                if (predicate(setup) && !setup.TryVerify(recursive: true, predicate, verifiedMocks, out var e) && e.IsVerificationError)
                {
                    errors.Add(e);
                }
            }

            if (errors.Count > 0)
            {
                error = MockException.Combined(
                    errors,
                    preamble: string.Format(CultureInfo.CurrentCulture, Resources.VerificationErrorsOfMock, this));
                return(false);
            }
            else
            {
                error = null;
                return(true);
            }
        }
Exemple #4
0
        private MockException TryVerifySetups(Func <Setup, MockException> verifySetup)
        {
            var errors = new List <MockException>();

            foreach (var setup in this.Setups.ToArrayLive(_ => true))
            {
                var error = verifySetup(setup);
                if (error?.IsVerificationError == true)
                {
                    errors.Add(error);
                }
            }

            if (errors.Count > 0)
            {
                return(MockException.Combined(
                           errors,
                           preamble: string.Format(CultureInfo.CurrentCulture, Resources.VerificationErrorsOfMock, this)));
            }
            else
            {
                return(null);
            }
        }