Example #1
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));
        }
Example #2
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);
        }