public void out_and_ref_arguments_always_result_in_a_non_discriminatory_filter()
        {
            int    i = 0;
            string s;
            var    argumentFilters = ArgumentFiltersVisitor.FindArgumentFiltersWithin(GetExpression(() => this.SomeMethod(ref i, out s)));

            Assert.NotNull(argumentFilters);
            Assert.Equal(2, argumentFilters.Count);
            Assert.IsType <IsAnyArgumentFilter <object> >(argumentFilters[0]);
            Assert.IsType <IsAnyArgumentFilter <object> >(argumentFilters[1]);
        }
Beispiel #2
0
        /// <summary>
        /// Begins a verification specification.
        /// </summary>
        /// <typeparam name="TMember"></typeparam>
        /// <param name="selector">
        /// An expression that resolves to the member being verified.
        /// </param>
        /// <returns>
        /// A continuation object with which the verification can be specified.
        /// </returns>
        public VerifyContinuation Verify <TMember>(Expression <Func <TMock, TMember> > selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            var whenContinuationCollection = this.EnsureWhenContinuationCollection(selector);

            return(new VerifyContinuation(selector, whenContinuationCollection, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters));
        }
Beispiel #3
0
        /// <summary>
        /// Begins the specification of what the mock should do when a given member is accessed.
        /// </summary>
        /// <param name="selector">
        /// An expression that resolves to the member.
        /// </param>
        /// <returns>
        /// A continuation object with which the actions to be performed can be configured.
        /// </returns>
        public WhenContinuation <TMock> When(Expression <Action <TMock> > selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            var continuation = new WhenContinuation <TMock>(selector, ArgumentFiltersVisitor.FindArgumentFiltersWithin(selector.Body) ?? emptyArgumentFilters);

            this.AddOrReplaceWhenContinuation(selector, continuation);
            return(continuation);
        }
        public void can_find_argument_filters_in_a_method_call()
        {
            var argumentFilters = ArgumentFiltersVisitor.FindArgumentFiltersWithin(GetExpression(() => Console.WriteLine(It.IsAny <string>(), 3, It.IsIn("foo", "bar"))));

            Assert.NotNull(argumentFilters);
            Assert.Equal(3, argumentFilters.Count);
            Assert.True(argumentFilters[0].Matches("foo"));
            Assert.True(argumentFilters[0].Matches("bar"));
            Assert.True(argumentFilters[0].Matches(null));
            Assert.True(argumentFilters[1].Matches(3));
            Assert.False(argumentFilters[1].Matches(2));
            Assert.True(argumentFilters[2].Matches("foo"));
            Assert.True(argumentFilters[2].Matches("bar"));
            Assert.False(argumentFilters[2].Matches("baz"));
            Assert.False(argumentFilters[2].Matches(3));
        }