/// <summary> /// 压进队列里 /// </summary> /// <param name="invocation">The invocation.</param> /// <returns></returns> public static int Enqueue(MockSetup invocation) { var fac = System.Threading.Interlocked.Increment(ref factor); invocationQueue[fac] = invocation; return(fac); }
/// <summary> /// 执行对象某个不带返回值的方法 /// </summary> /// <param name="expression"></param> public IMockSetup <T> Setup(Expression <Action <T> > expression) { if (expression == null) { throw new ArgumentNullException("expression is null"); } if (expression.Body is ParameterExpression) { throw new ArgumentException("expression body is parameter"); } var memberExpress = expression.Body as MemberExpression; if (memberExpress == null) { var unaryExpression = expression.Body as UnaryExpression; if (unaryExpression != null) { memberExpress = unaryExpression.Operand as MemberExpression; } } if (memberExpress == null) { var methodExpress = expression.Body as MethodCallExpression; if (methodExpress == null) { throw new ArgumentException("expression cannot support"); } var methodSetup = new MockSetup <T, object>(); methodSetup.Method = methodExpress.Method; this.rules.Add(methodSetup); return(methodSetup); } var mockSetup = new MockSetup <T, object>(); mockSetup.Field = memberExpress.Member as FieldInfo; mockSetup.Property = memberExpress.Member as PropertyInfo; mockSetup.Method = memberExpress.Member as MethodInfo; this.rules.Add(mockSetup); return(mockSetup); }