示例#1
0
        public bool IsMatch(Type targetType, Expression setupArgument, object actualValue)
        {
            if (_expressionHelper.IsMethodInvocation(setupArgument, "It", "IsAny", 0))
            {
                return(true);
            }

            bool isItIs = _expressionHelper.IsMethodInvocation(setupArgument, "It", "Is", 1);

            if (isItIs)
            {
                return(_itIsMatcher.ItIsMatch(setupArgument, actualValue));
            }

            object setupValue = _expressionHelper.GetValue(setupArgument);

            return(targetType.IsValueType
                ? Equals(setupValue, actualValue)
                : ReferenceEquals(setupValue, actualValue));
        }
示例#2
0
        private bool IsMatch(ReadOnlyCollection <Expression> setupArguments,
                             ReadOnlyCollection <object> actualArguments)
        {
            for (int i = 0; i < setupArguments.Count; ++i)
            {
                // Skip if the setup argument is It.IsAny<T> (moq/Smocks) or Arg.Any (NSubstitute).
                // We match the call by name, so that both Smock's and Moq's It class can be used.
                bool isIsAny = _expressionHelper.IsMethodInvocation(setupArguments[i], "It", "IsAny", 0) ||
                               _expressionHelper.IsMethodInvocation(setupArguments[i], "Arg", "Any", 0);
                if (isIsAny)
                {
                    continue;
                }

                object actualValue = actualArguments[i];

                // Check if the setup argument is It.Is<T>(...).
                bool isItIs = _expressionHelper.IsMethodInvocation(setupArguments[i], "It", "Is", 1) ||
                              _expressionHelper.IsMethodInvocation(setupArguments[i], "Arg", "Is", 1);
                if (isItIs)
                {
                    if (!_itIsMatcher.ItIsMatch(setupArguments[i], actualValue))
                    {
                        return(false);
                    }
                }
                else
                {
                    object setupValue = _expressionHelper.GetValue(setupArguments[i]);

                    if (!Equals(setupValue, actualValue))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }