public IsMatch ( string httpMethod, string withPathInfoParts ) : bool | ||
httpMethod | string | |
withPathInfoParts | string | |
return | bool |
public void RegisterRestPaths(Type requestType) { var attrs = appHost.GetRouteAttributes(requestType); foreach (RouteAttribute attr in attrs) { var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes); var defaultAttr = attr as FallbackRouteAttribute; if (defaultAttr != null) { if (appHost.Config.FallbackRestPath != null) { throw new NotSupportedException(string.Format( "Config.FallbackRestPath is already defined. Only 1 [FallbackRoute] is allowed.")); } appHost.Config.FallbackRestPath = (httpMethod, pathInfo, filePath) => { var pathInfoParts = RestPath.GetPathPartsForMatching(pathInfo); return(restPath.IsMatch(httpMethod, pathInfoParts) ? restPath : null); }; continue; } if (!restPath.IsValid) { throw new NotSupportedException(string.Format( "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.GetOperationName())); } RegisterRestPath(restPath); } }
public void RegisterRestPaths(Type requestType) { var restPaths = new List <RestPath>(AppHost.Routes.Where(p => p.RequestType == requestType)); foreach (RouteAttribute attr in AppHost.GetRouteAttributes(requestType)) { var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes, attr.Matches); if (attr is FallbackRouteAttribute defaultAttr) { if (AppHost.Config.FallbackRestPath != null) { throw new NotSupportedException( "Config.FallbackRestPath is already defined. Only 1 [FallbackRoute] is allowed."); } AppHost.Config.FallbackRestPath = httpReq => restPath.IsMatch(httpReq) ? restPath : null; continue; } restPaths.Add(restPath); } foreach (var restPath in restPaths) { RegisterRestPath(restPath); } }
public void RegisterRestPaths(Type requestType) { var attrs = appHost.GetRouteAttributes(requestType); foreach (RouteAttribute attr in attrs) { var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes); var defaultAttr = attr as FallbackRouteAttribute; if (defaultAttr != null) { if (appHost.Config.FallbackRestPath != null) throw new NotSupportedException(string.Format( "Config.FallbackRestPath is already defined. Only 1 [FallbackRoute] is allowed.")); appHost.Config.FallbackRestPath = (httpMethod, pathInfo, filePath) => { var pathInfoParts = RestPath.GetPathPartsForMatching(pathInfo); return restPath.IsMatch(httpMethod, pathInfoParts) ? restPath : null; }; continue; } if (!restPath.IsValid) throw new NotSupportedException(string.Format( "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.GetOperationName())); RegisterRestPath(restPath); } }
public void Can_match_lowercase_http_method() { var restPath = new RestPath(typeof(ComplexType), "/Complex/{Id}/{Name}/Unique/{UniqueId}", "PUT"); var withPathInfoParts = RestPath.GetPathPartsForMatching("/complex/5/Is Alive/unique/4583B364-BBDC-427F-A289-C2923DEBD547"); Assert.That(restPath.IsMatch("put", withPathInfoParts)); }
private static void AssertNoMatch(string definitionPath, string requestPath) { var restPath = new RestPath(typeof(SlugRequest), definitionPath); var requestTestPath = RestPath.GetPathPartsForMatching(requestPath); Assert.That(restPath.IsMatch("GET", requestTestPath), Is.False); }
private static void AssertMatch(string definitionPath, string requestPath, string firstMatchHashKey, SlugRequest expectedRequest, int expectedScore) { var restPath = new RestPath(typeof(SlugRequest), definitionPath); var requestTestPath = RestPath.GetPathPartsForMatching(requestPath); Assert.That(restPath.IsMatch("GET", requestTestPath), Is.True); Assert.That(firstMatchHashKey, Is.EqualTo(restPath.FirstMatchHashKey)); var actualRequest = restPath.CreateRequest(requestPath) as SlugRequest; Assert.That(actualRequest, Is.Not.Null); Assert.That(actualRequest.Slug, Is.EqualTo(expectedRequest.Slug)); Assert.That(actualRequest.Version, Is.EqualTo(expectedRequest.Version)); Assert.That(actualRequest.Options, Is.EqualTo(expectedRequest.Options)); Assert.That(restPath.MatchScore("GET", requestTestPath), Is.EqualTo(expectedScore)); }
private static void AssertMatch(string definitionPath, string requestPath, string firstMatchHashKey, RackSpaceRequest expectedRequest) { var restPath = new RestPath(typeof(RackSpaceRequest), definitionPath); var reqestTestPath = RestPath.GetPathPartsForMatching(requestPath); Assert.That(restPath.IsMatch("GET", reqestTestPath), Is.True); Assert.That(firstMatchHashKey, Is.EqualTo(restPath.FirstMatchHashKey)); var actualRequest = restPath.CreateRequest(requestPath) as RackSpaceRequest; Assert.That(actualRequest, Is.Not.Null); Assert.That(actualRequest.version, Is.EqualTo(expectedRequest.version)); Assert.That(actualRequest.id, Is.EqualTo(expectedRequest.id)); Assert.That(actualRequest.resource_type, Is.EqualTo(expectedRequest.resource_type)); Assert.That(actualRequest.action, Is.EqualTo(expectedRequest.action)); }
private static void AssertMatch(string definitionPath, string requestPath, string firstMatchHashKey, BbcMusicRequest expectedRequest) { var restPath = new RestPath(typeof(BbcMusicRequest), definitionPath); var reqestTestPath = RestPath.GetPathPartsForMatching(requestPath); Assert.That(restPath.IsMatch("GET", reqestTestPath), Is.True); Assert.That(firstMatchHashKey, Is.EqualTo(restPath.FirstMatchHashKey)); var actualRequest = restPath.CreateRequest(requestPath) as BbcMusicRequest; Assert.That(actualRequest, Is.Not.Null); Assert.That(actualRequest.mbz_guid, Is.EqualTo(expectedRequest.mbz_guid)); Assert.That(actualRequest.release_type, Is.EqualTo(expectedRequest.release_type)); Assert.That(actualRequest.content_type, Is.EqualTo(expectedRequest.content_type)); }