当前位置: 首页>>代码示例>>C#>>正文


C# ICallContext.InvokeBase方法代码示例

本文整理汇总了C#中ICallContext.InvokeBase方法的典型用法代码示例。如果您正苦于以下问题:C# ICallContext.InvokeBase方法的具体用法?C# ICallContext.InvokeBase怎么用?C# ICallContext.InvokeBase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICallContext的用法示例。


在下文中一共展示了ICallContext.InvokeBase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleIntercept

        public InterceptionAction HandleIntercept(ICallContext invocation, InterceptorContext ctx, CurrentInterceptContext localctx)
        {
            this.ctx = ctx;
            if (!FluentMockContext.IsActive)
            {
                //Special case for events
                if (invocation.Method.IsEventAttach())
                {
                    var delegateInstance = (Delegate)invocation.Arguments[0];
                    // TODO: validate we can get the event?
                    var eventInfo = this.GetEventFromName(invocation.Method.Name.Substring(4));

                    if (ctx.Mock.CallBase && !eventInfo.DeclaringType.IsInterface)
                    {
                        invocation.InvokeBase();
                    }
                    else if (delegateInstance != null)
                    {
                        ctx.AddEventHandler(eventInfo, (Delegate)invocation.Arguments[0]);
                    }

                    return InterceptionAction.Stop;
                }
                else if (invocation.Method.IsEventDetach())
                {
                    var delegateInstance = (Delegate)invocation.Arguments[0];
                    // TODO: validate we can get the event?
                    var eventInfo = this.GetEventFromName(invocation.Method.Name.Substring(7));

                    if (ctx.Mock.CallBase && !eventInfo.DeclaringType.IsInterface)
                    {
                        invocation.InvokeBase();
                    }
                    else if (delegateInstance != null)
                    {
                        ctx.RemoveEventHandler(eventInfo, (Delegate)invocation.Arguments[0]);
                    }

                    return InterceptionAction.Stop;
                }

                // Save to support Verify[expression] pattern.
                // In a fluent invocation context, which is a recorder-like
                // mode we use to evaluate delegates by actually running them,
                // we don't want to count the invocation, or actually run
                // previous setups.
                ctx.AddInvocation(invocation);
            }
            return InterceptionAction.Continue;
        }
开发者ID:moq,项目名称:moq4,代码行数:50,代码来源:InterceptorStrategies.cs

示例2: HandleIntercept

        public InterceptionAction HandleIntercept(ICallContext invocation, InterceptStrategyContext ctx)
        {
            if (invocation.Method.DeclaringType == typeof(object) ||
                invocation.Method.DeclaringType.IsClass && !invocation.Method.IsAbstract && ctx.Mock.CallBase
                )
            {
                // Invoke underlying implementation.

                // For mocked classes, if the target method was not abstract, 
                // invoke directly.
                // Will only get here for Loose behavior.
                // TODO: we may want to provide a way to skip this by the user.
                invocation.InvokeBase();
                return InterceptionAction.Stop;
            }
            else
            {
                return InterceptionAction.Continue;
            }
        }
开发者ID:gitter-badger,项目名称:MobileMoq,代码行数:20,代码来源:InterceptorStrategies.cs

示例3: HandleIntercept

        public InterceptionAction HandleIntercept(ICallContext invocation, InterceptorContext ctx, CurrentInterceptContext localctx)
        {
            if (invocation.Method.DeclaringType == typeof(object) || // interface proxy
                ctx.Mock.ImplementedInterfaces.Contains(invocation.Method.DeclaringType) && !invocation.Method.IsEventAttach() && !invocation.Method.IsEventDetach() && ctx.Mock.CallBase || // class proxy with explicitly implemented interfaces. The method's declaring type is the interface and the method couldn't be abstract
                invocation.Method.DeclaringType.IsClass && !invocation.Method.IsAbstract && ctx.Mock.CallBase // class proxy
                )
            {
                // Invoke underlying implementation.

                // For mocked classes, if the target method was not abstract, 
                // invoke directly.
                // Will only get here for Loose behavior.
                // TODO: we may want to provide a way to skip this by the user.
                invocation.InvokeBase();
                return InterceptionAction.Stop;
            }
            else
            {
                return InterceptionAction.Continue;
            }
        }
开发者ID:JohnsonYuan,项目名称:moq4,代码行数:21,代码来源:InterceptorStrategies.cs

示例4: Intercept

		public void Intercept(ICallContext invocation)
		{
			if (invocation.Method.IsDestructor())
			{
				return;
			}

			// Track current invocation if we're in "record" mode in a fluent invocation context.
			if (FluentMockContext.IsActive)
			{
				FluentMockContext.Current.Add(this.Mock, invocation);
			}

			// TODO: too many ifs in this method.
			// see how to refactor with strategies.
			if (invocation.Method.DeclaringType.IsGenericType() &&
			  invocation.Method.DeclaringType.GetGenericTypeDefinition() == typeof(IMocked<>))
			{
				// "Mixin" of IMocked<T>.Mock
				invocation.ReturnValue = this.Mock;
				return;
			}
			else if (invocation.Method.DeclaringType == typeof(IMocked))
			{
				// "Mixin" of IMocked.Mock
				invocation.ReturnValue = this.Mock;
				return;
			}

			// Special case for events.
			if (!FluentMockContext.IsActive)
			{
				if (invocation.Method.IsEventAttach())
				{
					var delegateInstance = (Delegate)invocation.Arguments[0];
					// TODO: validate we can get the event?
					var eventInfo = this.GetEventFromName(invocation.Method.Name.Substring(4));

					if (this.Mock.CallBase)
					{
						invocation.InvokeBase();
					}
					else if (delegateInstance != null)
					{
						this.AddEventHandler(eventInfo, (Delegate)invocation.Arguments[0]);
					}

					return;
				}
				else if (invocation.Method.IsEventDetach())
				{
					var delegateInstance = (Delegate)invocation.Arguments[0];
					// TODO: validate we can get the event?
					var eventInfo = this.GetEventFromName(invocation.Method.Name.Substring(7));

					if (this.Mock.CallBase)
					{
						invocation.InvokeBase();
					}
					else if (delegateInstance != null)
					{
						this.RemoveEventHandler(eventInfo, (Delegate)invocation.Arguments[0]);
					}

					return;
				}

				// Save to support Verify[expression] pattern.
				// In a fluent invocation context, which is a recorder-like 
				// mode we use to evaluate delegates by actually running them, 
				// we don't want to count the invocation, or actually run 
				// previous setups.
				actualInvocations.Add(invocation);
			}

			var call = FluentMockContext.IsActive ? (IProxyCall)null : orderedCalls.LastOrDefault(c => c.Matches(invocation));
			if (call == null && !FluentMockContext.IsActive && behavior == MockBehavior.Strict)
			{
				throw new MockException(MockException.ExceptionReason.NoSetup, behavior, invocation);
			}

			if (call != null)
			{
				call.SetOutParameters(invocation);

				// We first execute, as there may be a Throws 
				// and therefore we might never get to the 
				// next line.
				call.Execute(invocation);
				ThrowIfReturnValueRequired(call, invocation);
			}
			else if (invocation.Method.DeclaringType == typeof(object))
			{
				// Invoke underlying implementation.
				invocation.InvokeBase();
			}
			else if (invocation.Method.DeclaringType.IsClass() && !invocation.Method.IsAbstract && this.Mock.CallBase)
			{
				// For mocked classes, if the target method was not abstract, 
				// invoke directly.
//.........这里部分代码省略.........
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:101,代码来源:Interceptor.cs


注:本文中的ICallContext.InvokeBase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。