public ImplementationOverrideBehavior(Delegate implementationOverride, bool ignoreDelegateReturnValue)
        {
            this.ignoreDelegateReturnValue = ignoreDelegateReturnValue;
            this.implementationOverride    = implementationOverride;

            this.overrideInvoker = MockingUtil.MakeFuncCaller(implementationOverride);
        }
        public void Process(object[] invocationArgs, Type declaringType)
        {
            object[] args = null;

            var func = this.eventDelegateParametersFactory as Func <object[]>;

            if (func != null)
            {
                args = ProfilerInterceptor.GuardExternal(func);
            }
            else
            {
                var invoker = MockingUtil.MakeFuncCaller(this.eventDelegateParametersFactory);
                args = (object[])ProfilerInterceptor.GuardExternal(() => invoker(invocationArgs, this.eventDelegateParametersFactory));
            }

            RaiseEventImpl(this.instance, this.evt, args);
        }
示例#3
0
        private static bool NodeMatchesFilter(CallPattern callPattern, IMatcherTreeNode node)
        {
            var filter = callPattern.Filter;

            if (filter == null)
            {
                return(true);
            }

            var args     = new List <object>();
            var nodeIter = node;

            while (nodeIter != null)
            {
                var valueMatcher = nodeIter.Matcher as IValueMatcher;
                if (valueMatcher != null)
                {
                    args.Add(valueMatcher.Value);
                }
                nodeIter = nodeIter.Parent;
            }

            if (!callPattern.Method.IsStatic && filter.Method.GetParameters().Length + 1 == args.Count)
            {
                args.RemoveAt(args.Count - 1);
            }

            args.Reverse();
            var argsArray = args.ToArray();

            object state;

            MockingUtil.BindToMethod(MockingUtil.Default, new[] { filter.Method }, ref argsArray, null, null, null, out state);

            var filterFunc = MockingUtil.MakeFuncCaller(filter);
            var isMatch    = (bool)ProfilerInterceptor.GuardExternal(() => filterFunc(argsArray, filter));

            DebugView.TraceEvent(IndentLevel.Matcher, () => String.Format("Matcher predicate {0} call to {2} with arguments ({1})",
                                                                          isMatch ? "passed" : "rejected", String.Join(", ", args.Select(x => x.ToString()).ToArray()),
                                                                          callPattern.Method));

            return(isMatch);
        }
示例#4
0
        public void RaiseEvent(EventInfo evt, object[] delegateArguments)
        {
            Delegate existing;

            eventHandlers.TryGetValue(evt, out existing);

            if (existing != null)
            {
                try
                {
                    object state;
                    MockingUtil.BindToMethod(MockingUtil.Default, new[] { existing.Method }, ref delegateArguments, null, null, null, out state);
                }
                catch (MissingMethodException ex)
                {
                    throw new MockException(String.Format("Event signature {0} is incompatible with argument types ({1})",
                                                          existing.Method, String.Join(", ", delegateArguments.Select(x => x != null ? x.GetType().ToString() : "null").ToArray())
                                                          ), ex);
                }

                var invoker = MockingUtil.MakeFuncCaller(existing);
                ProfilerInterceptor.GuardExternal(() => invoker(delegateArguments, existing));
            }
        }