public bool MatchesRpcRoute(RpcRouteCollection routes, string requestUrl, out RpcRoute route) { if (routes == null) { throw new ArgumentNullException(nameof(routes)); } if (requestUrl == null) { throw new ArgumentNullException(nameof(requestUrl)); } this.Logger?.LogVerbose($"Attempting to match Rpc route for the request url '{requestUrl}'"); RpcPath requestPath = RpcPath.Parse(requestUrl); RpcPath routePrefix = RpcPath.Parse(routes.RoutePrefix); foreach (RpcRoute rpcRoute in routes) { RpcPath routePath = RpcPath.Parse(rpcRoute.Name); routePath = routePrefix.Add(routePath); if (requestPath == routePath) { this.Logger?.LogVerbose($"Matched the request url '{requestUrl}' to the route '{rpcRoute.Name}'"); route = rpcRoute; return(true); } } this.Logger?.LogVerbose($"Failed to match the request url '{requestUrl}' to a route"); route = null; return(false); }
public void MatchesRpcRoute_DifferentRoutes_Valid(string requestUrl, string availableRouteName, bool shouldMatch) { RpcRoute route = new RpcRoute(availableRouteName); RpcRouteCollection routes = new RpcRouteCollection { route }; DefaultRpcParser parser = new DefaultRpcParser(); RpcRoute matchedRoute; bool isMatch = parser.MatchesRpcRoute(routes, requestUrl, out matchedRoute); Assert.Equal(isMatch, shouldMatch); Assert.Equal(matchedRoute != null, shouldMatch); Assert.Equal(route == matchedRoute, shouldMatch); }