Exemplo n.º 1
0
        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>();
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        /// <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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        /// <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);
        }