internal WhenContinuation(Expression selector, IEnumerable <IArgumentFilter> filters) { Debug.Assert(selector != null); Debug.Assert(filters != null); this.selector = selector; this.filters = new ArgumentFilterCollection(filters); this.outAndRefAssignments = new Dictionary <int, object>(); }
internal VerifyContinuation(Expression selector, WhenContinuationCollection whenContinuationCollection, ArgumentFilterCollection filters) { Debug.Assert(selector != null); Debug.Assert(whenContinuationCollection != null); Debug.Assert(filters != null); this.selector = selector; this.whenContinuationCollection = whenContinuationCollection; this.filters = filters; }
/// <summary> /// Begins a verification specification for a property set. /// </summary> /// <typeparam name="TMember"> /// The type of the property. /// </typeparam> /// <param name="propertySelector"> /// An expression that resolves to the property being verified. /// </param> /// <param name="valueFilterSelector"> /// An optional expression that can provide filtering against the property value being set. /// </param> /// <returns> /// A continuation object with which the verification can be specified. /// </returns> public VerifyContinuation VerifyPropertySet <TMember>(Expression <Func <TMock, TMember> > propertySelector, Expression <Func <TMember> > valueFilterSelector = null) { if (propertySelector == null) { throw new ArgumentNullException("propertySelector"); } if (valueFilterSelector == null) { valueFilterSelector = () => It.IsAny <TMember>(); } var whenContinuationCollection = this.EnsureWhenContinuationCollection(propertySelector); var filters = new ArgumentFilterCollection(); filters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(valueFilterSelector.Body)); return(new VerifyContinuation(propertySelector, whenContinuationCollection, filters)); }
protected override Expression VisitMethodCall(MethodCallExpression node) { this.argumentFilters = new ArgumentFilterCollection(); var methodParameters = node.Method.GetParameters(); for (var i = 0; i < methodParameters.Length; ++i) { if (methodParameters[i].ParameterType.IsByRef || methodParameters[i].IsOut) { this.argumentFilters.Add(IsAnyArgumentFilter <object> .Instance); } else { this.argumentFilters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(node.Arguments[i])); } } return(Expression.Constant(this.argumentFilters)); }
public static bool TryFindArgumentFiltersWithin(Expression expression, out ArgumentFilterCollection argumentFilters) { Debug.Assert(expression != null); var visitor = new ArgumentFiltersVisitor(); try { visitor.Visit(expression); argumentFilters = visitor.argumentFilters; return(argumentFilters != null && argumentFilters.All(x => x != null)); } catch (Exception) { } argumentFilters = null; return(false); }
protected override Expression VisitMethodCall(MethodCallExpression node) { this.argumentFilters = new ArgumentFilterCollection(); var methodParameters = node.Method.GetParameters(); for (var i = 0; i < methodParameters.Length; ++i) { if (methodParameters[i].ParameterType.IsByRef || methodParameters[i].IsOut) { this.argumentFilters.Add(IsAnyArgumentFilter<object>.Instance); } else { this.argumentFilters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(node.Arguments[i])); } } return Expression.Constant(this.argumentFilters); }
public static bool TryFindArgumentFiltersWithin(Expression expression, out ArgumentFilterCollection argumentFilters) { Debug.Assert(expression != null); var visitor = new ArgumentFiltersVisitor(); try { visitor.Visit(expression); argumentFilters = visitor.argumentFilters; return argumentFilters != null && argumentFilters.All(x => x != null); } catch (Exception) { } argumentFilters = null; return false; }
/// <summary> /// Begins the specification of what the mock should do when a given property is set. /// </summary> /// <typeparam name="TMember"> /// The type of the property. /// </typeparam> /// <param name="propertySelector"> /// An expression that resolves the property. /// </param> /// <param name="valueFilterSelector"> /// An optional expression that can provide filtering against the property value being set. /// </param> /// <returns> /// A continuation object with which the actions to be performed can be configured. /// </returns> public WhenContinuation <TMock, TMember> WhenPropertySet <TMember>(Expression <Func <TMock, TMember> > propertySelector, Expression <Func <TMember> > valueFilterSelector = null) { if (propertySelector == null) { throw new ArgumentNullException("propertySelector"); } if (valueFilterSelector == null) { valueFilterSelector = () => It.IsAny <TMember>(); } var filters = new ArgumentFilterCollection(); filters.Add(ArgumentFilterVisitor.FindArgumentFilterWithin(valueFilterSelector.Body)); var continuation = new WhenContinuation <TMock, TMember>(propertySelector, filters); this.AddOrReplaceWhenContinuation(propertySelector, continuation); return(continuation); }