Implements the actual interception and method invocation for all mocks.
Inheritance: ICallInterceptor
コード例 #1
0
        private static void VerifyCalls(
            Interceptor targetInterceptor,
            MethodCall expected,
            Expression expression,
            Times times)
        {
            var callCount = targetInterceptor.ActualCalls.Where(ac => expected.Matches(ac)).Count();

            if (!times.Verify(callCount))
            {
                var setups = targetInterceptor.OrderedCalls.Where(oc => AreSameMethod(oc.SetupExpression, expression));
                ThrowVerifyException(expected, setups, targetInterceptor.ActualCalls, expression, times, callCount);
            }
        }
コード例 #2
0
ファイル: Mock.cs プロジェクト: lxf/moq4
        private static void VerifyCalls(
            Interceptor targetInterceptor,
            MethodCall expected,
            Expression expression,
            Times times)
        {
            // .Where does an enumeration, and calls to a mocked method concurrent to VerifyCalls might change the content of ActualCalls. therefore, it is necessary to take a snapshot, using ToList(), so that concurrent calls will not impact the ongoing verification.
            var actualCalls = targetInterceptor.InterceptionContext.ActualInvocations.ToList();

            var callCount = actualCalls.Where(ac => expected.Matches(ac)).Count();

            if (!times.Verify(callCount))
            {
                var setups = targetInterceptor.InterceptionContext.OrderedCalls.Where(oc => AreSameMethod(oc.SetupExpression, expression));
                ThrowVerifyException(expected, setups, actualCalls, expression, times, callCount);
            }
        }
コード例 #3
0
ファイル: Mock.cs プロジェクト: lxf/moq4
        internal static void VerifySet <T>(
            Mock <T> mock,
            Action <T> setterExpression,
            Times times,
            string failMessage)
            where T : class
        {
            Interceptor targetInterceptor = null;
            Expression  expression        = null;
            var         expected          = SetupSetImpl <T, MethodCall <T> >(mock, setterExpression, (m, expr, method, value) =>
            {
                targetInterceptor = m.Interceptor;
                expression        = expr;
                return(new MethodCall <T>(m, null, expr, method, value)
                {
                    FailMessage = failMessage
                });
            });

            VerifyCalls(targetInterceptor, expected, expression, times);
        }
コード例 #4
0
        public Mock(MockBehavior behavior, Interceptor interceptor, params object[] args)
        {
            if (args == null)
            {
                args = new object[] { null };
            }

            if (interceptor == null)
            {
                interceptor = new Interceptor(behavior, typeof(T), this);
            }

            this.Name = GenerateMockName();

            this.Behavior             = behavior;
            this.Interceptor          = interceptor;
            this.constructorArguments = args;
            this.ImplementedInterfaces.AddRange(typeof(T).GetInterfaces().Where(i => (i.IsPublic || i.IsNestedPublic) && !i.IsImport));
            this.ImplementedInterfaces.Add(typeof(IMocked <T>));

            this.CheckParameters();
        }