public ICallSpecification CreateFrom(ICall call, MatchArgs matchArgs)
 {
     var methodInfo = call.GetMethodInfo();
     var argumentSpecs = call.GetArgumentSpecifications();
     var arguments = call.GetOriginalArguments();
     var parameterInfos = call.GetParameterInfos();
     var argumentSpecificationsForCall = _argumentSpecificationsFactory.Create(argumentSpecs, arguments, parameterInfos, matchArgs);
     return new CallSpecification(methodInfo, argumentSpecificationsForCall);
 }
예제 #2
0
        public ICallSpecification CreateFrom(ICall call, MatchArgs matchArgs)
        {
            var methodInfo     = call.GetMethodInfo();
            var argumentSpecs  = call.GetArgumentSpecifications();
            var arguments      = call.GetOriginalArguments();
            var parameterInfos = call.GetParameterInfos();
            var argumentSpecificationsForCall = _argumentSpecificationsFactory.Create(argumentSpecs, arguments, parameterInfos, methodInfo, matchArgs);

            return(new CallSpecification(methodInfo, argumentSpecificationsForCall));
        }
예제 #3
0
        private static IEnumerable<Argument> GetArgumentsFromCall(ICall call)
        {
            var values = call.GetArguments();
            var types = call.GetParameterInfos().Select(x => x.ParameterType).ToArray();

            for (var index = 0; index < values.Length; index++)
            {
                var i = index;
                yield return new Argument(types[i], () => values[i], x => values[i] = x);
            }
        }
예제 #4
0
        private static IEnumerable <Argument> GetArgumentsFromCall(ICall call)
        {
            var values = call.GetArguments();
            var types  = call.GetParameterInfos().Select(x => x.ParameterType).ToArray();

            for (var index = 0; index < values.Length; index++)
            {
                var i = index;
                yield return(new Argument(types[i], () => values[i], x => values[i] = x));
            }
        }
예제 #5
0
        private static IEnumerable <Argument> GetArgumentsFromCall(ICall call)
        {
            var values         = call.GetArguments();
            var parameterInfos = call.GetParameterInfos();

            for (var index = 0; index < values.Length; index++)
            {
                var i = index;
                yield return(new Argument(parameterInfos[i].ParameterType, () => values[i], x => values[i] = x));
            }
        }
예제 #6
0
            public override void Context()
            {
                base.Context();
                var methodInfo = ReflectionHelper.GetMethod(() => SampleMethod());
                var arguments  = new[] { new object() };

                _call = CreateStubCall(methodInfo, arguments);
                _call.stub(x => x.GetArgumentSpecifications()).Return(mock <IList <IArgumentSpecification> >());

                _argumentSpecificationsFactory = mock <IArgumentSpecificationsFactory>();
                _argSpecsFromFactory           = new[] { mock <IArgumentSpecification>(), mock <IArgumentSpecification>() };
                _argumentSpecificationsFactory
                .Stub(x => x.Create(
                          _call.GetArgumentSpecifications(),
                          _call.GetArguments(),
                          _call.GetParameterInfos(),
                          _argMatching))
                .Return(_argSpecsFromFactory);
            }
예제 #7
0
        private IList <IArgumentSpecification> GetGetterCallSpecificationsFromSetterCall(ICall callToSetter)
        {
            var lastSetterArg     = callToSetter.GetOriginalArguments().Last();
            var lastSetterArgType = callToSetter.GetParameterInfos().Last().ParameterType;

            var argumentSpecifications = callToSetter.GetArgumentSpecifications();

            if (argumentSpecifications.Count == 0)
            {
                return(argumentSpecifications);
            }

            // Getter call has one less argument than the setter call (the last arg is trimmed).
            // Therefore, we need to remove the last argument specification if it's for the trimmed arg.
            // Otherwise, NSubstitute might find that the redundant argument specification is present and the
            // validation logic might trigger an exception.
            if (_argSpecCompatTester.IsSpecificationCompatible(argumentSpecifications.Last(), lastSetterArg, lastSetterArgType))
            {
                argumentSpecifications = SkipLast(argumentSpecifications);
            }

            return(argumentSpecifications);
        }