Esempio n. 1
0
        private void HandleOutParameters(object[] arguments, IInternalSetupBase setup, MethodBase originalMethod)
        {
            ParameterInfo[] parameters = originalMethod.GetParameters();

            for (int i = 0; i < parameters.Length; ++i)
            {
                int offset = originalMethod.IsStatic ? 0 : 1;

                if (parameters[i].IsOut)
                {
                    arguments[i + offset] = _expressionHelper.GetValue(setup.MethodCall.Arguments[i + offset]);
                }
            }
        }
Esempio n. 2
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));
        }
Esempio n. 3
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);
        }