Beispiel #1
0
        private object ResolveReturnValue(ICall call)
        {
            if (call.GetReturnType() == typeof(void))
            {
                return(null);
            }

            // If this is a call to a property getter, we resolve value via the 'PropertyInfo' request.
            var propertyInfo = call.GetMethodInfo().GetPropertyFromGetterCallOrNull();

            if (propertyInfo != null)
            {
                return(this.SpecimenContext.Resolve(propertyInfo));
            }

            return(this.SpecimenContext.Resolve(call.GetReturnType()));
        }
 public RouteAction Handle(ICall call)
 {
     var type = call.GetReturnType();
     var compatibleProviders = _autoValueProviders.Where(x => x.CanProvideValueFor(type)).FirstOrNothing();
     return compatibleProviders.Fold(
         RouteAction.Continue,
         ReturnValueUsingProvider(call, type));
 }
        public RouteAction Handle(ICall call)
        {
            var type = call.GetReturnType();
            var compatibleProviders = _autoValueProviders.Where(x => x.CanProvideValueFor(type)).FirstOrNothing();

            return(compatibleProviders.Fold(
                       RouteAction.Continue,
                       ReturnValueUsingProvider(call, type)));
        }
 public RouteAction Handle(ICall call)
 {
     var type = call.GetReturnType();
     var compatibleProviders = _autoValueProviders.Where(x => x.CanProvideValueFor(type));
     if (compatibleProviders.Any())
     {
             var valueToReturn = compatibleProviders.First().GetValue(type);
             ConfigureCall.SetResultForCall(call, new ReturnValue(valueToReturn), MatchArgs.AsSpecifiedInCall);
             return RouteAction.Return(valueToReturn);
     }
     return RouteAction.Continue();
 }
        public RouteAction Handle(ICall call)
        {
            var type = call.GetReturnType();
            var compatibleProviders = _autoValueProviders.Where(x => x.CanProvideValueFor(type));

            if (compatibleProviders.Any())
            {
                var valueToReturn = compatibleProviders.First().GetValue(type);
                _resultSetter.SetResultForCall(call, new ReturnValue(valueToReturn), MatchArgs.AsSpecifiedInCall);
                return(RouteAction.Return(valueToReturn));
            }
            return(RouteAction.Continue());
        }
Beispiel #6
0
        public RouteAction Handle(ICall call)
        {
            if (_callResults.TryGetResult(call, out var cachedResult))
            {
                return(RouteAction.Return(cachedResult));
            }

            var type = call.GetReturnType();
            var compatibleProviders = _autoValueProviders.Where(x => x.CanProvideValueFor(type)).FirstOrNothing();

            return(compatibleProviders.Fold(
                       RouteAction.Continue,
                       ReturnValueUsingProvider(call, type)));
        }
Beispiel #7
0
            public RouteAction Handle(ICall call)
            {
                var property = call.GetMethodInfo().GetPropertyFromGetterCallOrNull();

                if (property is null)
                {
                    return(RouteAction.Continue());
                }

                var service = _context.ResolveOptional(call.GetReturnType());

                if (service is null)
                {
                    return(RouteAction.Continue());
                }

                return(RouteAction.Return(service));
            }
Beispiel #8
0
        public RouteAction Handle(ICall call)
        {
            if (_callResults.TryGetResult(call, out var cachedResult))
            {
                return(RouteAction.Return(cachedResult));
            }

            var type = call.GetReturnType();

            // This is a hot method which is invoked frequently and has major impact on performance.
            // Therefore, the LINQ cycle was unwinded to loop.
            foreach (var autoValueProvider in _autoValueProviders)
            {
                if (autoValueProvider.CanProvideValueFor(type))
                {
                    return(RouteAction.Return(GetResultValueUsingProvider(call, type, autoValueProvider)));
                }
            }

            return(RouteAction.Continue());
        }
Beispiel #9
0
 bool ReturnsVoidFrom(ICall call)
 {
     return(call.GetReturnType() == typeof(void));
 }
 public bool IsResultFor(ICall call)
 {
     return call.GetReturnType() == _type;
 }
 private bool ReturnsVoid(ICall call)
 {
     return call.GetReturnType() == typeof(void);
 }
Beispiel #12
0
 bool ReturnsVoidFrom(ICall call)
 {
     return call.GetReturnType() == typeof (void);
 }
Beispiel #13
0
 public bool IsSatisfiedBy(ICall call)
 => call.GetReturnType() == _expectedReturnType;
 public bool IsResultFor(ICall call)
 {
     return(call.GetReturnType() == _type);
 }
 private bool ReturnsVoid(ICall call)
 {
     return(call.GetReturnType() == typeof(void));
 }