예제 #1
0
        public void Matches_ArgumentCountMismatch_ReturnsFalse()
        {
            var predicateBuilder = new MatchInfoBuilder();
            Expression<Action<IFoo>> expression = (f) => f.Execute("SomeValue");

            var matchInfo = predicateBuilder.Build(expression);

            var invocationInfo = new InvocationInfo(
                typeof(IFoo).GetMethod("Execute", new Type[] { typeof(string) }),
                new[] { "SomeValue", "AnotherValue" });

            Assert.IsFalse(matchInfo.Matches(invocationInfo));
        }
예제 #2
0
        /// <summary>
        /// Determines if the <paramref name="invocationInfo"/> matches this <see cref="MatchInfo"/>.
        /// </summary>
        /// <param name="invocationInfo">The <see cref="InvocationInfo"/> to be matched.</param>
        /// <returns><b>True</b> if the <paramref name="invocationInfo"/> matches 
        /// this <see cref="MatchInfo"/>, otherwise, <b>False</b>.</returns>
        public bool Matches(InvocationInfo invocationInfo)
        {
            if (ExpressionType != invocationInfo.ExpressionType) return false;
            
            if (member != invocationInfo.Member)
            {
                return false;
            }

            if (ExpressionType == ExpressionType.MemberAccess) return true;

            if (matchExpressions.Length != invocationInfo.Arguments.Length)
            {
                return false;
            }

            return !matchExpressions.Where((t, i) => !(bool)t.Execute(invocationInfo.Arguments[i])).Any();
        }
예제 #3
0
 /// <summary>
 /// Determines if the <paramref name="invocationInfo"/> matches this <see cref="Arrangement"/>.
 /// </summary>
 /// <param name="invocationInfo">The <see cref="InvocationInfo"/> that represents the method invocation.</param>
 /// <returns><b>True</b> if the <paramref name="invocationInfo"/> matches this <see cref="Arrangement"/>, otherwise, <b>False</b>.</returns>
 internal bool Matches(InvocationInfo invocationInfo)
 {
     return(expression.ToMatchInfo().Matches(invocationInfo));
 }