public ConfiguredCall SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs)
 {
     var spec = _getCallSpec.FromPendingSpecification(matchArgs);
     CheckResultIsCompatibleWithCall(valueToReturn, spec);
     _configuredResults.SetResult(spec, valueToReturn);
     return new ConfiguredCall(action => _callActions.Add(spec, action));
 }
 private static void CheckResultIsCompatibleWithCall(IReturn valueToReturn, ICallSpecification spec)
 {
     var requiredReturnType = spec.ReturnType();
     if (!valueToReturn.CanBeAssignedTo(requiredReturnType))
     {
         throw new CouldNotSetReturnDueToTypeMismatchException(valueToReturn.TypeOrNull(), spec.GetMethodInfo());
     }
 }
 public override void Context()
 {
     _value = new object();
     _substitutionContext = mock<ISubstitutionContext>();
     _substitutionContext
         .stub(x => x.LastCallShouldReturn(It.IsAny<IReturn>(), It.IsAny<MatchArgs>()))
         .IgnoreArguments()
         .WhenCalled(x => _returnValueSet = (IReturn) x.Arguments[0]);
     temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext);
 }
Beispiel #4
0
 public void SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs)
 {
     if (_pendingSpecification.HasPendingCallSpec())
     {
         SetResultForCall(_pendingSpecification.UseCallSpec(), valueToReturn, matchArgs);
     }
     else
     {
         var lastCall = _callStack.Pop();
         SetResultForCall(lastCall, valueToReturn, matchArgs);
     }
 }
 public override void Context()
 {
     _sub = mock<IFoo>();
     _substitutionContext = mock<ISubstitutionContext>();
     _callRouter = mock<ICallRouter>();
     _substitutionContext.stub(x => x.GetCallRouterFor(_sub))
                         .IgnoreArguments()
                         .Return(_callRouter);
     _callRouter.stub(x => x.SetReturnForType(It.IsAny<Type>(), It.IsAny<IReturn>()))
                .IgnoreArguments()
                .WhenCalled(x => _returnValueSet = (IReturn)x.Arguments[1]);
     temporarilyChange(() => SubstitutionContext.Current).to(_substitutionContext);
 }
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null) throw new CouldNotSetReturnDueToNoLastCallException();
     if (_argumentSpecifications.Value.Any())
     {
         //Clear invalid arg specs so they will not affect other tests
         _argumentSpecifications.Value.Clear();
         throw new UnexpectedArgumentMatcherException();
     }
     var configuredCall = _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     ClearLastCallRouter();
     return configuredCall;
 }
Beispiel #7
0
 public TResponse Delete <TResponse>(IReturn <TResponse> request)
 {
     return(DeleteAsync(request).GetSyncResponse());
 }
Beispiel #8
0
 public void SetReturnForType(Type type, IReturn returnValue)
 {
     TypeUseForSetReturnForType         = type;
     ReturnValueUsedForSetReturnForType = returnValue;
 }
 public ResultForTypeSpec(Type type, IReturn resultToReturn)
 {
     _type = type;
     _resultToReturn = resultToReturn;
 }
Beispiel #10
0
 public ResultForCallSpec(ICallSpecification callSpecification, IReturn resultToReturn)
 {
     _callSpecification = callSpecification;
     _resultToReturn = resultToReturn;
 }
 public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
 }
Beispiel #12
0
 void SetResultForCall(ICallSpecification callSpecification, IReturn valueToReturn, MatchArgs matchArgs)
 {
     var callSpecForReturnValue = GetCallSpecForArgMatchStrategy(callSpecification, matchArgs);
     _configuredResults.SetResult(callSpecForReturnValue, valueToReturn);
 }
Beispiel #13
0
 public void SetResultForCall(ICall call, IReturn valueToReturn, MatchArgs matchArgs)
 {
     var callSpecification = _callSpecificationFactory.CreateFrom(call, matchArgs);
     _configuredResults.SetResult(callSpecification, valueToReturn);
 }
Beispiel #14
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return(new ConfiguredCall(x => { }));
 }
Beispiel #15
0
 public TResponse Get <TResponse>(IReturn <TResponse> request)
 {
     return(GetAsync(request).GetSyncResponse());
 }
