Exemplo n.º 1
0
        public void a_constant_being_returned_is_translated_to_an_is_argument_filter(object value)
        {
            var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => value));

            Assert.NotNull(argumentFilter);
            Assert.IsType <IsArgumentFilter>(argumentFilter);
            Assert.True(argumentFilter.Matches(value));
        }
Exemplo n.º 2
0
        public void expressions_are_evaluated_and_translated_to_an_is_argument_filter()
        {
            var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => decimal.MinValue));

            Assert.NotNull(argumentFilter);
            Assert.IsType <IsArgumentFilter>(argumentFilter);
            Assert.True(argumentFilter.Matches(decimal.MinValue));

            argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => Tuple.Create(1, "one")));
            Assert.NotNull(argumentFilter);
            Assert.IsType <IsArgumentFilter>(argumentFilter);
            Assert.True(argumentFilter.Matches(Tuple.Create(1, "one")));
        }
Exemplo n.º 3
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.º 4
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);
        }
Exemplo n.º 5
0
        public void can_find_argument_filter_in_method_call_against_it_class()
        {
            var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.IsAny <string>()));

            Assert.NotNull(argumentFilter);
            Assert.True(argumentFilter.Matches("foo"));
            Assert.True(argumentFilter.Matches("bar"));
            Assert.True(argumentFilter.Matches(null));

            argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.Is("foo")));
            Assert.NotNull(argumentFilter);
            Assert.True(argumentFilter.Matches("foo"));
            Assert.False(argumentFilter.Matches("bar"));

            argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => It.IsIn(1, 2, 3)));
            Assert.NotNull(argumentFilter);
            Assert.True(argumentFilter.Matches(1));
            Assert.True(argumentFilter.Matches(3));
            Assert.False(argumentFilter.Matches(4));
        }
Exemplo n.º 6
0
        public void cannot_find_argument_filter_in_method_call_with_no_arguments()
        {
            var argumentFilter = ArgumentFilterVisitor.FindArgumentFilterWithin(GetExpression(() => Console.WriteLine()));

            Assert.Null(argumentFilter);
        }