本文整理汇总了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;
}
示例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;
}
}
示例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;
}
}
示例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.
//.........这里部分代码省略.........