Beispiel #16
0
 public Task <TResponse> PutAsync <TResponse>(IReturn <TResponse> requestDto)
 {
     return(SendAsync <TResponse>(HttpMethods.Put, ResolveTypedUrl(HttpMethods.Put, requestDto), requestDto));
 }
Beispiel #17
0
 public Task <TResponse> DeleteAsync <TResponse>(IReturn <TResponse> requestDto)
 {
     return(SendAsync <TResponse>(HttpMethods.Delete, ResolveTypedUrl(HttpMethods.Delete, requestDto), null));
 }
Beispiel #18
0
 public TResponse CustomMethod <TResponse>(string httpVerb, IReturn <TResponse> request)
 {
     return(SendAsync <TResponse>(httpVerb, ResolveTypedUrl(httpVerb, request), request).GetSyncResponse());
 }
Beispiel #19
0
 public TResponse Patch <TResponse>(IReturn <TResponse> request)
 {
     return(SendAsync <TResponse>(HttpMethods.Patch, ResolveTypedUrl(HttpMethods.Patch, request), request).GetSyncResponse());
 }
Beispiel #20
0
 public void SetReturnForType(Type type, IReturn returnValue)
 {
     TypeUseForSetReturnForType = type;
     ReturnValueUsedForSetReturnForType = returnValue;
 }
Beispiel #21
0
 /// <summary>
 /// Alias for ToUrl
 /// </summary>
 /// <returns></returns>
 public static string ToRelativeUri(this IReturn request, string httpMethod, string formatFallbackToPredefinedRoute = null)
 {
     return(request.ToUrl(httpMethod, formatFallbackToPredefinedRoute));
 }
Beispiel #22
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return(ConfigureCall.SetResultForLastCall(returnValue, matchArgs));
 }
Beispiel #23
0
        public static string ToUrl(this IReturn request, string httpMethod, string formatFallbackToPredefinedRoute = null)
        {
            httpMethod = httpMethod.ToUpper();

            var requestType   = request.GetType();
            var requestRoutes = routesCache.GetOrAdd(requestType, GetRoutesForType);

            if (requestRoutes.Count == 0)
            {
                if (formatFallbackToPredefinedRoute == null)
                {
                    throw new InvalidOperationException("There are no rest routes mapped for '{0}' type. ".Fmt(requestType)
                                                        + "(Note: The automatic route selection only works with [Route] attributes on the request DTO and"
                                                        + "not with routes registered in the IAppHost!)");
                }

                var predefinedRoute = "/{0}/syncreply/{1}".Fmt(formatFallbackToPredefinedRoute, requestType.Name);
                if (httpMethod == "GET" || httpMethod == "DELETE" || httpMethod == "OPTIONS" || httpMethod == "HEAD")
                {
                    var queryProperties = RestRoute.GetQueryProperties(request.GetType());
                    predefinedRoute += "?" + RestRoute.GetQueryString(request, queryProperties);
                }

                return(predefinedRoute);
            }

            var routesApplied  = requestRoutes.Select(route => route.Apply(request, httpMethod)).ToList();
            var matchingRoutes = routesApplied.Where(x => x.Matches).ToList();

            if (matchingRoutes.Count == 0)
            {
                var errors = string.Join(String.Empty, routesApplied.Select(x => "\r\n\t{0}:\t{1}".Fmt(x.Route.Path, x.FailReason)).ToArray());
                var errMsg = "None of the given rest routes matches '{0}' request:{1}"
                             .Fmt(requestType.Name, errors);

                throw new InvalidOperationException(errMsg);
            }

            RouteResolutionResult matchingRoute;

            if (matchingRoutes.Count > 1)
            {
                matchingRoute = FindMostSpecificRoute(matchingRoutes);
                if (matchingRoute == null)
                {
                    var errors = String.Join(String.Empty, matchingRoutes.Select(x => "\r\n\t" + x.Route.Path).ToArray());
                    var errMsg = "Ambiguous matching routes found for '{0}' request:{1}".Fmt(requestType.Name, errors);
                    throw new InvalidOperationException(errMsg);
                }
            }
            else
            {
                matchingRoute = matchingRoutes[0];
            }

            var url = matchingRoute.Uri;

            if (httpMethod == HttpMethods.Get || httpMethod == HttpMethods.Delete || httpMethod == HttpMethods.Head)
            {
                var queryParams = matchingRoute.Route.FormatQueryParameters(request);
                if (!String.IsNullOrEmpty(queryParams))
                {
                    url += "?" + queryParams;
                }
            }

            return(url);
        }
