Пример #1
0
        private bool IsSpecifyingACall(ICall call)
        {
            var args     = call.GetArguments() ?? EmptyArgs;
            var argSpecs = call.GetArgumentSpecifications() ?? EmptyArgSpecs;

            return(_isSetToDefaultRoute && args.Any() && argSpecs.Any());
        }
Пример #2
0
        private static bool IsSpecifyingACall(ICall call, IRoute currentRoute)
        {
            var args     = call.GetArguments() ?? EmptyArgs;
            var argSpecs = call.GetArgumentSpecifications() ?? EmptyArgSpecs;

            return(currentRoute.IsRecordReplayRoute && args.Any() && argSpecs.Any());
        }
 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);
 }
Пример #4
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));
        }
Пример #5
0
 public ICall CreateCallToPropertyGetterFromSetterCall(ICall callToSetter)
 {
     var propertyInfo = GetPropertyFromSetterCallOrNull(callToSetter);
     if (!PropertySetterExistsAndHasAGetMethod(propertyInfo))
     {
         throw new InvalidOperationException("Could not find a GetMethod for \"" + callToSetter.GetMethodInfo() + "\"");
     }
     var setterArgs = callToSetter.GetArguments();
     var getter = propertyInfo.GetGetMethod();
     var getterArgs = setterArgs.Take(setterArgs.Length - 1).ToArray();
     return new Call(getter, getterArgs, callToSetter.Target(), callToSetter.GetArgumentSpecifications());
 }
Пример #6
0
        public ICall CreateCallToPropertyGetterFromSetterCall(ICall callToSetter)
        {
            var propertyInfo = GetPropertyFromSetterCallOrNull(callToSetter);

            if (!PropertySetterExistsAndHasAGetMethod(propertyInfo))
            {
                throw new InvalidOperationException("Could not find a GetMethod for \"" + callToSetter.GetMethodInfo() + "\"");
            }
            var setterArgs = callToSetter.GetArguments();
            var getter     = propertyInfo.GetGetMethod();
            var getterArgs = setterArgs.Take(setterArgs.Length - 1).ToArray();

            return(new Call(getter, getterArgs, callToSetter.Target(), callToSetter.GetArgumentSpecifications()));
        }
        public object Route(ICall call)
        {
            Trace($"Route(call: {call.DiagName(_ctx)})");
            Log($"[Received call] " +
                $"Substitute: {call.Target().SubstituteId(_ctx)} " +
                $"Call: {call.FormatArgs(_ctx)} " +
                $"Signature: {call.GetMethodInfo().DiagName()} " +
                $"Argument specifications: {call.GetArgumentSpecifications().Print(s => s.DiagName())}");

            using (new LoggingScope())
            {
                return(_impl.Route(call));
            }
        }
        public RouteAction Handle(ICall call)
        {
            var callSpec = _callSpecificationFactory.CreateFrom(call, MatchArgs.AsSpecifiedInCall);

            _pendingCallSpecification.SetCallSpecification(callSpec);

            // Performance optimization - don't register call actions if current argument matchers
            // don't have any callbacks.
            if (call.GetArgumentSpecifications().Any(x => x.HasAction))
            {
                _callActions.Add(callSpec);
            }

            return(RouteAction.Continue());
        }
Пример #9
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);
            }
Пример #10
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);
        }
Пример #11
0
 private bool IsSpecifyingACall(ICall call)
 {
     var args = call.GetArguments() ?? EmptyArgs;
     var argSpecs = call.GetArgumentSpecifications() ?? EmptyArgSpecs;
     return _isSetToDefaultRoute && args.Any() && argSpecs.Any();
 }