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


C# ICallContext类代码示例

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


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

示例1: AfterCall

		public override void AfterCall(ICallContext callContext)
		{
			Console.WriteLine("> Leaving {0}", callContext.Method.Name);
			if (callContext.CallFailed) {
				Console.WriteLine("  Exception: {0}", callContext.Exception);
			}
		}
开发者ID:codetuner,项目名称:Arebis.Common,代码行数:7,代码来源:ExtensionSample.cs

示例2: AfterCall

        /// <summary>
        /// Method called after a call is issued.
        /// </summary>
        public override void AfterCall(ICallContext callContext)
        {
            // Should happen only on constructor methods which are not supported:
            if (callContext.Instance == null)
                return;

            // Call IInterceptible.AfterCall method, or throw exception:
            var instance = callContext.Instance as IInterceptible;
            if (instance != null)
                instance.AfterCall(callContext);
            else
                throw new InvalidOperationException(String.Format("{0} should implement IInterceptible.", callContext.Instance.GetType()));
        }
开发者ID:codetuner,项目名称:Arebis.Common,代码行数:16,代码来源:InterceptionAdviceAttribute.cs

示例3: 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

示例4: Search

		/// <summary>
		/// Will search the index using the specified query.
		/// </summary>
		/// <param name="callContext"></param>
		/// <param name="query"></param>
        public IndexResponse Search( ICallContext callContext, IQuery query, UUID accessPointGUID )
        {
			if( accessPointGUID != null )
                query.Query = string.Format("({0})+AND+(ap{1}_PubStart:[*+TO+NOW]+AND+ap{1}_PubEnd:[NOW+TO+*])", query.Query, accessPointGUID);
            else
            {
				var folders = callContext.PortalApplication.GetModule<MCM.Module.FolderModule>().Get( callContext, null, null, null, (uint) FolderPermission.Read );

                query.Query = string.Format( "({0})+AND+({1})", query.Query, string.Join( "+OR+", folders.Select( folder => string.Format( "FolderTree:{0}", folder.ID ) ) ) );
            }

            var response = callContext.IndexManager.GetIndex( "CHAOS.MCM.Module.AMCMModule" ).Get<UUIDResult>( query );

            return new IndexResponse( response );
        }
开发者ID:CHAOS-Community,项目名称:CHAOS.Portal.Indexing,代码行数:20,代码来源:Index.cs

示例5: ThrowIfReturnValueRequired

 private void ThrowIfReturnValueRequired(IProxyCall call, ICallContext invocation)
 {
     if (ctx.Behavior != MockBehavior.Loose &&
         invocation.Method != null &&
         invocation.Method.ReturnType != null &&
         invocation.Method.ReturnType != typeof(void))
     {
         var methodCall = call as MethodCallReturn;
         if (methodCall == null || !methodCall.HasReturnValue)
         {
             throw new MockException(
                 MockException.ExceptionReason.ReturnValueRequired,
                 ctx.Behavior,
                 invocation);
         }
     }
 }
开发者ID:JohnsonYuan,项目名称:moq4,代码行数:17,代码来源:InterceptorStrategies.cs

示例6: HandleIntercept

		public InterceptionAction HandleIntercept(ICallContext invocation, InterceptorContext ctx, CurrentInterceptContext localctx)
        {
			if (invocation.Method != null && invocation.Method.ReturnType != null &&
                    invocation.Method.ReturnType != typeof(void))
            {
                Mock recursiveMock;
                if (ctx.Mock.InnerMocks.TryGetValue(invocation.Method, out recursiveMock))
                {
                    invocation.ReturnValue = recursiveMock.Object;
                }
                else
                {
                    invocation.ReturnValue = ctx.Mock.DefaultValueProvider.ProvideDefault(invocation.Method);
                }
                return InterceptionAction.Stop;
            }
            return InterceptionAction.Continue;
        }
开发者ID:JohnsonYuan,项目名称:moq4,代码行数:18,代码来源:InterceptorStrategies.cs

示例7: HandleIntercept

        public InterceptionAction HandleIntercept(ICallContext invocation, InterceptStrategyContext ctx)
        {
            this.ctx = ctx;
            if (ctx.CurrentCall != null)
            {
                ctx.CurrentCall.SetOutParameters(invocation);

                // We first execute, as there may be a Throws 
                // and therefore we might never get to the 
                // next line.
                ctx.CurrentCall.Execute(invocation);
                ThrowIfReturnValueRequired(ctx.CurrentCall, invocation);
                return InterceptionAction.Stop;
            }
            else
            {
                return InterceptionAction.Continue;
            }
        }
开发者ID:gitter-badger,项目名称:MobileMoq,代码行数:19,代码来源:InterceptorStrategies.cs

示例8: AfterCall

 public override void AfterCall(ICallContext callContext)
 {
     System.Current.DateTime = (IDateTimeFactory)callContext.GetProperty("datetimefactory", null);
 }
开发者ID:codetuner,项目名称:Arebis.Common,代码行数:4,代码来源:MockTimeAdviceAttribute.cs

示例9: BeforeCall

 public override void BeforeCall(ICallContext callContext)
 {
     callContext.SetProperty("datetimefactory", System.Current.DateTime);
     System.Current.DateTime = mock;
 }
开发者ID:codetuner,项目名称:Arebis.Common,代码行数:5,代码来源:MockTimeAdviceAttribute.cs

示例10: AfterCall

 /// <summary>
 /// Method called after a call is issued.
 /// </summary>
 public abstract void AfterCall(ICallContext callContext);
开发者ID:codetuner,项目名称:Arebis.Common,代码行数:4,代码来源:AdviceAttribute.cs

示例11: 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

示例12: AddInvocation

		internal void AddInvocation(ICallContext invocation)
		{
			lock (actualInvocations)
			{
				actualInvocations.Add(invocation);
			}
		}
开发者ID:JohnsonYuan,项目名称:moq4,代码行数:7,代码来源:IInterceptStrategy.cs

示例13: AddInvocation

        internal void AddInvocation(ICallContext invocation)
        {
            lock (actualInvocations)
            {
                actualInvocations.Add(invocation);
            }

            lock (Mock.CallSequence)
            {
                Mock.CallSequence.Add(invocation, Mock);
            }
        }
开发者ID:grzesiek-galezowski,项目名称:moq4,代码行数:12,代码来源:IInterceptStrategy.cs

示例14: Intercept

		public void Intercept(ICallContext invocation)
		{

            lock (Mock) // this solves issue #249
            {
                var interceptionContext = new InterceptStrategyContext(Mock
                                                                    , targetType
                                                                    , invocationLists
                                                                    , actualInvocations
                                                                    , behavior
                                                                    , orderedCalls
                                                                    );
                foreach (var strategy in InterceptionStrategies())
                {
                    if (InterceptionAction.Stop == strategy.HandleIntercept(invocation, interceptionContext))
                    {
                        break;
                    }
                }
            }
		}
开发者ID:gitter-badger,项目名称:MobileMoq,代码行数:21,代码来源:Interceptor.cs

示例15: MockInvocation

			public MockInvocation(Mock mock, ICallContext invocation, Match matcher)
			{
				this.Mock = mock;
				this.Invocation = invocation;
				this.Match = matcher;
				defaultValue = mock.DefaultValue;
				// Temporarily set mock default value to Mock so that recursion works.
				mock.DefaultValue = DefaultValue.Mock;
			}
开发者ID:20John22,项目名称:moq4,代码行数:9,代码来源:FluentMockContext.cs


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