Beispiel #24
0
 public void SetResultForLastCall(IReturn valueToReturn, MatchArgs matchArgs)
 {
     var lastCall = _callStack.Pop();
     SetResultForCall(lastCall, valueToReturn, matchArgs);
 }
 public ReturnController(IReturnServices IssueService, IStudentServices studentService, IBookService bookservices, IReturn Issuemodel, IStaffServices staffSevices)
 {
     _entity           = new Return();
     _IReturnServices  = IssueService;
     _IStudentServices = studentService;
     _IBookService     = bookservices;
     _IReturn          = Issuemodel;
     _IStaffServices   = staffSevices;
 }
Beispiel #26
0
 public IEnumerable <TResponse> GetLazy <TResponse>(IReturn <QueryResponse <TResponse> > queryDto)
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
 public TResponse Delete <TResponse>(IReturn <TResponse> request)
 {
     throw new NotImplementedException();
 }
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null) throw new CouldNotSetReturnDueToNoLastCallException();
     var configuredCall = _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     ClearLastCallRouter();
     return configuredCall;
 }
Beispiel #29
0
 public TResponse Patch <TResponse>(IReturn <TResponse> requestDto)
 {
     throw new NotImplementedException();
 }
Beispiel #30
0
 public void SetResult(ICallSpecification callSpecification, IReturn result)
 {
     _results.Add(new ResultForCallSpec(callSpecification, result));
 }
Beispiel #31
0
 public Task <TResponse> SendAsync <TResponse>(IReturn <TResponse> requestDto)
 {
     return(SendAsync <TResponse>((object)requestDto));
 }
 public void SetResult(Type type, IReturn resultToReturn)
 {
     _results.Enqueue(new ResultForTypeSpec(type, resultToReturn));
 }
Beispiel #33
0
 public Task <TResponse> PutAsync <TResponse>(IReturn <TResponse> requestDto)
 {
     throw new NotImplementedException();
 }
 public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter == null) throw new SubstituteException();
     _lastCallRouter.LastCallShouldReturn(value, matchArgs);
 }
Beispiel #35
0
 public Task <TResponse> CustomMethodAsync <TResponse>(string httpVerb, IReturn <TResponse> requestDto)
 {
     throw new NotImplementedException();
 }
 public void SetResultForCall(ICall call, IReturn valueToReturn, MatchArgs matchArgs)
 {
     var spec = _getCallSpec.FromCall(call, matchArgs);
     CheckResultIsCompatibleWithCall(valueToReturn, spec);
     _configuredResults.SetResult(spec, valueToReturn);
 }
 public void SetResult(Type type, IReturn resultToReturn)
 {
     _results.Enqueue(new ResultForTypeSpec(type, resultToReturn));
 }
Beispiel #38
0
 public void SetReturnForType(Type type, IReturn returnValue)
 {
     _substituteState.ResultsForType.SetResult(type, returnValue);
 }
 public ResultForTypeSpec(Type type, IReturn resultToReturn)
 {
     _type           = type;
     _resultToReturn = resultToReturn;
 }
 public void LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     if (_lastCallRouter.Value == null) throw new CouldNotSetReturnException();
     _lastCallRouter.Value.LastCallShouldReturn(value, matchArgs);
     _lastCallRouter.Value = null;
 }
Beispiel #41
0
 public void LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     _resultSetter.SetResultForLastCall(returnValue, matchArgs);
 }
Beispiel #42
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return new ConfiguredCall(x => { });
 }
 public ConfiguredCall LastCallShouldReturn(IReturn value, MatchArgs matchArgs)
 {
     return innerContext.LastCallShouldReturn(value, matchArgs);
 }
Beispiel #44
0
 public ConfiguredCall LastCallShouldReturn(IReturn returnValue, MatchArgs matchArgs)
 {
     return ConfigureCall.SetResultForLastCall(returnValue, matchArgs);
 }
 public override void Context()
 {
     base.Context();
     _returnValue = mock <IReturn>();
 }